Hello, I was wondering if it's possible to get the location of a player then use it in a function (i.e. a spawn prop vector) :smile: thanks.
In case you're wondering, i'm making a script which spawns a grave prop by someones corpse when they die, and have it disappear when they respawn.
[B][URL="http://wiki.garrysmod.com/?title=Gamemode.PlayerDeath"]Gamemode.PlayerDeath [IMG]http://wiki.garrysmod.com/favicon.ico[/IMG][/URL][/B]
[B][URL="http://wiki.garrysmod.com/?title=Entity.GetPos"]Entity.GetPos [IMG]http://wiki.garrysmod.com/favicon.ico[/IMG][/URL][/B]
That should be what your looking for.
Tried that but when I suicide, there's a slight lag and nothing appears.
"kill" takes 6 or 7 tries now too.
[lua]
function Graves()
local GLoc = Self:GetPos()
MakeGrave(Vector(GLoc), "models/props_c17/gravestone002a.mdl")
end
function spawnthegrave(position, model)
local entity1 = ents.create("prop_physics")
local angle1 = Vector(0,0,1):Angle();
angle1.pitch = angle1.pitch + 90;
angle1:RotateAroundAxis(angle1:Up(), math.random(0,360))
entity1:SetAngles(angle1)
entity1:SetModel(model)
local pos = position
pos.z = pos.z - entity1:OBBMaxs().z
entity1:SetPos( pos )
entity1:Spawn()
end
function GM:PlayerSpawn( ply )
entity1:Remove()
end
hook.Add("PlayerDeath", "Graves",timer.Simple(1,Graves)[/lua]
The hook was below the first function at first, thought i'd move it to the bottom and see if that fixed it. It didn't :v:
[QUOTE=thejjokerr;26175084]- Indent your code properly
- hook.Add is missing a ) and you can use a timer in a hook like that.[/QUOTE]
It was cut off in the copy-pasting. I've also tried removing the timer but no dice.
[editline]20th November 2010[/editline]
function Graves()
local GLoc = Self:GetPos()
MakeGrave(Vector(GLoc), "models/props_c17/gravestone002a.mdl")
end
hook.Add("PlayerDeath", "DumbHookHere", Graves)
returns an error with the "GetPos" thing
Function Graves is missing the argument player, self does not exist, change the function header to
function Graves(pl) or function Graves(self) and it would work instantly. And I can't see a function named MakeGrave, are you trying to call spawnthegrave?
Hey don't rate me dumb while i'm learning. That's not very good motivation :saddowns:
And that's not working anyway, i'm gonna check out the Lua wiki and try to get mine to work.
Sorry, you need to Log In to post a reply to this thread.