• Well I am back again...
    5 replies, posted
Ok so... I got the spawn menu working, again thanks... But now when I go to spawn a prop it breaks... Lol Here is the code for the spawn: [CODE]lastspawn = CurTime() itemsactive = 0 local ply = LocalPlayer() function spawnitem(prop) if CurTime() > lastspawn then lastspawn = CurTime()+10 itemsactive = itemsactive+1 local tr = ply:GetEyeTrace() -- tr now contains a trace object local ent = ents.Create("prop_physics") -- This creates our entity ent:SetPos(tr.HitPos) -- This positions the zombie at the place our trace hit. ent:SetModel(prop) -- Set model of entity print("You spawned a "..prop..".") ent:Spawn() -- This method spawns the prop else print("You can't do that yet! Try again in "..CurTime()-lastspawn.." seconds.") end end concommand.Add("pdrop_spawn", spawnitem) [/CODE] And here is the code calling to the spawn function [CODE] icon.DoClick = function( icon ) surface.PlaySound( "ui/buttonclickrelease.wav" ) RunConsoleCommand("pdrop_spawn",v) end[/CODE] Now... when I try to spawn a prop it gives me [CODE] gamemodes\propfall\gamemode\cl_spawnitem.lua:8: attempt to call method 'GetEyeTrace' (a nil value) [/CODE] But it had been giving me a print of "You have spawned a pdrop_spawn." I changed how ply was passed in hoping to fix it and it started giving the different error. If there is anyone that can help I will be greatly appreciative. [editline]11:12PM[/editline] I have also changed the variable ply to be global, and changed the name to me so it would not effect the rest of the game mode
Console commands have 3 arguments player, command, args. [lua] local lSpawn = 0; local numProps = 0 local trace concommand.Add("pdrop_spawn", function( p, c, a) if( lSpawn < CurTime() ) then lSpawn = CurTime() + 10; numProps = numProps + 1; trace = p:GetEyeTrace(); local prop = ents.Create("prop_physics"); prop:SetModel(tostring(a[1])); prop:SetPos(trace.HitPos); prop:Spawn(); prop:Activate(); else p:PrintMessage(3, "Please wait: "..lSpawn - CurTime().. " before trying to create another prop."); end end) [/lua] Untested.
Thank you very much! Now I am only missing one thing and I can't find anything on it in the wiki... using this method is there any way to activate physics on the entity?
You didnt search for very long, did you? :wink: [b][url=http://wiki.garrysmod.com/?title=Entity.Activate]Entity.Activate [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]
I just don't know what to look for I guess.... thank you :P
[QUOTE=chief2493;23525503]using this method is there [b]any way to [u]activate[/u] physics on the [u]entity?[/u][/b][/QUOTE]
Sorry, you need to Log In to post a reply to this thread.