Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PLAYER:SetPos Fails when called in sweps #2447

Open
aStonedPenguin opened this issue Feb 9, 2016 · 8 comments
Open

PLAYER:SetPos Fails when called in sweps #2447

aStonedPenguin opened this issue Feb 9, 2016 · 8 comments

Comments

@aStonedPenguin
Copy link

PLAYER:SetPos Fails when called in sweps and GetPos returns the new pos until the next frame.

Test Code

ENTITY.OldSetPos = ENTITY.OldSetPos or ENTITY.SetPos
ENTITY.SetPos = function(self, pos)
    if self:IsPlayer() then
        print('\n\n')
        print('Calling SetPos on ', self)
        print('New Pos', pos)
        print('Before SetPos', self:GetPos())
    end

    self.OldSetPos(self, pos)

    if self:IsPlayer() then
        print('After SetPos', self:GetPos())
    end
end

Output

Calling SetPos on   Player [22][Bot21]
New Pos             -2519.000000 344.000000 -12.000000
Before SetPos       -348.968750 -84.990211 64.031250
After SetPos        -2519.000000 344.000000 -12.000000

Video
https://f.stonedpengu.in/index.php/s/LqReMgERmgJ19FI

@KingofBeast
Copy link

👍 I seemed to have the issue outside of SWEPs as well, though. I had a high failure rate setting positions while the player isn't finished loading in (but their object exists), so I'm led to believe that network lag between the client and server may have some role in this.

@Kefta
Copy link
Contributor

Kefta commented Feb 10, 2016

I think it's due to prediction desync. It might work properly if the player/weapon is set to not be predictable.

@Jvs34
Copy link

Jvs34 commented Feb 10, 2016

Not entirely prediction but player movement actually, PrimaryAttack/Think/ and the other (predicted) weapon hooks are called within the player movement code, and since the movement code is already in process and the functions are called in the middle of it, SetPos will appear to have no effect since it will be overridden right after the movement is done calculating the position to put the player in.

As for @KingofBeast 's problem, also related to player movement, since the movement of a player is only calculated when the player sends packets ( usercmd inputs ), during loading screens and such the player's gmod is still loading crap and thus not really sending usercmds, making it look like the player object is frozen and can't even be pushed around sometimes.

Btw this is not a "hurrr you're doing it wrong guys" post, but just a note on what's happening.

@Kefta
Copy link
Contributor

Kefta commented Feb 10, 2016

@Jvs34 Thanks for the explanation. Is there a reason the weapon's predicted hooks are called before movement calculations?

@Jvs34
Copy link

Jvs34 commented Feb 10, 2016

That's just the way it is, no particular reason other than Valve wanted the order to be like this.

@ZehMatt
Copy link

ZehMatt commented Oct 15, 2016

Kefta lead me to this subject as I was having the same issue in my point_teleport entity, Jvs is right but GMod doesnt provide the binding for the Teleport function which takes care of it.

http://codepad.org/tVu0cBWv thats thats the correct code to call.

@aStonedPenguin
Copy link
Author

@willox plz

@ZehMatt
Copy link

ZehMatt commented Oct 16, 2016

Well there is a way to get around it, I did following http://codepad.org/ZKkU16j6
I know its not ideal but it works for the moment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants