• Probelms with; "for k, v in pairs( Spawn ) do"
    13 replies, posted
Hey facepunch! I'll like to hear it anyone out there knew anything about the new lua in gmod 13, I've got a broken script! Thanks! :) Script: [code] local Spawn = { } Spawn[ 1 ] = { } Spawn[ 1 ].Entity = "npc_car_dealer" Spawn[ 1 ].Vector = Vector( -1621.910767, -1584.883545, -54.160973 ) Spawn[ 1 ].Angle = Angle( 0, 180, 0 ) function SpawnEnts() for k, v in pairs( Spawn ) do local ent = ents.Create( Spawn[ k ].Entity ) ent:SetPos( Spawn[ k ].Vector ) ent:SetAngles( Spawn[ k ].Angle ) ent:Spawn( ) ent:DropToFloor( ) local bubble = ents.Create( "ent_quest_bubble" ) bubble:SetNetworkedEntity( "ChaseEntity", ent ) bubble:SetPos( ent:GetPos( ) + Vector( 0, 0, 64 ) ) bubble:Spawn( ) end end hook.Add( "InitPostEntity", "SpawnEntities", SpawnEnts ) [/code] ERROR: [code] [ERROR] gamemodes/darkrp/gamemode/npc.lua:10: Tried to use a NULL entity! 1. SetPos - [C]:-1 2. v - gamemodes/darkrp/gamemode/npc.lua:10 3. unknown - lua/includes/modules/hook.lua:82[/code]
It can't create npc_car_dealer
[QUOTE=Errolight;39700438]Hey facepunch! I'll like to hear it anyone out there knew anything about the new lua in gmod 13, I've got a broken script! Thanks! :) Script: [code] local Spawn = { } Spawn[ 1 ] = { } Spawn[ 1 ].Entity = "npc_car_dealer" Spawn[ 1 ].Vector = Vector( -1621.910767, -1584.883545, -54.160973 ) Spawn[ 1 ].Angle = Angle( 0, 180, 0 ) function SpawnEnts() for k, v in pairs( Spawn ) do local ent = ents.Create( Spawn[ k ].Entity ) ent:SetPos( Spawn[ k ].Vector ) ent:SetAngles( Spawn[ k ].Angle ) ent:Spawn( ) ent:DropToFloor( ) local bubble = ents.Create( "ent_quest_bubble" ) bubble:SetNetworkedEntity( "ChaseEntity", ent ) bubble:SetPos( ent:GetPos( ) + Vector( 0, 0, 64 ) ) bubble:Spawn( ) end end hook.Add( "InitPostEntity", "SpawnEntities", SpawnEnts ) [/code] ERROR: [code] [ERROR] gamemodes/darkrp/gamemode/npc.lua:10: Tried to use a NULL entity! 1. SetPos - [C]:-1 2. v - gamemodes/darkrp/gamemode/npc.lua:10 3. unknown - lua/includes/modules/hook.lua:82[/code][/QUOTE] Because you're trying to iterate over the entirety of the Spawn table. Replace "for k, v in pairs( Spawn ) do" with "for k, v in pairs(Spawn[1].Entity) do" Which in this case there is only one entity class so you should just put its class name in there instead.
Divran, you dissagre why do you don't type so? [editline]24th February 2013[/editline] [QUOTE=ms333;39700624]It can't create npc_car_dealer[/QUOTE] You can't create it because the script is from gmod 12, and not working for 13. Why do you think I made the topic... [editline]24th February 2013[/editline] [QUOTE=Feihc;39700920]Because you're trying to iterate over the entirety of the Spawn table. Replace "for k, v in pairs( Spawn ) do" with "for k, v in pairs(Spawn[1].Entity) do" Which in this case there is only one entity class so you should just put its class name in there instead.[/QUOTE] Thanks! But what with the rest of it???
[QUOTE=Errolight;39701074]Divran, you dissagre why do you don't type so? [editline]24th February 2013[/editline] You can't create it because the script is from gmod 12, and not working for 13. Why do you think I made the topic... [editline]24th February 2013[/editline] Thanks! But what with the rest of it???[/QUOTE] Wait, why is this in a loop at all? There is only only location, angle and entity... [code] function SpawnEnts() local ent = ents.Create( "npc_car_dealer" ) ent:SetPos( Vector( -1621.910767, -1584.883545, -54.160973 ) ) ent:SetAngles( Angle( 0, 180, 0 ) ) ent:Spawn( ) ent:DropToFloor( ) local bubble = ents.Create( "ent_quest_bubble" ) bubble:SetNetworkedEntity( "ChaseEntity", ent ) bubble:SetPos( ent:GetPos( ) + Vector( 0, 0, 64 ) ) bubble:Spawn( ) end hook.Add( "InitPostEntity", "SpawnEntities", SpawnEnts ) [/code] That's all you need
Because, you can add more than one npc, but I only need one :) Thanks! [editline]24th February 2013[/editline] New Error :/ [code] [ERROR] gamemodes/darkrp/gamemode/npc.lua:3: Tried to use a NULL entity! 1. SetPos - [C]:-1 2. v - gamemodes/darkrp/gamemode/npc.lua:3 3. unknown - lua/includes/modules/hook.lua:82 [/code] It's this line :/ ent:SetPos( Vector( -1621.910767, -1584.883545, -54.160973 ) )
[QUOTE=Errolight;39701074]Divran, you dissagre why do you don't type so?[/QUOTE] I disagree because his "correction" makes no sense whatsoever [QUOTE=ms333;39700624]It can't create npc_car_dealer[/QUOTE] What he said. The entity probably doesn't exist
Anyone?
What's your entity code? (The entity you're trying to spawn)
Look further up in console for any lua error related to npc_car_dealer. Your problem here is that the entity npc_car_dealer does not exist because it've probably errored upon loading, or the lua files doesn't exist at all for it.
Do you have a folder named npc_car_dealer in your entities/entities folder?
The problem is it can't create the entity, it probably has a error in it that prevents it from spawning(the entity its self). Oh I just realized somebody already said this 2 posts above me. Oh well.
[QUOTE=Errolight;39700438]Hey facepunch! I'll like to hear it anyone out there knew anything about the new lua in gmod 13, I've got a broken script! Thanks! :) Script: [code] local Spawn = { } Spawn[ 1 ] = { } Spawn[ 1 ].Entity = "npc_car_dealer" Spawn[ 1 ].Vector = Vector( -1621.910767, -1584.883545, -54.160973 ) Spawn[ 1 ].Angle = Angle( 0, 180, 0 ) function SpawnEnts() for k, v in pairs( Spawn ) do local ent = ents.Create( Spawn[ k ].Entity ) ent:SetPos( Spawn[ k ].Vector ) ent:SetAngles( Spawn[ k ].Angle ) ent:Spawn( ) ent:DropToFloor( ) local bubble = ents.Create( "ent_quest_bubble" ) bubble:SetNetworkedEntity( "ChaseEntity", ent ) bubble:SetPos( ent:GetPos( ) + Vector( 0, 0, 64 ) ) bubble:Spawn( ) end end hook.Add( "InitPostEntity", "SpawnEntities", SpawnEnts ) [/code] ERROR: [code] [ERROR] gamemodes/darkrp/gamemode/npc.lua:10: Tried to use a NULL entity! 1. SetPos - [C]:-1 2. v - gamemodes/darkrp/gamemode/npc.lua:10 3. unknown - lua/includes/modules/hook.lua:82[/code][/QUOTE] Also, why using Spawn[ k ] while you can use v.Entity ? (That's all I can say since people already told you what could be wrong and I believe it's what they said)
I know you solved it by removing the spawn thingo but: [lua]local Spawn = {} Spawn[1] = { Ent = "npc_car_dealer", Pos = Vector(-1621.910767, -1584.883545, -54.160973), Ang = Angle(0, 180, 0) } function SpawnEnts() for k, v in pairs(Spawn) do local ent = ents.Create(v.Ent) ent:SetPos(v.Pos) ent:SetAngles(v.Ang) ent:Spawn() ent:DropToFloor() local bubble = ents.Create("ent_quest_bubble") bubble:SetNetworkedEntity("ChaseEntity", ent) bubble:SetPos(ent:GetPos() + Vector(0, 0, 64)) bubble:Spawn() end end hook.Add("InitPostEntity", "SpawnEntities", SpawnEnts)[/lua]
Sorry, you need to Log In to post a reply to this thread.