LUA 175
V1+ Ramdom Weapons 1.01 By xdedeone on 26th February 2019 07:42:57 PM
  1. -- RandomWeapon 1.01
  2.  
  3. -- Written by [SC]Nuggets
  4. -- If you have questions, comments, critiques, or evil plans to rule the world, contact [SC]Nuggets via phasor.proboards.com
  5. -- Enjoy!
  6.  
  7. --[[
  8.  
  9. In this gametype, you spawn with assigned attributes based on random number generators.
  10. You may not pick up any other weapon other than what you have spawned with.
  11.  
  12. --]]
  13.  
  14. --[[
  15.  
  16. I have re-scripted my RandomWeapon script in order to make it more user-friendly.
  17. This version of the script is meant to make the probabilities of spawning with certain attributes easier to edit.
  18. If you're interested in how the code works, I have comments and such in the code below.
  19. If you just want this script to work and don't care how it actually works, then you can stop reading when you get to "function GetRequiredVersion".
  20. This is the first script I've written with intentions of others reading and trying to understand it, so let me know if I suck at it or not.
  21.  
  22. --]]
  23.  
  24. -- PROBABILITIES:
  25.  
  26. --[[
  27.  
  28. Change these values to whatever you choose.
  29. The percentage of probability is based on the ratio of the value you enter for a specific field and the sum of all of the values of that category.
  30. For example, if the sum of all of the values of the "Primary" category is 100, and the assault_rifle is set to 25, there is a 25% chance a player will spawn with an assault rifle (25/100).
  31. If the sum of the "Primary" category is 500 and assault_rifle is set to 25, then there's a 5% chance a player will spawn with an assault rifle (25/500).
  32. It's obviously easiest to just let each section add up to 100 so the values you enter for each attribute will be a percent value, but if for some reason you don't it want to, I've given you that freedom.
  33. Enter the values to any precision you like.
  34.  
  35. --]]
  36.  
  37. -- Weapon probabilities:
  38.  
  39.         -- Primary:
  40.         plasma_pistol = 19
  41.         assault_rifle = 22
  42.         needler = 14
  43.         plasma_rifle = 12
  44.         shotgun = 10
  45.         pistol = 11
  46.         sniper = 9
  47.         flamethrower = 1.5
  48.         rocket = 1
  49.         fuel_rod = 0.5 
  50.        
  51.         -- Secondary:
  52.         no_weapon = 70
  53.         plasma_pistol_2 = 7
  54.         assault_rifle_2 = 7
  55.         needler_2 = 5
  56.         plasma_rifle_2 = 3
  57.         shotgun_2 = 3
  58.         pistol_2 = 2
  59.         sniper_2 = 1
  60.         flamethrower_2 = 1
  61.         rocket_2 = 0.75
  62.         fuel_rod_2 = 0.25
  63.        
  64.  
  65. -- Grenade probabilities:
  66. no_grenades = 75
  67. one_frag = 7
  68. two_frags = 4
  69. one_plasma = 7
  70. two_plasmas = 4
  71. two_of_each = 2
  72. four_of_each = 1
  73.  
  74. -- Special probabilities:
  75. none = 95.5
  76. invisible = 0.75
  77. overshield = 0.75
  78. extra_speed = 0.75
  79. invis_overshield = 0.5
  80. invis_speed = 0.5
  81. overshield_speed = 0.5
  82. all_special = 0.25
  83.  
  84.  
  85. -- Ammo probabilities:
  86. normal_ammo = 75
  87. double_ammo = 12
  88. triple_ammo = 8
  89. ammotacular = 4.75
  90. infinite_ammo = 0.25
  91.  
  92.  
  93. -- Server Messages:
  94. welcome_message = "Random attributes will be assigned to you on each spawn."
  95. death_message = "Choosing random attributes..."
  96.  
  97. -- Other Editable Variables:
  98. speed = 2.0   -- Speed value of players who spawn with extra speed
  99.  
  100. -- Weapon tables:  Keeps track of what players have what weapon.  1 = yes, 0 = no.
  101. -- Don't mess with this unless you know what you're doing.
  102.  
  103. AssaultRifle = {}
  104. Pistol = {}
  105. Needler = {}
  106. PlasmaRifle = {}
  107. PlasmaPistol = {}
  108. FuelRod = {}
  109. Rocket = {}
  110. Flamethrower = {}
  111. Shotgun = {}
  112. Sniper = {}
  113.  
  114. function GetRequiredVersion()
  115.  
  116.         return 10057
  117. end
  118.  
  119.  
  120. function OnScriptLoad(process)
  121.  
  122.         -- Create tables for each weapon and set every player's value to 0.
  123.        
  124.         for i = 1, 16 do
  125.        
  126.                 AssaultRifle[i] = 0
  127.                 Pistol[i] = 0
  128.                 Needler[i] = 0
  129.                 PlasmaRifle[i] = 0
  130.                 PlasmaPistol[i] = 0
  131.                 FuelRod[i] = 0
  132.                 Rocket[i] = 0
  133.                 Flamethrower[i] = 0
  134.                 Shotgun[i] = 0
  135.                 Sniper[i] = 0
  136.         end
  137. end
  138.  
  139.  
  140. function OnScriptUnload()
  141.  
  142.  
  143. end
  144.  
  145.  
  146. function OnNewGame(map)
  147.  
  148.  
  149. end
  150.  
  151.  
  152. function OnGameEnd(mode)
  153.  
  154.  
  155. end
  156.  
  157. function OnServerChat(player, chattype, message)
  158.  
  159.         return 1
  160. end
  161.  
  162. function OnServerCommand(player, command)
  163.  
  164.         return 1
  165. end
  166.  
  167.  
  168. function OnTeamDecision(cur_team)
  169.  
  170.         return cur_team
  171. end
  172.  
  173.  
  174. function OnPlayerJoin(player, team)
  175.  
  176.         privatesay(player, "Randomness:")
  177.         privatesay(player, welcome_message)
  178. end
  179.  
  180. function OnPlayerLeave(player, team)
  181.  
  182.  
  183. end
  184.  
  185.  
  186. function OnPlayerKill(killer, victim, mode)
  187.  
  188.         privatesay(victim, death_message)      
  189.         local victimId = resolveplayer(victim)
  190.        
  191.         -- Reset all weapon values of the victim to 0.
  192.        
  193.         AssaultRifle[victimId] = 0
  194.         Pistol[victimId] = 0
  195.         Needler[victimId] = 0
  196.         PlasmaRifle[victimId] = 0
  197.         PlasmaPistol[victimId] = 0
  198.         FuelRod[victimId] = 0
  199.         Rocket[victimId] = 0
  200.         Flamethrower[victimId] = 0
  201.         Shotgun[victimId] = 0
  202.         Sniper[victimId] = 0
  203. end
  204.  
  205.  
  206. function OnKillMultiplier(player, multiplier)
  207.  
  208.  
  209. end
  210.  
  211.  
  212. function OnPlayerSpawn(player, m_objectId)
  213.  
  214.  
  215. end
  216.  
  217. function OnPlayerSpawnEnd(player, m_objectId)
  218.  
  219.         if gethash(player) ~= nil then
  220.         -- GRENADES
  221.  
  222.                 -- Determine whether a player will spawn with grenades, and if so, what kind and how many.     
  223.                 -- Sum up all of the values entered in the probabilities.
  224.  
  225.                         local grenade_sum = no_grenades + one_frag + two_frags + one_plasma + two_plasmas + two_of_each + four_of_each
  226.                
  227.                 -- Find the highest precision used out of all of the values entered.           
  228.                         -- Create array
  229.                         local g = {no_grenades, one_frag, two_frags, one_plasma, two_plasmas, two_of_each, four_of_each}
  230.                        
  231.                         -- Find the highest precision out of all elements of the array.
  232.                         local g_precision = findHighestPrecision(g)    
  233.                        
  234.                         -- Be lazy.
  235.                         local x = 10^g_precision
  236.                        
  237.                         -- Get a random number:  0 <= grenade < (grenade_sum * 10^precision)
  238.                         local grenade = getrandomnumber(0, (grenade_sum * x))
  239.  
  240.                 local m_Object = getobject(m_objectId)
  241.                
  242.                 -- Determine what the random number will do.
  243.                
  244.                         if m_Object ~= 0 then
  245.                                 if grenade >= 0 and grenade < (no_grenades * x) then
  246.  
  247.                                         writebyte(m_Object, 0x31E, 0)  -- set frag grenades to 0
  248.                                         writebyte(m_Object, 0x31F, 0)  -- set plasmas to 0
  249.  
  250.                                 elseif grenade >= (no_grenades * x) and grenade < (x * (no_grenades + one_frag)) then
  251.  
  252.                                         writebyte(m_Object, 0x31E, 1)  -- set frags to 1
  253.                                         writebyte(m_Object, 0x31F, 0)  -- plasmas to 0
  254.  
  255.                                         privatesay(player, "A Frag Grenade.")  -- tell the player what they spawned with
  256.  
  257.                                 elseif grenade >= (x * (no_grenades + one_frag)) and grenade < (x * (no_grenades + one_frag + one_plasma)) then
  258.  
  259.                                         writebyte(m_Object, 0x31E, 0)  -- yadayadayada
  260.                                         writebyte(m_Object, 0x31F, 1)  -- yada.
  261.  
  262.                                         privatesay(player, "A Plasma Grenade.")
  263.  
  264.                                 elseif grenade >= (x * (no_grenades + one_frag + one_plasma)) and grenade < (x * (no_grenades + one_frag + one_plasma + two_frags)) then
  265.  
  266.                                         writebyte(m_Object, 0x31E, 2)
  267.                                         writebyte(m_Object, 0x31F, 0)
  268.  
  269.                                         privatesay(player, "Two Frag Grenades.")
  270.  
  271.                                 elseif grenade >= (x * (no_grenades + one_frag + one_plasma + two_frags)) and grenade < (x * (no_grenades + one_frag + one_plasma + two_frags + two_plasmas)) then
  272.  
  273.                                         writebyte(m_Object, 0x31E, 0)
  274.                                         writebyte(m_Object, 0x31F, 2)
  275.  
  276.                                         privatesay(player, "Two Plasma Grenades.")
  277.  
  278.                                 elseif grenade >= (x * (no_grenades + one_frag + one_plasma + two_frags + two_plasmas)) and grenade < (x * (no_grenades + one_frag + one_plasma + two_frags + two_plasmas + two_of_each)) then
  279.  
  280.                                         writebyte(m_Object, 0x31E, 2)
  281.                                         writebyte(m_Object, 0x31F, 2)
  282.  
  283.                                         privatesay(player, "Two of each Grenade.")
  284.  
  285.                                 elseif grenade >= (x * (no_grenades + one_frag + one_plasma + two_frags + two_plasmas + two_of_each)) and grenade < (grenade_sum * x) then
  286.  
  287.                                         writebyte(m_Object, 0x31E, 4)
  288.                                         writebyte(m_Object, 0x31F, 4)
  289.  
  290.                                         privatesay(player, "Four of each Grenade.")
  291.                                 end
  292.                         end
  293.                
  294.         -- SPECIAL ATTRIBUTES
  295.  
  296.                 -- Determine whether a player will spawn with camouflage, overshield, or extra speed.  
  297.                 -- Sum up the values
  298.  
  299.                         local special_sum = invisible + overshield + extra_speed + invis_overshield + invis_speed + overshield_speed + all_special + none
  300.                
  301.                 -- Find the highest precision used (see the GRENADES section for info on what's going on here).
  302.                
  303.                         local s = {invisible, overshield, extra_speed, invis_overshield, invis_speed, overshield_speed, all_special, none}
  304.                         local s_precision = findHighestPrecision(s)
  305.                         local y = 10^s_precision
  306.                
  307.                         local gametype_base = 0x671340
  308.                         local gametype_game = readbyte(gametype_base, 0x30)   -- Make sure this isn't an Oddball or Race gametype where speed cannot be changed
  309.                        
  310.                 -- Determine whether this is a shields or no-shields gametype so players don't spawn with "overshield" in a no-shields gametype.
  311.                
  312.                         local gametype_parameters = readbyte(gametype_base, 0x38)
  313.                         local binary = convertbase(10, 2, gametype_parameters)  -- gametype_parameters is represented in binary...
  314.                         local obj_max_shields = 0      
  315.                        
  316.                         if string.sub(binary, -4, -4) == "0" then   --  ... but we only care if this is a shields or no-shields gametype (which is represented by the fourth digit from the right)  Shields on = 0; Shields off = 1
  317.                        
  318.                                 obj_max_shields = 1
  319.                         end
  320.                
  321.                         local special = getrandomnumber(0, (special_sum * y))
  322.  
  323.                 -- Put it all together and do magical stuff.
  324.                        
  325.                         if special >= 0 and special < (invisible * y) then
  326.  
  327.                                 applycamo(player, 0)
  328.                                 setspeed(player, 1)
  329.                                 privatesay(player, "You are invisible!")
  330.  
  331.                         elseif special >= (invisible * y) and special < (y * (invisible + extra_speed)) then
  332.  
  333.                                 if gametype_game ~= 3 and gametype_game ~= 5 then   -- make sure this isn't oddball or race
  334.                                         setspeed(player, speed)
  335.                                         privatesay(player, "You have increased speed!")
  336.                                 end
  337.  
  338.                         elseif special >= (y * (invisible + extra_speed)) and special < (y * (invisible + extra_speed + invis_speed)) then
  339.  
  340.                                 if gametype_game ~= 3 and gametype_game ~= 5 then
  341.                                         applycamo(player, 0)
  342.                                         setspeed(player, speed)
  343.                                         privatesay(player, "You are invisible AND have increased speed!")
  344.                                 end
  345.                                
  346.                         elseif special >= (y * (invisible + extra_speed + invis_speed)) and special < (y * (invisible + extra_speed + invis_speed + overshield)) then
  347.                        
  348.                                 if obj_max_shields ~= 0 then   -- make sure players have shields in this gametype
  349.                                         applyos(player)
  350.                                         setspeed(player, 1)
  351.                                         privatesay(player, "You have overshield!")
  352.                                 else
  353.                                         setspeed(player, 1)
  354.                                 end
  355.                                
  356.                         elseif special >= (y * (invisible + extra_speed + invis_speed + overshield)) and special < (y * (invisible + extra_speed + invis_speed + overshield + invis_overshield)) then
  357.                        
  358.                                 if obj_max_shields ~= 0 then
  359.                                         applyos(player)
  360.                                         applycamo(player, 0)
  361.                                         setspeed(player, 1)
  362.                                         privatesay(player, "You are invisible AND have overshield!")
  363.                                 else
  364.                                         setspeed(player, 1)
  365.                                 end
  366.                                
  367.                         elseif special >= (y * (invisible + extra_speed + invis_speed + overshield + invis_overshield)) and special < (y * (invisible + extra_speed + invis_speed + overshield + invis_overshield + overshield_speed)) then
  368.                        
  369.                                 if obj_max_shields ~= 0 and gametype_game ~= 3 and gametype_game ~= 5 then
  370.                                         applyos(player)
  371.                                         setspeed(player, speed)
  372.                                         privatesay(player, "You have overshield AND extra speed!")
  373.                                 else
  374.                                         setspeed(player, 1)
  375.                                 end
  376.                                
  377.                         elseif special >= (y * (invisible + extra_speed + invis_speed + overshield+ invis_overshield + overshield_speed)) and special < (y * (invisible + extra_speed + invis_speed + overshield + invis_overshield + overshield_speed + all_special)) then
  378.                        
  379.                                 if obj_max_shields ~= 0 and gametype_game ~= 3 and gametype_game ~= 5 then
  380.                                         applyos(player)
  381.                                         applycamo(player, 0)
  382.                                         setspeed(player, speed)
  383.                                         privatesay(player, "JACKPOT: All special attributes!")
  384.                                 else
  385.                                         setspeed(player, 1)
  386.                                 end
  387.  
  388.                         elseif special >= (y * (invisible + extra_speed + invis_speed + overshield + invis_overshield + overshield_speed + all_special)) and special < (y * special_sum) then
  389.  
  390.                                 setspeed(player, 1.0)
  391.                         end
  392.                
  393.         -- AMMO ATTRIBUTES
  394.  
  395.                 -- Determine whether a player will spawn with extra ammo.
  396.                
  397.                         local ammo_sum = normal_ammo + double_ammo + triple_ammo + ammotacular + infinite_ammo
  398.                
  399.                 -- Find the highest precision used (see the GRENADES section for more info on how this works).
  400.                
  401.                         local a = {normal_ammo, double_ammo, triple_ammo, ammotacular, infinite_ammo}
  402.                         local a_precision = findHighestPrecision(a)
  403.                         local z = 10^a_precision
  404.                        
  405.                         local ammo = getrandomnumber(0, (ammo_sum * z))
  406.                
  407.                 local m_player = getplayer(player)
  408.                 local ammo_multiplier = 1   -- Initialize an ammo multiplier
  409.  
  410.                 -- Get a player's weapons.....
  411.                
  412.                 if m_player ~= nil then
  413.                
  414.                         local m_ObjId = readdword(m_player, 0x34)
  415.                         local m_object = getobject(m_ObjId)
  416.  
  417.                         if m_object ~= nil then
  418.                                 for i = 0, 3 do   -- For primary, secondary, ternary, and quartary weapons do...
  419.                                
  420.                                         local m_weaponId = readdword(m_object, 0x2F8 + (i*4))   -- Get the weapon ID of each weapon (incrementing by four bytes each time)
  421.  
  422.                                         if m_weaponId ~= nil then
  423.  
  424.                                                 local m_weapon = getobject(m_weaponId)
  425.  
  426.                                                 if m_weapon ~= nil then
  427.                                                
  428.                                                         -- Make sure the player isn't getting "extra ammo" in his/her plasma weapon
  429.                                                        
  430.                                                         if PlasmaRifle[resolveplayer(player)] ~= 1 and PlasmaPistol[resolveplayer(player)] ~= 1 and FuelRod[resolveplayer(player)] ~= 1 then
  431.                                                
  432.                                                         -- Do all the shmexy stuff.
  433.                                                        
  434.                                                                 local weap_ammo = readword(m_weapon, 0x2B6)
  435.                                                                
  436.                                                                 if ammo >= 0 and ammo < (double_ammo * z) then
  437.                                                        
  438.                                                                         writeword(m_weapon, 0x2B6, weap_ammo * 2)
  439.                                                                         ammo_multiplier = 2
  440.                                                                        
  441.                                                                 elseif ammo >= (double_ammo * z) and ammo < (z * (double_ammo + triple_ammo)) then
  442.                                                                
  443.                                                                         writeword(m_weapon, 0x2B6, weap_ammo * 3)                                                              
  444.                                                                         ammo_multiplier = 3
  445.                                                                        
  446.                                                                 elseif ammo >= (z * (double_ammo + triple_ammo)) and ammo < (z * (double_ammo + triple_ammo + ammotacular)) then
  447.                                                                
  448.                                                                         writeword(m_weapon, 0x2B6, weap_ammo * 4)                                                              
  449.                                                                         ammo_multiplier = 4
  450.                                                                        
  451.                                                                 elseif ammo >= (z * (double_ammo + triple_ammo + ammotacular)) and ammo < (z * (double_ammo + triple_ammo + ammotacular + infinite_ammo)) then
  452.                                                                
  453.                                                                         writeword(m_weapon, 0x2B6, 9999)
  454.                                                                         writeword(m_weapon, 0x2B8, 9999)
  455.                                                                         updateammo(m_weaponId)
  456.                                                                         ammo_multiplier = 5                                                    
  457.                                                                 end
  458.                                                         end
  459.                                                 end
  460.                                         end
  461.                                 end
  462.                         end
  463.                 end
  464.                        
  465.                 -- Print the messages (if you print the messages in the loop above, the player will be spammed the same message for each weapon)
  466.                
  467.                 if ammo_multiplier == 2 then
  468.                         privatesay(player, "Double Ammo!")
  469.                 elseif ammo_multiplier == 3 then
  470.                         privatesay(player, "Triple Ammo!")
  471.                 elseif ammo_multiplier == 4 then
  472.                         privatesay(player, "Ammotacular!")
  473.                 elseif ammo_multiplier == 5 then
  474.                         privatesay(player, "JACKPOT: INFINITE AMMO!")
  475.                 end    
  476.         end
  477. end
  478.  
  479.  
  480. function OnTeamChange(relevant, player, team, dest_team)
  481.  
  482.         return 1
  483. end
  484.  
  485.  
  486. function OnObjectInteraction(player, m_ObjectId, tagType, tagName)
  487.  
  488.         -- Set values of "player" so they can be accessed in the weapon arrays (since there is no "0th" element of an array in Lua)
  489.        
  490.         local player = resolveplayer(player)
  491.  
  492.         -- Make sure players can always pick up the flag.
  493.        
  494.         if tagType == "weap" then
  495.                 if tagName == "weapons\\flag\\flag" then
  496.                
  497.                         response = 1
  498.  
  499.                 -- Based on weapon values, determine what weapon(s) a player can interact with.
  500.                        
  501.                 elseif tagName == "weapons\\assault rifle\\assault rifle" then
  502.                         if AssaultRifle[player] == 1 then
  503.                        
  504.                                 response = 1
  505.                         else
  506.                                 response = 0
  507.                         end
  508.  
  509.                 elseif tagName == "weapons\\pistol\\pistol" then
  510.                         if Pistol[player] == 1 then
  511.                        
  512.                                 response = 1
  513.                         else
  514.                                 response = 0
  515.                         end
  516.  
  517.                 elseif tagName == "weapons\\plasma rifle\\plasma rifle" then
  518.                         if PlasmaRifle[player] == 1 then
  519.                        
  520.                                 response = 1
  521.                         else
  522.                                 response = 0
  523.                         end
  524.        
  525.                 elseif tagName == "weapons\\plasma pistol\\plasma pistol" then
  526.                         if PlasmaPistol[player] == 1 then
  527.                        
  528.                                 response = 1
  529.                         else
  530.                                 response = 0
  531.                         end
  532.  
  533.                 elseif tagName == "weapons\\needler\\mp_needler" then
  534.                         if Needler[player] == 1 then
  535.                        
  536.                                 response = 1
  537.                         else
  538.                                 response = 0
  539.                         end
  540.  
  541.                 elseif tagName == "weapons\\flamethrower\\flamethrower" then
  542.                         if Flamethrower[player] == 1 then
  543.                        
  544.                                 response = 1
  545.                         else
  546.                                 response = 0
  547.                         end
  548.  
  549.                 elseif tagName == "weapons\\plasma_cannon\\plasma_cannon" then
  550.                         if FuelRod[player] == 1 then
  551.                        
  552.                                 response = 1
  553.                         else
  554.                                 response = 0
  555.                         end
  556.  
  557.                 elseif tagName == "weapons\\rocket launcher\\rocket launcher" then
  558.                         if Rocket[player] == 1 then
  559.                        
  560.                                 response = 1
  561.                         else
  562.                                 response = 0
  563.                         end
  564.                
  565.                 elseif tagName == "weapons\\shotgun\\shotgun" then
  566.                         if Shotgun[player] == 1 then
  567.                        
  568.                                 response = 1
  569.                         else
  570.                                 response = 0
  571.                         end
  572.                        
  573.                 elseif tagName == "weapons\\sniper rifle\\sniper rifle" then
  574.                         if Sniper[player] == 1 then
  575.                        
  576.                                 response = 1
  577.                         else
  578.                                 response = 0
  579.                         end
  580.                 end
  581.                
  582.         elseif tagType == "eqip" then
  583.        
  584.                 if tagName == "weapons\\frag grenade\\frag grenade" or tagName == "weapons\\plasma grenade\\plasma grenade" then
  585.                
  586.                 -- Don't let players pick up grenades.         
  587.                         response = 0
  588.                 else
  589.                 -- Let players pick up overshield, camo, and health.
  590.                         response = 1
  591.                 end
  592.         end
  593.                                
  594.         return response
  595. end
  596.  
  597.  
  598. function OnWeaponReload(player, weapon)
  599.  
  600.         return 1
  601. end
  602.  
  603.  
  604. function OnVehicleEntry(relevant, player, vehicleId, vehicle_tag, seat)
  605.  
  606.         return 1
  607. end
  608.  
  609.  
  610. function OnDamageLookup(receiving_obj, causing_obj, tagdata, tagname)
  611.  
  612.  
  613. end
  614.  
  615. function OnWeaponAssignment(player, object, count, tag)
  616.  
  617.         -- Make sure the weapon is being assigned to a player, not a vehicle
  618.        
  619.         if player ~= 0xFFFFFFFF then
  620.        
  621.                 -- Determine what weapon(s) a player will spawn with.  
  622.                         -- Sum it up.
  623.                
  624.                         local weap_sum = assault_rifle + pistol + needler + plasma_rifle + plasma_pistol + fuel_rod + rocket + flamethrower + shotgun + sniper
  625.                         local weap2_sum = no_weapon + assault_rifle_2 + pistol_2 + needler_2 + plasma_rifle_2 + plasma_pistol_2 + fuel_rod_2 + rocket_2 + flamethrower_2 + shotgun_2 + sniper_2
  626.                
  627.                 -- Find the highest precision used (see the GRENADES section for more info on how this works).
  628.                
  629.                         local w = {assault_rifle, pistol, needler, plasma_rifle, plasma_pistol, fuel_rod, rocket, flamethrower, shotgun, sniper}
  630.                         local w2 = {no_weapon, assault_rifle_2, pistol_2, needler_2, plasma_rifle_2, plasma_pistol_2, fuel_rod_2, rocket_2, flamethrower_2, shotgun_2, sniper_2}
  631.                         local precision = findHighestPrecision(w)
  632.                         local precision_2 = findHighestPrecision(w2)
  633.                         local x = 10^precision
  634.                         local y = 10^precision_2
  635.  
  636.                         local weapon = getrandomnumber(0, (weap_sum * x))
  637.                         local weapon2 = getrandomnumber(0, (weap2_sum * y))
  638.                
  639.                 -- Primary
  640.                
  641.                 if count == 0 then             
  642.                         if weapon >= 0 and weapon < (x * plasma_pistol) then
  643.                        
  644.                                 actualWeapon = lookuptag("weap", "weapons\\plasma pistol\\plasma pistol")
  645.                                 privatesay(player, "Plasma Pistol.")
  646.                                 PlasmaPistol[resolveplayer(player)] = 1
  647.  
  648.                         elseif weapon >= (x * plasma_pistol) and weapon < (x * (plasma_pistol + assault_rifle)) then
  649.  
  650.                                 actualWeapon = lookuptag("weap", "weapons\\assault rifle\\assault rifle")
  651.                                 privatesay(player, "Assault Rifle.")
  652.                                 AssaultRifle[resolveplayer(player)] = 1
  653.  
  654.                         elseif weapon >= (x * (plasma_pistol + assault_rifle)) and weapon < (x * (plasma_pistol + assault_rifle + plasma_rifle)) then
  655.  
  656.                                 actualWeapon = lookuptag("weap", "weapons\\plasma rifle\\plasma rifle")
  657.                                 privatesay(player, "Plasma Rifle.")
  658.                                 PlasmaRifle[resolveplayer(player)] = 1
  659.  
  660.                         elseif weapon >= (x * (plasma_pistol + assault_rifle + plasma_rifle)) and weapon < (x * (plasma_pistol + assault_rifle + plasma_rifle + pistol)) then
  661.  
  662.                                 actualWeapon = lookuptag("weap", "weapons\\pistol\\pistol")
  663.                                 privatesay(player, "Pistol.")
  664.                                 Pistol[resolveplayer(player)] = 1
  665.  
  666.                         elseif weapon >= (x * (plasma_pistol + assault_rifle + plasma_rifle + pistol)) and weapon < (x * (plasma_pistol + assault_rifle + plasma_rifle + pistol + shotgun)) then
  667.  
  668.                                 actualWeapon = lookuptag("weap", "weapons\\shotgun\\shotgun")  
  669.                                 privatesay(player, "Shotgun.")
  670.                                 Shotgun[resolveplayer(player)] = 1
  671.  
  672.                         elseif weapon >= (x * (plasma_pistol + assault_rifle + plasma_rifle + pistol + shotgun)) and weapon < (x * (plasma_pistol + assault_rifle + plasma_rifle + pistol + shotgun + needler)) then
  673.  
  674.                                 actualWeapon = lookuptag("weap", "weapons\\needler\\mp_needler")
  675.                                 privatesay(player, "Needler.")
  676.                                 Needler[resolveplayer(player)] = 1
  677.  
  678.                         elseif weapon >= (x * (plasma_pistol + assault_rifle + plasma_rifle + pistol + shotgun + needler)) and weapon < (x * (plasma_pistol + assault_rifle + plasma_rifle + pistol + shotgun + needler + sniper)) then
  679.  
  680.                                 actualWeapon = lookuptag("weap", "weapons\\sniper rifle\\sniper rifle")
  681.                                 privatesay(player, "Sniper.")
  682.                                 Sniper[resolveplayer(player)] = 1
  683.  
  684.                         elseif weapon >= (x * (plasma_pistol + assault_rifle + plasma_rifle + pistol + shotgun + needler + sniper)) and weapon < (x * (plasma_pistol + assault_rifle + plasma_rifle + pistol + shotgun + needler + sniper + flamethrower)) then
  685.  
  686.                                 actualWeapon = lookuptag("weap", "weapons\\flamethrower\\flamethrower")
  687.                                 privatesay(player, "Flamethrower.")
  688.                                 Flamethrower[resolveplayer(player)] = 1
  689.  
  690.                         elseif weapon >= (x * (plasma_pistol + assault_rifle + plasma_rifle + pistol + shotgun + needler + sniper + flamethrower)) and weapon < (x * (plasma_pistol + assault_rifle + plasma_rifle + pistol + shotgun + needler + sniper + flamethrower + rocket)) then
  691.  
  692.                                 actualWeapon = lookuptag("weap", "weapons\\rocket launcher\\rocket launcher")
  693.                                 privatesay(player, "Rocket.")
  694.                                 Rocket[resolveplayer(player)] = 1
  695.  
  696.                         elseif weapon >= (x * (plasma_pistol + assault_rifle + plasma_rifle + pistol + shotgun + needler + sniper + flamethrower + rocket)) and weapon < (x * weap_sum) then
  697.  
  698.                                 actualWeapon = lookuptag("weap", "weapons\\plasma_cannon\\plasma_cannon")
  699.                                 privatesay(player, "Fuel Rod.")
  700.                                 FuelRod[resolveplayer(player)] = 1
  701.                         end
  702.  
  703.                 -- Secondary
  704.                        
  705.                 elseif count == 1 then
  706.                        
  707.                         if weapon2 >= 0 and weapon2 < (y * plasma_pistol_2) then
  708.  
  709.                                 if PlasmaPistol[resolveplayer(player)] ~= 1 then   -- Make sure player doesn't spawn with the same primary and secondary weapon
  710.                                
  711.                                         actualWeapon = lookuptag("weap", "weapons\\plasma pistol\\plasma pistol")
  712.                                         privatesay(player, "Secondary: Plasma Pistol")
  713.                                         PlasmaPistol[resolveplayer(player)] = 1
  714.                                 end
  715.  
  716.                         elseif weapon2 >= (y * plasma_pistol_2) and weapon2 < (y * (plasma_pistol_2 + assault_rifle_2)) then
  717.  
  718.                                 if AssaultRifle[resolveplayer(player)] ~= 1 then
  719.                                
  720.                                         actualWeapon = lookuptag("weap", "weapons\\assault rifle\\assault rifle")
  721.                                         privatesay(player, "Secondary: Assault Rifle")
  722.                                         AssaultRifle[resolveplayer(player)] = 1
  723.                                 end
  724.  
  725.                         elseif weapon2 >= (y * (plasma_pistol_2 + assault_rifle_2)) and weapon2 < (y * (plasma_pistol_2 + assault_rifle_2 + plasma_rifle_2)) then
  726.  
  727.                                 if PlasmaRifle[resolveplayer(player)] ~= 1 then
  728.                                
  729.                                         actualWeapon = lookuptag("weap", "weapons\\plasma rifle\\plasma rifle")
  730.                                         privatesay(player, "Secondary: Plasma Rifle")
  731.                                         PlasmaRifle[resolveplayer(player)] = 1
  732.                                 end
  733.  
  734.                         elseif weapon2 >= (y * (plasma_pistol_2 + assault_rifle_2 + plasma_rifle_2)) and weapon2 < (y * (plasma_pistol_2 + assault_rifle_2 + plasma_rifle_2 + needler_2)) then
  735.  
  736.                                 if Needler[resolveplayer(player)] ~= 1 then
  737.                                
  738.                                         actualWeapon = lookuptag("weap", "weapons\\needler\\mp_needler")
  739.                                         privatesay(player, "Secondary: Needler")
  740.                                         Needler[resolveplayer(player)] = 1
  741.                                 end
  742.  
  743.                         elseif weapon2 >= (y * (plasma_pistol_2 + assault_rifle_2 + plasma_rifle_2 + needler_2)) and weapon2 < (y * (plasma_pistol_2 + assault_rifle_2 + plasma_rifle_2 + needler_2 + pistol_2)) then
  744.  
  745.                                 if Pistol[resolveplayer(player)] ~= 1 then
  746.                                
  747.                                         actualWeapon = lookuptag("weap", "weapons\\pistol\\pistol")
  748.                                         privatesay(player, "Secondary: Pistol")
  749.                                         Pistol[resolveplayer(player)] = 1
  750.                                 end
  751.  
  752.                         elseif weapon2 >= (y * (plasma_pistol_2 + assault_rifle_2 + plasma_rifle_2 + needler_2 + pistol_2)) and weapon2 < (y * (plasma_pistol_2 + assault_rifle_2 + plasma_rifle_2 + needler_2 + pistol_2 + shotgun_2)) then
  753.  
  754.                                 if Shotgun[resolveplayer(player)] ~= 1 then
  755.                                
  756.                                         actualWeapon = lookuptag("weap", "weapons\\shotgun\\shotgun")
  757.                                         privatesay(player, "Secondary: Shotgun")
  758.                                         Shotgun[resolveplayer(player)] = 1
  759.                                 end
  760.  
  761.                         elseif weapon2 >= (y * (plasma_pistol_2 + assault_rifle_2 + plasma_rifle_2 + needler_2 + pistol_2 + shotgun_2)) and weapon2 < (y * (plasma_pistol_2 + assault_rifle_2 + plasma_rifle_2 + needler_2 + pistol_2 + shotgun_2 + sniper_2)) then
  762.  
  763.                                 if Sniper[resolveplayer(player)] ~= 1 then
  764.                                
  765.                                         actualWeapon = lookuptag("weap", "weapons\\sniper rifle\\sniper rifle")
  766.                                         privatesay(player, "Secondary: Sniper")
  767.                                         Sniper[resolveplayer(player)] = 1
  768.                                 end
  769.  
  770.                         elseif weapon2 >= (y * (plasma_pistol_2 + assault_rifle_2 + plasma_rifle_2 + needler_2 + pistol_2 + shotgun_2 + sniper_2)) and weapon2 < (y * (plasma_pistol_2 + assault_rifle_2 + plasma_rifle_2 + needler_2 + pistol_2 + shotgun_2 + sniper_2 + rocket_2)) then
  771.  
  772.                                 if Rocket[resolveplayer(player)] ~= 1 then
  773.                                
  774.                                         actualWeapon = lookuptag("weap", "weapons\\rocket launcher\\rocket launcher")
  775.                                         privatesay(player, "Secondary: Rocket Launcher")
  776.                                         Rocket[resolveplayer(player)] = 1
  777.                                 end
  778.  
  779.                         elseif weapon2 >= (y * (plasma_pistol_2 + assault_rifle_2 + plasma_rifle_2 + needler_2 + pistol_2 + shotgun_2 + sniper_2 + rocket_2)) and weapon2 < (y * (plasma_pistol_2 + assault_rifle_2 + plasma_rifle_2 + needler_2 + pistol_2 + shotgun_2 + sniper_2 + rocket_2 + flamethrower_2)) then
  780.  
  781.                                 if Flamethrower[resolveplayer(player)] ~= 1 then
  782.                                
  783.                                         actualWeapon = lookuptag("weap", "weapons\\flamethrower\\flamethrower")
  784.                                         privatesay(player, "Secondary: Flamethrower")
  785.                                         Flamethrower[resolveplayer(player)] = 1
  786.                                 end
  787.  
  788.                         elseif weapon2 >= (y * (plasma_pistol_2 + assault_rifle_2 + plasma_rifle_2 + needler_2 + pistol_2 + shotgun_2 + sniper_2 + rocket_2 + flamethrower_2)) and weapon2 < (y * (plasma_pistol_2 + assault_rifle_2 + plasma_rifle_2 + needler_2 + pistol_2 + shotgun_2 + sniper_2 + rocket_2 + flamethrower_2 + fuel_rod_2)) then
  789.  
  790.                                 if FuelRod[resolveplayer(player)] ~= 1 then
  791.                                
  792.                                         actualWeapon = lookuptag("weap", "weapons\\plasma_cannon\\plasma_cannon")
  793.                                         privatesay(player, "Secondary: Fuel Rod")
  794.                                         FuelRod[resolveplayer(player)] = 1
  795.                                 end
  796.                         end
  797.                 end
  798.         end
  799.  
  800.         return actualWeapon
  801. end
  802.  
  803.  
  804. function OnObjectCreation(m_objId, player_owner, tagName)
  805.  
  806.  
  807. end
  808.  
  809. function OnClientUpdate(player, m_object)
  810.  
  811.  
  812. end
  813.  
  814. function OnVehicleEject(player, forced)
  815.  
  816.         return 1
  817. end
  818.  
  819. function findHighestPrecision(array)
  820.  
  821.         local precision = 0   -- Initialize.
  822.        
  823.         for i = 1, #array do   -- From the first element of the array to the last, do...       
  824.        
  825.                 local p = getPrecision(array[i])   -- Get the precision of each element.
  826.                
  827.                 if p > precision then          
  828.                         precision = p   -- Set the highest value found to the variable "precision".
  829.                 end
  830.         end
  831.        
  832.         return precision   -- return it.
  833. end
  834.  
  835. function getPrecision(number)
  836.  
  837.         local temp = math.ceil(number)   -- Truncate digits after the decimal (could use math.floor here too; doesn't really matter).
  838.         local count = 0   -- Initialize a count.
  839.        
  840.         while temp ~= number do   -- If these are equal, our precision has been reached.
  841.        
  842.                 number = number * 10   -- Move to the next decimal place.
  843.                 temp = math.ceil(number)   -- Set temp to be the truncated version of this new number.
  844.                 count = count + 1   -- Increase the count.
  845.         end
  846.        
  847.         return count   -- Return the precision of the number.
  848. end
  849.  
  850. function applyos(player)
  851.  
  852.         boolean = false   -- Initialize
  853.         local hash = gethash(player)
  854.        
  855.         if hash ~= nil then   -- Make sure player exists
  856.        
  857.                 local m_player = getplayer(player)
  858.                
  859.                 if m_player ~= nil then
  860.                
  861.                         local m_objId = readdword(m_player, 0x34)
  862.                         local m_object = getobject(m_objId)
  863.                        
  864.                         if m_object ~= nil then   -- Make sure player is alive
  865.                        
  866.                                 -- Get player's coordinates
  867.                                 local x = readfloat(m_object, 0x5C)
  868.                                 local y = readfloat(m_object, 0x60)
  869.                                 local z = readfloat(m_object, 0x64)
  870.                                
  871.                                 createobject("eqip", "powerups\\over shield", 0, 0, false, x, y, z)   -- Create Overshield
  872.                                
  873.                                 boolean = true  -- The application was successful
  874.                         end
  875.                 end
  876.         end
  877.        
  878.         return boolean   -- Return success or failure of application
  879. end
  880.  
  881. -- This function is courtesy of Smiley's awesomeness
  882.  
  883. function convertbase(inputbase, outputbase, input)
  884.  
  885.         local power = 0
  886.         local answer = 0
  887.         local number = math.floor(input / (outputbase^power))
  888.         local check = true
  889.  
  890.         for word in string.gmatch(tostring(input), "%d") do
  891.                 if tonumber(word) >= inputbase then
  892.                         check = false
  893.                         break
  894.                 end
  895.         end
  896.  
  897.         if check == false then
  898.                 answer = 0
  899.         else
  900.                 if input == 0 then
  901.                         answer = 0
  902.                 else
  903.  
  904.                         while number ~= 1 do
  905.                                 power = power + 1
  906.                                 number = math.floor(input / (outputbase^power))
  907.                         end
  908.  
  909.                         while power >= 0 do
  910.                                 number = math.floor(input / (outputbase^power))
  911.                                 input = input - (number * (outputbase^power))
  912.                                 answer = answer + (number * (inputbase^power))
  913.                                 power = power - 1
  914.                         end
  915.                 end
  916.         end
  917.  
  918.         return answer
  919. end
  920.  
  921. --[[function HelpTimer(id, count, player)
  922.  
  923.         if count == 15 then
  924.                 privatesay(player, "FAQ: Why can't I pick up weapons?")
  925.         elseif count == 18 then
  926.                 privatesay(player, "You spawn with a random weapon set and are stuck with it until you die.")
  927.                 return 0
  928.         end
  929.        
  930.         return 1
  931. end
  932.  
  933. function ScriptTimer(id, count)
  934.  
  935.         hprintf("Script: UniversalRandomWeapon")
  936.  
  937.         return 1
  938. end--]]

HaloNet.Net is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.