Timer Error: includes/extensions/table.lua:177: bad argument #2 to 'random' (interval is empty)
It gives this error when trying this code:
[Lua]function SpawnZombie()
local spawn = table.Random(ZombieSpawns)
local pos = spawn:GetPos()
local angles = spawn:GetAngles()
local zombie = ents.Create("npc_zombie")
zombie:SetPos(pos)
zombie:SetAngles(angles)
zombie:Spawn()
end
timer.Create("zombieh_spawn", 2, 0, SpawnZombie)
[/LUA]
I've tried various things like combining them instead of calling the function but it still doesent work.
Where have you declared ZombieSpawns?
I just included one part, but here is the whole script if you need it:
[LUA]hook.Add("OnNPCKilled", "MoneyUp", function(npc,killer,wep)
if not( killer:IsPlayer() ) then return end;
local mon = killer:GetNWInt("money", 0)
killer:SetNWInt("money", mon+10)
end)
concommand.Add("CheckMoney", function(p)
if( p:GetNWInt("money", 0) == 0 ) then
p:PrintMessage(3, "You have no money, Nubcaek");
else
p:PrintMessage(3, "Money: $"..p:GetNWInt("money", 0))
end
end)
concommand.Add("buy_ar2", function(p)
if( p:GetNWInt("money", 0) < 800 ) then
p:PrintMessage(3, "No weapon for you noobcaek");
else
p:PrintMessage(3, "You have bought a Combine Rifle")
p:PrintMessage(3, "You now have $"..p:GetNWInt("money", 0))
local mon = p:GetNWInt("money", 0)
p:SetNWInt("money", mon-800)
local weapon1 = ents.Create("weapon_ar2")
weapon1:SetPos(p:LocalToWorld(p:OBBCenter()))
weapon1:Spawn()
end
end)
concommand.Add("buy_smg", function(p)
if( p:GetNWInt("money", 0) < 450 ) then
p:PrintMessage(3, "No weapon for you noobcaek");
else
p:PrintMessage(3, "You have bought a Submachine Gun")
p:PrintMessage(3, "You now have $"..p:GetNWInt("money", 0))
local mon = p:GetNWInt("money", 0)
p:SetNWInt("money", mon-450)
local weapon2 = ents.Create("weapon_smg2")
weapon2:SetPos(p:LocalToWorld(p:OBBCenter()))
weapon2:spawn()
end
end)
local weapon_to_spawn = table.Random(WeaponList)
function Weaponspawn()
local weapon_spawnlist = ents.FindByClass("random_weapon_spawn")
local wep_spawn = table.Random(weapon_spawnlist)
local wep_spawn_pos = wep_spawn:GetPos()
local wep_spawn_angles = wep_spawn:GetAngles()
local weapon_spawn = ents.Create(weapon_to_spawn)
weapon_spawn:SetPos(wep_spawn_pos)
weapon_spawn:SetAngles(wep_spawn_angles)
weapon_spawn:Spawn()
end
local ZombieSpawns = ents.FindByClass("info_zombie_spawn")
function SpawnZombie()
local spawn = table.Random(ZombieSpawns)
local pos = spawn:GetPos()
local angles = spawn:GetAngles()
local zombie = ents.Create("npc_zombie")
zombie:SetPos(pos)
zombie:SetAngles(angles)
zombie:Spawn()
end
local WeaponList = {
"weapon_pistol",
"weapon_smg1",
"weapon_ar2"
}
timer.Create( "weapon_spawn_ilold", 10, 0, Weaponspawn )
timer.Create("zombieh_spawn", 2, 0, SpawnZombie) [/LUA]
[lua]print(ZombieSpawns)[/lua]
I wonder if it's a table or just an entity.
It will be an empty table, because the entities aren't spawned at that time. Move that line to an InitPostEntity hook.
Sorry, you need to Log In to post a reply to this thread.