help spawning a entity on a map using ents.FindByName ()
3 replies, posted
i cant seem to get this going but im trying to set an entity using ents.FindByName () i have the name of the entity set but im not sure if its possible on what im doing.
so hers what i did
i went on source sdk and made a map...well... box. and i add only a info_player_start and a func_button
i gave that func_button a name and in my gamemode init.lua file i added
[lua]function SpawnFunction( ply, tr )
button= ents.FindByName( "buttonone" )
ent = ents.Create( "sent_kreeper" )
ent:GetPos(button)
ent:SetPos( ent:GetPos() )
ent:Spawn()
ent:Activate()
end [/lua]
and i turn it on with a console command.
when i do i get this error twice.
[lua]
ERROR: Trying to derive entity sent_kreeper from non existant entity base_gmodentity!
ERROR: Trying to derive entity sent_kreeper from non existant entity base_gmodentity!
[/lua]
btw im still learning lua so sory if i ask any noob question
any ideas/help ?
Well first off, ents.FindByName returns a table.
So try this (Btw I have no clue what your trying to do)
[LUA]
function SpawnFunction( ply, tr )
local Buttons = ents.FindByName( "buttonone" )
for _, button in ipairs( Buttons ) do
ent = ents.Create( "sent_kreeper" )
ent:SetPos( button:GetPos() )
ent:Spawn()
ent:Activate()
end
end
[/LUA]
But I think it might be a lot easier to just make a 'sent_kreeper' in hammer
Just create a new entity and change the entity class to 'sent_kreeper', It will say Obselete or something like that, but when you load the map with your gamemode, It should work.
And also base_gmodentity is an entity from sandbox, so unless your gamemode is derived from sandbox, dont use that as the base for your entity
[QUOTE=Scooby;34820911]Well first off, ents.FindByName returns a table.
So try this (Btw I have no clue what your trying to do)
[LUA]
function SpawnFunction( ply, tr )
local Buttons = ents.FindByName( "buttonone" )
for _, button in ipairs( Buttons ) do
ent = ents.Create( "sent_kreeper" )
ent:SetPos( button:GetPos() )
ent:Spawn()
ent:Activate()
end
end
[/LUA]
But I think it might be a lot easier to just make a 'sent_kreeper' in hammer
Just create a new entity and change the entity class to 'sent_kreeper', It will say Obselete or something like that, but when you load the map with your gamemode, It should work.
And also base_gmodentity is an entity from sandbox, so unless your gamemode is derived from sandbox, dont use that as the base for your entity[/QUOTE]
ok so i removed the base and its working the way i want it but for some reason it still shows the error and i made sure the entity base wasn't base_gmodentity. is there a way to hide that error from the console or figure out why its still showing the error ? and thank you for your help by the way :)
Try switching base_gmodentity to base
and double check the model name you defined, / and \ differ. And need to end with .mdl
Sorry, you need to Log In to post a reply to this thread.