Newb needing help with creating Game Mode entities.
3 replies, posted
Hi All,
I've come from a dotnet/c# background and am currently getting to grips with Lua.
I have created a few things so far however they have all only been clientside scripts etc.
I have started to create a new gamemode and have got to the point of spawning in and loading HUD etc. I am testing this just using singleplayer>start new game.
I have created my first custom entity within the gamemodes\*GameModeName*\entities\*entityname* folder, however when i start the game i am unable to spawn the entity and am struggling to find any useful information on Google.
I am using a playersay chat hook to send an entity spawn request to a lua script which is running serverside,
Gamemode init.lua
hook.Add("PlayerSay","CommandIdent",function(ply, text, bteam)
if (text == "pr") then
local spawns = ents.FindByClass("info_player_start")
local random_entry = math.random(#spawns)
local Ent = ents.Create("myentity")
Ent:SetPos(spawns[random_entry]:GetPos() + Vector(0,0,5))
Ent:Spawn()
end
end)
If for say i use
ents.Create("npc_zombie")
it works perfectly fine.
If i use the entity i created, i get
gamemode/init.lua:31: Tried to use a NULL entity!
Am i meant to do something in my gamemode/init.lua to include all my custom entities that i have created or something?
Thanks all so much! I know it's probably annoying getting questions like this here as they've likely been seen millions of times... I appreciate all the help.
thats the problem with most questions being asked on forums..
Haha yep!! Unfortunately it's understandable though as i seem to struggle much more with obtaining information on Lua/Garrys Mod development than i do with C# or any other programming I've ever done.
It still keeps the forum active and helps folks in the future
Sorry, you need to Log In to post a reply to this thread.