Jump to content

[SOLVED] Wrong Zombie Weapons


HeK

Recommended Posts

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 by Guest
Link to comment
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 
) 

Link to comment

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 ) ] ) 
  

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...