HeK Posted March 31, 2012 Posted March 31, 2012 (edited) I saw this on another topic and then i edited it to use "Baseball Bat", "Shovel", "Katana" and "Chainsaw". But they come with nightsticks, golf clubs, knives. What is wrong? Server: local weaponsTable = {5, 6, 8, 9 } addEvent("onZombieSpawned",true) addEventHandler("onZombieSpawned",root, function ( ) giveWeapon ( source, math.random(#weaponsTable), 1, true ) end) Client: addEvent("Zomb_STFU",true) addEventHandler("Zomb_STFU",root, function ( zomb ) triggerServerEvent ( "onZombieSpawned", zomb ) end) Edited March 31, 2012 by Guest
Castillo Posted March 31, 2012 Posted March 31, 2012 local weaponsTable = { 5, 6, 8, 9 } addEvent ( "onZombieSpawned", true ) addEventHandler ( "onZombieSpawned", root, function ( ) giveWeapon ( source, weaponsTable[ math.random ( #weaponsTable ) ], 1, true ) -- You we're giving the return of math.random as weapon, end )
Kenix Posted April 1, 2012 Posted April 1, 2012 Toxiic, viewtopic.php?f=148&t=40809 math.random(#weaponsTable) --[[ It return random number 1 to 4 ( it's indexes table, but you need get value in indexes ) #is table size ]] weaponsTable[ math.random( #weaponsTable ) ] --[[ So, math.random( #weaponsTable ) return random number 1 to 4 And you get value from table with this random index. ]] local t = { [1] = 1; [2] = 2; [3] = 3; } print( t[ math.random( #t ) ] )
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now