Guest User

Untitled

a guest
Apr 27th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 28.01 KB | None | 0 0
  1. -- RandomWeapon
  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, welcome_message)
  177. end
  178.  
  179. function OnPlayerLeave(player, team)
  180.  
  181.  
  182. end
  183.  
  184.  
  185. function OnPlayerKill(killer, victim, mode)
  186.  
  187.     privatesay(victim, death_message)  
  188.     local victimId = resolveplayer(victim)
  189.    
  190.     -- Reset all weapon values of the victim to 0.
  191.    
  192.     AssaultRifle[victimId] = 0
  193.     Pistol[victimId] = 0
  194.     Needler[victimId] = 0
  195.     PlasmaRifle[victimId] = 0
  196.     PlasmaPistol[victimId] = 0
  197.     FuelRod[victimId] = 0
  198.     Rocket[victimId] = 0
  199.     Flamethrower[victimId] = 0
  200.     Shotgun[victimId] = 0
  201.     Sniper[victimId] = 0
  202. end
  203.  
  204.  
  205. function OnKillMultiplier(player, multiplier)
  206.  
  207.  
  208. end
  209.  
  210.  
  211. function OnPlayerSpawn(player, m_objectId)
  212.  
  213.  
  214. end
  215.  
  216. function OnPlayerSpawnEnd(player, m_objectId)
  217.  
  218. -- GRENADES
  219.  
  220.     -- Determine whether a player will spawn with grenades, and if so, what kind and how many. 
  221.     -- Sum up all of the values entered in the probabilities.
  222.  
  223.         local grenade_sum = no_grenades + one_frag + two_frags + one_plasma + two_plasmas + two_of_each + four_of_each
  224.    
  225.     -- Find the highest precision used out of all of the values entered.       
  226.         -- Create array
  227.         local g = {no_grenades, one_frag, two_frags, one_plasma, two_plasmas, two_of_each, four_of_each}
  228.        
  229.         -- Find the highest precision out of all elements of the array.
  230.         local g_precision = findHighestPrecision(g)
  231.        
  232.         -- Be lazy.
  233.         local x = 10^g_precision
  234.        
  235.         -- Get a random number:  0 <= grenade < (grenade_sum * 10^precision)
  236.         local grenade = getrandomnumber(0, (grenade_sum * x))
  237.  
  238.     local m_Object = getobject(m_objectId)
  239.    
  240.     -- Determine what the random number will do.
  241.    
  242.         if m_Object ~= 0 then
  243.             if grenade >= 0 and grenade < (no_grenades * x) then
  244.  
  245.                 writebyte(m_Object, 0x31E, 0)  -- set frag grenades to 0
  246.                 writebyte(m_Object, 0x31F, 0)  -- set plasmas to 0
  247.  
  248.             elseif grenade >= (no_grenades * x) and grenade < (x * (no_grenades + one_frag)) then
  249.  
  250.                 writebyte(m_Object, 0x31E, 1)  -- set frags to 1
  251.                 writebyte(m_Object, 0x31F, 0)  -- plasmas to 0
  252.  
  253.                 privatesay(player, "A Frag Grenade.")  -- tell the player what they spawned with
  254.  
  255.             elseif grenade >= (x * (no_grenades + one_frag)) and grenade < (x * (no_grenades + one_frag + one_plasma)) then
  256.  
  257.                 writebyte(m_Object, 0x31E, 0)  -- yadayadayada
  258.                 writebyte(m_Object, 0x31F, 1)  -- yada.
  259.  
  260.                 privatesay(player, "A Plasma Grenade.")
  261.  
  262.             elseif grenade >= (x * (no_grenades + one_frag + one_plasma)) and grenade < (x * (no_grenades + one_frag + one_plasma + two_frags)) then
  263.  
  264.                 writebyte(m_Object, 0x31E, 2)
  265.                 writebyte(m_Object, 0x31F, 0)
  266.  
  267.                 privatesay(player, "Two Frag Grenades.")
  268.  
  269.             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
  270.  
  271.                 writebyte(m_Object, 0x31E, 0)
  272.                 writebyte(m_Object, 0x31F, 2)
  273.  
  274.                 privatesay(player, "Two Plasma Grenades.")
  275.  
  276.             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
  277.  
  278.                 writebyte(m_Object, 0x31E, 2)
  279.                 writebyte(m_Object, 0x31F, 2)
  280.  
  281.                 privatesay(player, "Two of each Grenade.")
  282.  
  283.             elseif grenade >= (x * (no_grenades + one_frag + one_plasma + two_frags + two_plasmas + two_of_each)) and grenade < (grenade_sum * x) then
  284.  
  285.                 writebyte(m_Object, 0x31E, 4)
  286.                 writebyte(m_Object, 0x31F, 4)
  287.  
  288.                 privatesay(player, "Four of each Grenade.")
  289.             end
  290.         end
  291.    
  292. -- SPECIAL ATTRIBUTES
  293.  
  294.     -- Determine whether a player will spawn with camouflage, overshield, or extra speed.  
  295.     -- Sum up the values
  296.  
  297.         local special_sum = invisible + overshield + extra_speed + invis_overshield + invis_speed + overshield_speed + all_special + none
  298.    
  299.     -- Find the highest precision used (see the GRENADES section for info on what's going on here).
  300.    
  301.         local s = {invisible, overshield, extra_speed, invis_overshield, invis_speed, overshield_speed, all_special, none}
  302.         local s_precision = findHighestPrecision(s)
  303.         local y = 10^s_precision
  304.    
  305.         local gametype_base = 0x671340
  306.         local gametype_game = readbyte(gametype_base, 0x30)   -- Make sure this isn't an Oddball or Race gametype where speed cannot be changed
  307.        
  308.     -- Determine whether this is a shields or no-shields gametype so players don't spawn with "overshield" in a no-shields gametype.
  309.    
  310.         local gametype_parameters = readbyte(gametype_base, 0x38)
  311.         local binary = convertbase(10, 2, gametype_parameters)  -- gametype_parameters is represented in binary...
  312.         local obj_max_shields = 0  
  313.        
  314.         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
  315.        
  316.             obj_max_shields = 1
  317.         end
  318.    
  319.         local special = getrandomnumber(0, (special_sum * y))
  320.  
  321.     -- Put it all together and do magical stuff.
  322.        
  323.         if special >= 0 and special < (invisible * y) then
  324.  
  325.             applycamo(player, 0)
  326.             setspeed(player, 1)
  327.             privatesay(player, "You are invisible!")
  328.  
  329.         elseif special >= (invisible * y) and special < (y * (invisible + extra_speed)) then
  330.  
  331.             if gametype_game ~= 3 and gametype_game ~= 5 then   -- make sure this isn't oddball or race
  332.                 setspeed(player, speed)
  333.                 privatesay(player, "You have increased speed!")
  334.             end
  335.  
  336.         elseif special >= (y * (invisible + extra_speed)) and special < (y * (invisible + extra_speed + invis_speed)) then
  337.  
  338.             if gametype_game ~= 3 and gametype_game ~= 5 then
  339.                 applycamo(player, 0)
  340.                 setspeed(player, speed)
  341.                 privatesay(player, "You are invisible AND have increased speed!")
  342.             end
  343.            
  344.         elseif special >= (y * (invisible + extra_speed + invis_speed)) and special < (y * (invisible + extra_speed + invis_speed + overshield)) then
  345.        
  346.             if obj_max_shields ~= 0 then   -- make sure players have shields in this gametype
  347.                 local m_player = getplayer(player)
  348.                 local m_objId = readdword(m_player, 0x34)
  349.                 local m_object = getobject(m_objId)
  350.                 writefloat(m_object, 0xE4, 3)
  351.                 setspeed(player, 1)
  352.                 privatesay(player, "You have overshield!")
  353.             else
  354.                 setspeed(player, 1)
  355.             end
  356.            
  357.         elseif special >= (y * (invisible + extra_speed + invis_speed + overshield)) and special < (y * (invisible + extra_speed + invis_speed + overshield + invis_overshield)) then
  358.        
  359.             if obj_max_shields ~= 0 then
  360.                 local m_player = getplayer(player)
  361.                 local m_objId = readdword(m_player, 0x34)
  362.                 local m_object = getobject(m_objId)
  363.                 writefloat(m_object, 0xE4, 3)
  364.                 applycamo(player, 0)
  365.                 setspeed(player, 1)
  366.                 privatesay(player, "You are invisible AND have overshield!")
  367.             else
  368.                 setspeed(player, 1)
  369.             end
  370.            
  371.         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
  372.        
  373.             if obj_max_shields ~= 0 and gametype_game ~= 3 and gametype_game ~= 5 then
  374.                 local m_player = getplayer(player)
  375.                 local m_objId = readdword(m_player, 0x34)
  376.                 local m_object = getobject(m_objId)
  377.                 writefloat(m_object, 0xE4, 3)
  378.                 setspeed(player, speed)
  379.                 privatesay(player, "You have overshield AND extra speed!")
  380.             else
  381.                 setspeed(player, 1)
  382.             end
  383.            
  384.         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
  385.        
  386.             if obj_max_shields ~= 0 and gametype_game ~= 3 and gametype_game ~= 5 then
  387.                 local m_player = getplayer(player)
  388.                 local m_objId = readdword(m_player, 0x34)
  389.                 local m_object = getobject(m_objId)
  390.                 writefloat(m_object, 0xE4, 3)
  391.                 applycamo(player, 0)
  392.                 setspeed(player, speed)
  393.                 privatesay(player, "JACKPOT: All special attributes!")
  394.             else
  395.                 setspeed(player, 1)
  396.             end
  397.  
  398.         elseif special >= (y * (invisible + extra_speed + invis_speed + overshield + invis_overshield + overshield_speed + all_special)) and special < (y * special_sum) then
  399.  
  400.             setspeed(player, 1.0)
  401.         end
  402.    
  403. -- AMMO ATTRIBUTES
  404.  
  405.     -- Determine whether a player will spawn with extra ammo.
  406.    
  407.         local ammo_sum = normal_ammo + double_ammo + triple_ammo + ammotacular + infinite_ammo
  408.    
  409.     -- Find the highest precision used (see the GRENADES section for more info on how this works).
  410.    
  411.         local a = {normal_ammo, double_ammo, triple_ammo, ammotacular, infinite_ammo}
  412.         local a_precision = findHighestPrecision(a)
  413.         local z = 10^a_precision
  414.        
  415.         local ammo = getrandomnumber(0, (ammo_sum * z))
  416.    
  417.     local m_player = getplayer(player)
  418.     local ammo_multiplier = 1   -- Initialize an ammo multiplier
  419.  
  420.     -- Get a player's weapons.....
  421.    
  422.     if m_player ~= -1 then
  423.    
  424.         local m_ObjId = readdword(m_player, 0x34)
  425.         local m_object = getobject(m_ObjId)
  426.  
  427.         if m_object ~= -1 then
  428.             for i = 0, 3 do   -- For primary, secondary, ternary, and quartary weapons do...
  429.            
  430.                 local m_weaponId = readdword(m_object, 0x2F8 + (i*4))   -- Get the weapon ID of each weapon (incrementing by four bytes each time)
  431.  
  432.                 if m_weaponId ~= -1 then
  433.  
  434.                     local m_weapon = getobject(m_weaponId)
  435.  
  436.                     if m_weapon ~= -1 then
  437.                    
  438.                         -- Make sure the player isn't getting "extra ammo" in his/her plasma weapon
  439.                        
  440.                         if PlasmaRifle[resolveplayer(player)] ~= 1 and PlasmaPistol[resolveplayer(player)] ~= 1 and FuelRod[resolveplayer(player)] ~= 1 then
  441.                    
  442.                         -- Do all the shmexy stuff.
  443.                        
  444.                             local weap_ammo = readword(m_weapon, 0x2B6)
  445.                            
  446.                             if ammo >= 0 and ammo < (double_ammo * z) then
  447.                        
  448.                                 writeword(m_weapon, 0x2B6, weap_ammo * 2)
  449.                                 ammo_multiplier = 2
  450.                                
  451.                             elseif ammo >= (double_ammo * z) and ammo < (z * (double_ammo + triple_ammo)) then
  452.                            
  453.                                 writeword(m_weapon, 0x2B6, weap_ammo * 3)                              
  454.                                 ammo_multiplier = 3
  455.                                
  456.                             elseif ammo >= (z * (double_ammo + triple_ammo)) and ammo < (z * (double_ammo + triple_ammo + ammotacular)) then
  457.                            
  458.                                 writeword(m_weapon, 0x2B6, weap_ammo * 4)                              
  459.                                 ammo_multiplier = 4
  460.                                
  461.                             elseif ammo >= (z * (double_ammo + triple_ammo + ammotacular)) and ammo < (z * (double_ammo + triple_ammo + ammotacular + infinite_ammo)) then
  462.                            
  463.                                 writeword(m_weapon, 0x2B6, 9999)                           
  464.                                 ammo_multiplier = 5                        
  465.                             end
  466.                         end
  467.                     end
  468.                 end
  469.             end
  470.         end
  471.     end
  472.        
  473.     -- Print the messages (if you print the messages in the loop above, the player will be spammed the same message for each weapon)
  474.    
  475.     if ammo_multiplier == 2 then
  476.         privatesay(player, "Double Ammo!")
  477.     elseif ammo_multiplier == 3 then
  478.         privatesay(player, "Triple Ammo!")
  479.     elseif ammo_multiplier == 4 then
  480.         privatesay(player, "Ammotacular!")
  481.     elseif ammo_multiplier == 5 then
  482.         privatesay(player, "JACKPOT: INFINITE AMMO!")
  483.     end
  484. end
  485.  
  486.  
  487. function OnTeamChange(relevant, player, team, dest_team)
  488.  
  489.     return 1
  490. end
  491.  
  492.  
  493. function OnObjectInteraction(player, m_ObjectId, tagType, tagName)
  494.  
  495.     -- Set values of "player" so they can be accessed in the weapon arrays (since there is no "0th" element of an array in Lua)
  496.    
  497.     local player = resolveplayer(player)
  498.  
  499.     -- Make sure players can always pick up the flag.
  500.    
  501.     if tagType == "weap" then
  502.         if tagName == "weapons\\flag\\flag" then
  503.        
  504.             response = 1
  505.  
  506.         -- Based on weapon values, determine what weapon(s) a player can interact with.
  507.            
  508.         elseif tagName == "weapons\\assault rifle\\assault rifle" then
  509.             if AssaultRifle[player] == 1 then
  510.            
  511.                 response = 1
  512.             else
  513.                 response = 0
  514.             end
  515.  
  516.         elseif tagName == "weapons\\pistol\\pistol" then
  517.             if Pistol[player] == 1 then
  518.            
  519.                 response = 1
  520.             else
  521.                 response = 0
  522.             end
  523.  
  524.         elseif tagName == "weapons\\plasma rifle\\plasma rifle" then
  525.             if PlasmaRifle[player] == 1 then
  526.            
  527.                 response = 1
  528.             else
  529.                 response = 0
  530.             end
  531.    
  532.         elseif tagName == "weapons\\plasma pistol\\plasma pistol" then
  533.             if PlasmaPistol[player] == 1 then
  534.            
  535.                 response = 1
  536.             else
  537.                 response = 0
  538.             end
  539.  
  540.         elseif tagName == "weapons\\needler\\mp_needler" then
  541.             if Needler[player] == 1 then
  542.            
  543.                 response = 1
  544.             else
  545.                 response = 0
  546.             end
  547.  
  548.         elseif tagName == "weapons\\flamethrower\\flamethrower" then
  549.             if Flamethrower[player] == 1 then
  550.            
  551.                 response = 1
  552.             else
  553.                 response = 0
  554.             end
  555.  
  556.         elseif tagName == "weapons\\plasma_cannon\\plasma_cannon" then
  557.             if FuelRod[player] == 1 then
  558.            
  559.                 response = 1
  560.             else
  561.                 response = 0
  562.             end
  563.  
  564.         elseif tagName == "weapons\\rocket launcher\\rocket launcher" then
  565.             if Rocket[player] == 1 then
  566.            
  567.                 response = 1
  568.             else
  569.                 response = 0
  570.             end
  571.        
  572.         elseif tagName == "weapons\\shotgun\\shotgun" then
  573.             if Shotgun[player] == 1 then
  574.            
  575.                 response = 1
  576.             else
  577.                 response = 0
  578.             end
  579.            
  580.         elseif tagName == "weapons\\sniper rifle\\sniper rifle" then
  581.             if Sniper[player] == 1 then
  582.            
  583.                 response = 1
  584.             else
  585.                 response = 0
  586.             end
  587.         end
  588.        
  589.     elseif tagType == "eqip" then
  590.    
  591.         if tagName == "weapons\\frag grenade\\frag grenade" or tagName == "weapons\\plasma grenade\\plasma grenade" then
  592.        
  593.         -- Don't let players pick up grenades.     
  594.             response = 0
  595.         else
  596.         -- Let players pick up overshield, camo, and health.
  597.             response = 1
  598.         end
  599.     end
  600.                
  601.     return response
  602. end
  603.  
  604.  
  605. function OnWeaponReload(player, weapon)
  606.  
  607.     return 1
  608. end
  609.  
  610.  
  611. function OnVehicleEntry(relevant, player, vehicleId, vehicle_tag, seat)
  612.  
  613.     return 1
  614. end
  615.  
  616.  
  617. function OnDamageLookup(receiving_obj, causing_obj, tagdata, tagname)
  618.  
  619.  
  620. end
  621.  
  622. function OnWeaponAssignment(player, object, count, tag)
  623.  
  624.     -- Make sure the weapon is being assigned to a player, not a vehicle
  625.    
  626.     if player >= 0 and player < 16 then
  627.    
  628.         -- Determine what weapon(s) a player will spawn with.  
  629.             -- Sum it up.
  630.        
  631.             local weap_sum = assault_rifle + pistol + needler + plasma_rifle + plasma_pistol + fuel_rod + rocket + flamethrower + shotgun + sniper
  632.             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
  633.        
  634.         -- Find the highest precision used (see the GRENADES section for more info on how this works).
  635.        
  636.             local w = {assault_rifle, pistol, needler, plasma_rifle, plasma_pistol, fuel_rod, rocket, flamethrower, shotgun, sniper}
  637.             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}
  638.             local precision = findHighestPrecision(w)
  639.             local precision_2 = findHighestPrecision(w2)
  640.             local x = 10^precision
  641.             local y = 10^precision_2
  642.  
  643.             local weapon = getrandomnumber(0, (weap_sum * x))
  644.             local weapon2 = getrandomnumber(0, (weap2_sum * y))
  645.        
  646.         -- Primary
  647.        
  648.         if count == 0 then     
  649.             if weapon >= 0 and weapon < (x * plasma_pistol) then
  650.            
  651.                 actualWeapon = lookuptag("weap", "weapons\\plasma pistol\\plasma pistol")
  652.                 privatesay(player, "Plasma Pistol.")
  653.                 PlasmaPistol[resolveplayer(player)] = 1
  654.  
  655.             elseif weapon >= (x * plasma_pistol) and weapon < (x * (plasma_pistol + assault_rifle)) then
  656.  
  657.                 actualWeapon = lookuptag("weap", "weapons\\assault rifle\\assault rifle")
  658.                 privatesay(player, "Assault Rifle.")
  659.                 AssaultRifle[resolveplayer(player)] = 1
  660.  
  661.             elseif weapon >= (x * (plasma_pistol + assault_rifle)) and weapon < (x * (plasma_pistol + assault_rifle + plasma_rifle)) then
  662.  
  663.                 actualWeapon = lookuptag("weap", "weapons\\plasma rifle\\plasma rifle")
  664.                 privatesay(player, "Plasma Rifle.")
  665.                 PlasmaRifle[resolveplayer(player)] = 1
  666.  
  667.             elseif weapon >= (x * (plasma_pistol + assault_rifle + plasma_rifle)) and weapon < (x * (plasma_pistol + assault_rifle + plasma_rifle + pistol)) then
  668.  
  669.                 actualWeapon = lookuptag("weap", "weapons\\pistol\\pistol")
  670.                 privatesay(player, "Pistol.")
  671.                 Pistol[resolveplayer(player)] = 1
  672.  
  673.             elseif weapon >= (x * (plasma_pistol + assault_rifle + plasma_rifle + pistol)) and weapon < (x * (plasma_pistol + assault_rifle + plasma_rifle + pistol + shotgun)) then
  674.  
  675.                 actualWeapon = lookuptag("weap", "weapons\\shotgun\\shotgun")  
  676.                 privatesay(player, "Shotgun.")
  677.                 Shotgun[resolveplayer(player)] = 1
  678.  
  679.             elseif weapon >= (x * (plasma_pistol + assault_rifle + plasma_rifle + pistol + shotgun)) and weapon < (x * (plasma_pistol + assault_rifle + plasma_rifle + pistol + shotgun + needler)) then
  680.  
  681.                 actualWeapon = lookuptag("weap", "weapons\\needler\\mp_needler")
  682.                 privatesay(player, "Needler.")
  683.                 Needler[resolveplayer(player)] = 1
  684.  
  685.             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
  686.  
  687.                 actualWeapon = lookuptag("weap", "weapons\\sniper rifle\\sniper rifle")
  688.                 privatesay(player, "Sniper.")
  689.                 Sniper[resolveplayer(player)] = 1
  690.  
  691.             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
  692.  
  693.                 actualWeapon = lookuptag("weap", "weapons\\flamethrower\\flamethrower")
  694.                 privatesay(player, "Flamethrower.")
  695.                 Flamethrower[resolveplayer(player)] = 1
  696.  
  697.             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
  698.  
  699.                 actualWeapon = lookuptag("weap", "weapons\\rocket launcher\\rocket launcher")
  700.                 privatesay(player, "Rocket.")
  701.                 Rocket[resolveplayer(player)] = 1
  702.  
  703.             elseif weapon >= (x * (plasma_pistol + assault_rifle + plasma_rifle + pistol + shotgun + needler + sniper + flamethrower + rocket)) and weapon < (x * weap_sum) then
  704.  
  705.                 actualWeapon = lookuptag("weap", "weapons\\plasma_cannon\\plasma_cannon")
  706.                 privatesay(player, "Fuel Rod.")
  707.                 FuelRod[resolveplayer(player)] = 1
  708.             end
  709.  
  710.         -- Secondary
  711.            
  712.         elseif count == 1 then
  713.            
  714.             if weapon2 >= 0 and weapon2 < (y * plasma_pistol_2) then
  715.  
  716.                 if PlasmaPistol[resolveplayer(player)] ~= 1 then   -- Make sure player doesn't spawn with the same primary and secondary weapon
  717.                
  718.                     actualWeapon = lookuptag("weap", "weapons\\plasma pistol\\plasma pistol")
  719.                     privatesay(player, "Secondary: Plasma Pistol")
  720.                     PlasmaPistol[resolveplayer(player)] = 1
  721.                 end
  722.  
  723.             elseif weapon2 >= (y * plasma_pistol_2) and weapon2 < (y * (plasma_pistol_2 + assault_rifle_2)) then
  724.  
  725.                 if AssaultRifle[resolveplayer(player)] ~= 1 then
  726.                
  727.                     actualWeapon = lookuptag("weap", "weapons\\assault rifle\\assault rifle")
  728.                     privatesay(player, "Secondary: Assault Rifle")
  729.                     AssaultRifle[resolveplayer(player)] = 1
  730.                 end
  731.  
  732.             elseif weapon2 >= (y * (plasma_pistol_2 + assault_rifle_2)) and weapon2 < (y * (plasma_pistol_2 + assault_rifle_2 + plasma_rifle_2)) then
  733.  
  734.                 if PlasmaRifle[resolveplayer(player)] ~= 1 then
  735.                
  736.                     actualWeapon = lookuptag("weap", "weapons\\plasma rifle\\plasma rifle")
  737.                     privatesay(player, "Secondary: Plasma Rifle")
  738.                     PlasmaRifle[resolveplayer(player)] = 1
  739.                 end
  740.  
  741.             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
  742.  
  743.                 if Needler[resolveplayer(player)] ~= 1 then
  744.                
  745.                     actualWeapon = lookuptag("weap", "weapons\\needler\\mp_needler")
  746.                     privatesay(player, "Secondary: Needler")
  747.                     Needler[resolveplayer(player)] = 1
  748.                 end
  749.  
  750.             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
  751.  
  752.                 if Pistol[resolveplayer(player)] ~= 1 then
  753.                
  754.                     actualWeapon = lookuptag("weap", "weapons\\pistol\\pistol")
  755.                     privatesay(player, "Secondary: Pistol")
  756.                     Pistol[resolveplayer(player)] = 1
  757.                 end
  758.  
  759.             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
  760.  
  761.                 if Shotgun[resolveplayer(player)] ~= 1 then
  762.                
  763.                     actualWeapon = lookuptag("weap", "weapons\\shotgun\\shotgun")
  764.                     privatesay(player, "Secondary: Shotgun")
  765.                     Shotgun[resolveplayer(player)] = 1
  766.                 end
  767.  
  768.             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
  769.  
  770.                 if Sniper[resolveplayer(player)] ~= 1 then
  771.                
  772.                     actualWeapon = lookuptag("weap", "weapons\\sniper rifle\\sniper rifle")
  773.                     privatesay(player, "Secondary: Sniper")
  774.                     Sniper[resolveplayer(player)] = 1
  775.                 end
  776.  
  777.             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
  778.  
  779.                 if Rocket[resolveplayer(player)] ~= 1 then
  780.                
  781.                     actualWeapon = lookuptag("weap", "weapons\\rocket launcher\\rocket launcher")
  782.                     privatesay(player, "Secondary: Rocket Launcher")
  783.                     Rocket[resolveplayer(player)] = 1
  784.                 end
  785.  
  786.             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
  787.  
  788.                 if Flamethrower[resolveplayer(player)] ~= 1 then
  789.                
  790.                     actualWeapon = lookuptag("weap", "weapons\\flamethrower\\flamethrower")
  791.                     privatesay(player, "Secondary: Flamethrower")
  792.                     Flamethrower[resolveplayer(player)] = 1
  793.                 end
  794.  
  795.             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
  796.  
  797.                 if FuelRod[resolveplayer(player)] ~= 1 then
  798.                
  799.                     actualWeapon = lookuptag("weap", "weapons\\plasma_cannon\\plasma_cannon")
  800.                     privatesay(player, "Secondary: Fuel Rod")
  801.                     FuelRod[resolveplayer(player)] = 1
  802.                 end--]]
  803.             end
  804.         end
  805.     end
  806.  
  807.     return actualWeapon
  808. end
  809.  
  810.  
  811. function OnObjectCreation(m_objectId, player_owner, tag)
  812.  
  813.  
  814. end
  815.  
  816. function findHighestPrecision(array)
  817.  
  818.     local precision = 0   -- Initialize.
  819.    
  820.     for i = 1, #array do   -- From the first element of the array to the last, do...   
  821.    
  822.         local p = getPrecision(array[i])   -- Get the precision of each element.
  823.        
  824.         if p > precision then      
  825.             precision = p   -- Set the highest value found to the variable "precision".
  826.         end
  827.     end
  828.    
  829.     return precision   -- return it.
  830. end
  831.  
  832. function getPrecision(number)
  833.  
  834.     local temp = math.ceil(number)   -- Truncate digits after the decimal (could use math.floor here too; doesn't really matter).
  835.     local count = 0   -- Initialize a count.
  836.    
  837.     while temp ~= number do   -- If these are equal, our precision has been reached.
  838.    
  839.         number = number * 10   -- Move to the next decimal place.
  840.         temp = math.ceil(number)   -- Set temp to be the truncated version of this new number.
  841.         count = count + 1   -- Increase the count.
  842.     end
  843.    
  844.     return count   -- Return the precision of the number.
  845. end
  846.  
  847. -- This function is courtesy of Smiley's awesomeness
  848.  
  849. function convertbase(inputbase, outputbase, input)
  850.  
  851.     local power = 0
  852.     local answer = 0
  853.     local number = math.floor(input / (outputbase^power))
  854.     local check = true
  855.  
  856.     for word in string.gmatch(tostring(input), "%d") do
  857.         if tonumber(word) >= inputbase then
  858.             check = false
  859.             break
  860.         end
  861.     end
  862.  
  863.     if check == false then
  864.         answer = 0
  865.     else
  866.         if input == 0 then
  867.             answer = 0
  868.         else
  869.  
  870.             while number ~= 1 do
  871.                 power = power + 1
  872.                 number = math.floor(input / (outputbase^power))
  873.             end
  874.  
  875.             while power >= 0 do
  876.                 number = math.floor(input / (outputbase^power))
  877.                 input = input - (number * (outputbase^power))
  878.                 answer = answer + (number * (inputbase^power))
  879.                 power = power - 1
  880.             end
  881.         end
  882.     end
  883.  
  884.     return answer
  885. end
Add Comment
Please, Sign In to add comment