• Attempting to spawn an entity at different locations.
    4 replies, posted
[code]Machines = { Vector(-1318, -430, 710), Vector(-1895, -702, 742), Vector(-1815, -690, 1998), Vector(-1815, -689, 1254), Vector(1040, -2692, 710), Vector(760, -3825, 710), Vector(3056, -2818, 805), Vector(2176, -2583, 805), Vector(-675, 244, 766), Vector(528, -1349, 758), Vector(-1711, 1188, 838) } function SpawnMachines() local vending; if( game.GetMap() == "rp_c18_v1" ) then for k, v in pairs( Machines ) do local vending = v local machines = ents.Create( "ts2_vendingmachine" ) machines:Spawn() machines:Activate() machines:SetMoveType(MOVETYPE_NONE) end end end timer.Simple( 5, SpawnMachines );[/code] None of them will spawn. I'm not getting any error in console either. I think it has something to do with the positioning but I honestly don't know for sure. Any help would be appreciated.
[lua] Machines = { Vector(-1318, -430, 710), Vector(-1895, -702, 742), Vector(-1815, -690, 1998), Vector(-1815, -689, 1254), Vector(1040, -2692, 710), Vector(760, -3825, 710), Vector(3056, -2818, 805), Vector(2176, -2583, 805), Vector(-675, 244, 766), Vector(528, -1349, 758), Vector(-1711, 1188, 838) } function SpawnMachines() if( game.GetMap() == "rp_c18_v1" ) then for k, v in pairs( Machines ) do local machines = ents.Create( "ts2_vendingmachine" ) machines:SetPos(v) machines:Spawn() machines:Activate() machines:SetMoveType(MOVETYPE_NONE) end end end timer.Simple( 5, SpawnMachines ); [/lua] You weren't using SetPos to set their positions.
ninja'd :ninja: [editline]01:25PM[/editline] Use ipairs as the table is numerically indexed, also you can hook it to InitPostEntity instead of using a timer.
[lua]local map = "rp_c18_v1"; local machines = { {Vector(-1318, -430, 710), Angle(0, 0, 0)}, {Vector(-1895, -702, 742), Angle(0, 0, 0)}, {Vector(-1815, -690, 1998), Angle(0, 0, 0)}, {Vector(-1815, -689, 1254), Angle(0, 0, 0)}, {Vector(1040, -2692, 710), Angle(0, 0, 0)}, {Vector(760, -3825, 710), Angle(0, 0, 0)}, {Vector(3056, -2818, 805), Angle(0, 0, 0)}, {Vector(2176, -2583, 805), Angle(0, 0, 0)}, {Vector(-675, 244, 766), Angle(0, 0, 0)}, {Vector(528, -1349, 758), Angle(0, 0, 0)}, {Vector(-1711, 1188, 838), Angle(0, 0, 0)} } hook.Add("InitPostEntity", "Create vendingmachines 5 seconds after map start" function() if(game.GetMap() != map) then return; end timer.Simple(5, function() // Create our machines 5 seconds after map start for _, posang in pairs(machines) do // Loop through all positions and angles stored. local machine = ents.Create("ts2_vendingmachine"); machine:SetPos(posang[1]); // The first field in the table is the position. machine:SetAngles(posang[2]); // The second field in the table is the angle. machine:Spawn(); machine:Activate(); machine:SetMoveType(MOVETYPE_NONE); end end); end);[/lua] Try that. [editline]03:28PM[/editline] Damn, ninja'd.
Thanks alot. CapsAdmin, yours worked. DarkSunrise, yours didn't seem to work at all. Thanks alot for your help though! Solved my problem.
Sorry, you need to Log In to post a reply to this thread.