Is there any way to have a entity spawn when I click a button on a derma menu besides ent_create? I read in a wiki that it doesn’t work in multiplayer.
It depends, if it’s to spawn stuff on servers others then your own then you will be limited to the console commands supplied by that server. What that means is that you can spawn any sandbox entity within the limits defined by the owner but if you go on some special gamemode that doesn’t allow entity spawning then you won’t be able to do anything.
The sandbox console commands you can use are gm_spawn, gmod_spawnnpc, gm_spawnsent, gm_giveswep, gm_spawnswep and gm_spawnvehicle.
They are detailed here : http://luabin.foszor.com/code/gamemodes/sandbox/gamemode/commands.lua
To call them use **[G.RunConsoleCommand
Ah, thanks for the help!
Oh I think I misread your post… If you are doing it for your own server then the best way to do it would be to create a console command on the server that you can use with previously mentionned RunConsoleCommand and in that console command you would use ents.Create to create your entity the way you want it to be.
Yeah, i am trying to do it for my server. And would i put Ents.Create in my gamemodes init.lua or my entitys init.lua?
On the server. Your entity is a description of it and the server is the one that creates it and spawns it into the world. Quick example time!
[lua]local function SpawnMyEnt(ply,cmd,args)–These arguments are supplied to the function no matter what, but we’ll only use ply
if not ply:IsAdmin() then return end – This ends the function if the caller is not an admin, feel free to remove this line or to replace it with another check
local tr = ply:GetEyeTrace()
local ent = ents.Create(“myent”)–Class name of your entity here. This creates one instance of your entity
ent:SetAndles(ply:GetAngles()) --This will make it face away from you.
ent:Spawn()–This makes it visible
Ah, thanks for helping me!
I had forgotten the concommand.Add part!! I edited my post. Really important or it just won’t do anything.
It works thanks for the help!