• Trying to spawn entities from an addon.
    0 replies, posted
I'm trying to create a Gamemode base on the Bio-Annihilation addon. I'm new to LUA programming, so i'm trying to learn still. I'm wanting a command to spawn a test entity which i found here: [url]https://wiki.garrysmod.com/page/ents/Create[/url] Once i get this to work, i'm going to change it to the addon's Gas Mask. The problem only comes in when trying to spawn the entity in front of the player. It throws this error: [ERROR] gamemodes/bioannihilation/gamemode/commands.lua:6: attempt to call global 'EyePos' (a nil value) This is the code i have for the function. [CODE]function SpawnMask() local button = ents.Create( "gmod_button" ) if(!IsValid(button)) then return end button:SetModel("models/dav0r/buttons/button.mdl") local EyePos = EyePos() local EyeAngles = EyeAngles() trace = util.TraceLine( { start = EyePos, endpos = EyePos + Ang:Forward() * 10000, filter = function( ent ) if (ent:GetClass()) == "prop_physics" then return true end end } ) button:SetPos(Vector(trace.HitPos)) button:Spawn() end concommand.Add( "bag_spawnmask", SpawnMask, nil, "Spawns a gas mask" )[/CODE] When i have button:SetPos( 0, 0, 100) without getting the eyepos, etc., like in the tutorial, it doesnt throw an error, but of course i don't know where to look for the thing on the map. I have tried using start = EyePos(), etc., and i can't find much of anything that is remotely helpful. Any and all help is appreciated! [editline]7th February 2016[/editline] A bit of stabbing around in the gmod Sandbox gamemode, and a bit of feeling like an idiot, i realize i needed to do player:EyePos() [CODE]function SpawnMask() local button = ents.Create( "gmod_button" ) if(!IsValid(button)) then return end button:SetModel("models/dav0r/buttons/button.mdl") local tracer = player:EyePos() local angles = player:EyeAngles() trace = util.TraceLine( { start = tracer, endpos = tracer + angles:Forward() * 10000, filter = function( ent ) if (ent:GetClass()) == "prop_physics" then return true end end } ) button:SetPos(Vector(trace.HitPos)) button:Spawn() end concommand.Add( "bag_spawnmask", SpawnMask, nil, "Spawns a gas mask" )[/CODE] Once i fixed that to get this: [ERROR] gamemodes/bioannihilation/gamemode/commands.lua:6: attempt to call method 'EyePos' (a nil value)
Sorry, you need to Log In to post a reply to this thread.