Ok so i am making this entity that spawns random guns for one price. I keep getting this error.
[CODE]
Timer Failed! [924spawned_weapon][@addons/darkrpmodification/lua/entities/mystery_box/init.lua (line 95)]
[ERROR] lua/includes/extensions/table.lua:161: bad argument #1 to 'pairs' (table expected, got nil)
1. pairs - [C]:-1
2. Count - lua/includes/extensions/table.lua:161
3. Random - lua/includes/extensions/table.lua:173
4. createGun - addons/darkrpmodification/lua/entities/mystery_box/init.lua:103
5. unknown - addons/darkrpmodification/lua/entities/mystery_box/init.lua:97[/CODE]
And this is the code.
[CODE] timer.Create(self:EntIndex() .. "spawned_weapon", 1, 1, function()
if not IsValid(self) then return end
self:createGun()
end)
end
function ENT:createGun()
self.Once = false
local gun = table.Random( WeaponsTable ),
local WeaponsTable = {
{ gun:SetModel"models/weapons/w_rif_ak47.mdl", gun:SetWeaponClass"weapon_real_cs_ak47" };
{ gun:SetModel"models/weapons/w_snip_awp.mdl", gun:SetWeaponClass"weapon_real_cs_awp" };
{ gun:SetModel"models/weapons/w_rif_galil.mdl", gun:SetWeaponClass"weapon_real_cs_galil" };
{ gun:SetModel"models/weapons/w_snip_g3sg1.mdl", gun:SetWeaponClass"weapon_real_cs_g3sg1" };
};
local _random = table.Random( WeaponsTable );
print( _random.model );
print( _random.class );
local gunPos = self:GetPos()
self.sparking = false
local gunPos = self:GetPos()
gun:SetPos(Vector(gunPos.x, gunPos.y, gunPos.z + 27))
gun.ShareGravgun = true
gun.nodupe = true
gun:Spawn()
self.sparking = false
end[/CODE]
Line 95 is timer.Create(self:EntIndex() .. "spawned_weapon", 1, 1, function()
Line 97 is self:createGun()
Line 103 is local gun = table.Random( WeaponsTable ),
[lua]local gun = table.Random( WeaponsTable ),
local WeaponsTable = {}[/lua]
you dont see anything wrong with this?
I have never used table stuff so idk what i am doing aha. I was using math.random but it was still having issues so someone suggested using tables and i am trying to figure it out still.
You are trying to get a value out of a table you haven't created yet.
Swap those bits around.
Sorry, you need to Log In to post a reply to this thread.