• Teleport behind player you're looking at
    13 replies, posted
Can someone please help me figure out how to do this? I have no idea where to figure it out.
What exactly is the problem? Calling SetPos? Or calling GetEyeTrace?
I have no idea where to start, all I really need is the things from the wiki and I'll see if I can make it work. I've never done anything like that before.
IMO,he want an addon that let you teleport behind player when you are looking at the victim (for surprise attack) His problem is he dont understand the codes
[QUOTE=Thane;50671675]I have no idea where to start, all I really need is the things from the wiki and I'll see if I can make it work. I've never done anything like that before.[/QUOTE] [QUOTE=Robotboy655;50671604]What exactly is the problem? Calling [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/SetPos]Entity:SetPos[/url]? Or calling [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Player/GetEyeTrace]Player:GetEyeTrace[/url]?[/QUOTE]
[QUOTE=boxvader;50672415][/QUOTE] There's quite a bit of maths behind it; it's not that easy to do it correctly. I'll post a solution tomorrow. EDIT: To specify, you can easily do it with Player1:SetPos( Player2:GetPos() - Player2:GetAngles():Forward() * some_integer_distance ), however, it can easily get Player1 stuck.
[QUOTE=code_gs;50672418]There's quite a bit of maths behind it; it's not that easy to do it correctly. I'll post a solution tomorrow. EDIT: To specify, you can easily do it with Player1:SetPos( Player2:GetPos() - Player2:GetAngles():Forward() * some_integer_distance ), however, it can easily get Player1 stuck.[/QUOTE] Alright man thank you!
So I've resorted to trying to figure it out by myself for the sake of learning, and I've ran into a problem. Here's my current code. [CODE] hook.Add("KeyPress", "test2", function(ply, key) local pos = LocalPlayer():GetEyeTrace().Entity:GetPos() if (key == IN_SPEED) then print (pos.."Entity Position") LocalPlayer():SetPos(pos) print (LocalPlayer():GetPos().."Player Position") end end) [/CODE] EDIT: Oops forgot the error. [CODE] [ERROR] addons/lokimod/lua/autorun/client/lokimod.lua:17: attempt to concatenate local 'pos' (a userdata value) 1. v - addons/lokimod/lua/autorun/client/lokimod.lua:17 2. unknown - lua/includes/modules/hook.lua:84 [/CODE]
:snip: doesn't work
[QUOTE=MPan1;50677491]:snip: That wasn't the problem [editline]9th July 2016[/editline] Try this: [CODE] hook.Add("KeyPress", "test2", function(ply, key) local pos = ply:GetEyeTrace().Entity:GetPos() if (key == IN_SPEED) then print (tostring(pos).."Entity Position") ply:SetPos(pos) print (tostring(ply:GetPos()).."Player Position") end end) [/CODE] [editline]9th July 2016[/editline] Also, it's not a good idea to use LocalPlayer(). SetPos doesn't work clientside, and you already have a ply variable to use.[/QUOTE] Nope, same error. I should mention this is being ran clientside, maybe that has something to do with it?
[QUOTE=Thane;50677506]Nope, same error. I should mention this is being ran clientside, maybe that has something to do with it?[/QUOTE] Well, it has to be serverside if you want SetPos to work on a player. Try this then: [CODE] hook.Add("KeyPress", "test2", function(ply, key) local pos = ply:GetEyeTrace().Entity:GetPos() if (key == IN_SPEED) then print (pos) ply:SetPos(pos) print (ply:GetPos()) end end) [/CODE] Sorry, I forgot to test if tostring worked on vectors, I guess not. This should work though.
[QUOTE=MPan1;50677512]Well, it has to be serverside if you want SetPos to work on a player. Try this then: [CODE] hook.Add("KeyPress", "test2", function(ply, key) local pos = ply:GetEyeTrace().Entity:GetPos() if (key == IN_SPEED) then print (pos) ply:SetPos(pos) print (ply:GetPos()) end end) [/CODE] Sorry, I forgot to test if tostring worked on vectors, I guess not. This should work though.[/QUOTE] Yeah, that works. But how would I make it so that it only teleports me to NPC's and players
[QUOTE=Thane;50677523]Yeah, that works. But how would I make it so that it only teleports me to NPC's and players[/QUOTE] Check if the trace entity is an NPC or a player [editline]9th July 2016[/editline] [CODE] local ent = ply:GetEyeTrace().Entity if IsValid( ent ) and ( ent:IsPlayer() or ent:IsNPC() ) then -- continue with the code, otherwise bail [/CODE]
snipped ninja'd [editline]9th July 2016[/editline] [QUOTE=MPan1;50677525]Check if the trace entity is an NPC or a player [editline]9th July 2016[/editline] [CODE] local ent = ply:GetEyeTrace().Entity if IsValid( ent ) and ( ent:IsPlayer() or ent:IsNPC() ) then -- continue with the code, otherwise bail [/CODE][/QUOTE] This works thank you!
Sorry, you need to Log In to post a reply to this thread.