• Print

Author Topic: Imitating Movement  (Read 5151 times)

0 Members and 1 Guest are viewing this topic.

Offline Timmy

  • Ulysses Team Member
  • Sr. Member
  • *****
  • Posts: 252
  • Karma: 168
  • Code monkey
Imitating Movement
« on: May 16, 2015, 06:11:30 am »
I'm working on this command that will allow me to control another player. Part of it is imitating movement.

I figured I should use the SetupMove function to override another player's movement. This is what I came up with so far:

Code: Lua
  1. local function imitate( calling_ply, target_ply )
  2.  
  3.     calling_ply.buttons = 0
  4.  
  5.     hook.Add( "SetupMove", "Imitate " .. calling_ply:EntIndex(), function( ply, mvd, cmd )
  6.         if ply == calling_ply then
  7.             ply.buttons = mvd:GetButtons()
  8.         end
  9.  
  10.         if ply == target_ply then
  11.             mvd:SetButtons( calling_ply.buttons )
  12.         end
  13.     end )
  14.  
  15. end

So this snippet should apply my button presses to the person I'm imitating. That's what I want (roughly). But it only seems to work with the jump key... It's detecting the other keys but it's not overriding them.

Why isn't it overriding them? How do I make it so it will override them? I'd be very grateful if someone can point me in the right direction. :)

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2727
  • Karma: 430
    • |G4P| Gman4President
Re: Imitating Movement
« Reply #1 on: May 16, 2015, 06:33:44 am »
I wasn't able to find any proof on the wiki to back what I'm about to say, but I strongly recall this not being possible.
Something to do with how the engine handles movement events and not allowing overriding of certain events.

Offline Timmy

  • Ulysses Team Member
  • Sr. Member
  • *****
  • Posts: 252
  • Karma: 168
  • Code monkey
Re: Imitating Movement
« Reply #2 on: May 17, 2015, 06:16:07 pm »
Aww, that's too bad! I just found this article about prediction on the wiki.

From what I understand: Movement is simulated client-side and validated on the server-side. If I were to mess with a player's movement on the server-side it would totally mess up the prediction thing. Without prediction, players with higher ping will have a horrible experience.

So even if it allowed me to override someone's movement, it probably wouldn't work very well anyways.

This would have been so funny though. I will find something else to work on. ^-^

Offline Bite That Apple

  • Hero Member
  • *****
  • Posts: 858
  • Karma: 416
  • Apple Innovations 2010®
    • Fun 4 Everyone Gaming
Re: Imitating Movement
« Reply #3 on: May 19, 2015, 08:23:04 am »
There is or was at least a way to do this in gmod 3-4 years ago. I remember this script called Player Possessor, an here it is: http://facepunch.com/showthread.php?t=534181

and

https://garrysmods.org/download/1652/player-possessor-swepzip
« Last Edit: May 19, 2015, 08:28:00 am by Bite That Apple »
Quote from: John F. Kennedy 1963
A man may die, nations may rise and fall, but an idea lives on.

Offline Timmy

  • Ulysses Team Member
  • Sr. Member
  • *****
  • Posts: 252
  • Karma: 168
  • Code monkey
Re: Imitating Movement
« Reply #4 on: May 19, 2015, 09:56:40 am »
There is or was at least a way to do this in gmod 3-4 years ago. I remember this script called Player Possessor, an here it is: http://facepunch.com/showthread.php?t=534181

and

https://garrysmods.org/download/1652/player-possessor-swepzip
Thank you, you rock. ^-^

Quickly skimmed through the code and I think this might help me achieve what I want! He used ConCommands on the target to imitate the caller. I would have preferred to somehow handle this on the server-side (and eliminate some latency) but I'm not complaining. This also takes away the whole problem with prediction. Sweet, now I can have another go at my possess command. :)

  • Print