Raised This Month: $ Target: $400
 0% 

OnPlayerRunCmd tip


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Greyscale
SourceMod Plugin Approver
Join Date: Dec 2007
Location: strYoMommasHouse[you];
Old 01-05-2010 , 21:29   OnPlayerRunCmd tip
Reply With Quote #1

If you use OnPlayerRunCmd to block certain actions, like attacking or jumping, the client will experience the start of the action before the server can tell them to stop.

This is because Valve made our clients "predict" what we want to do. For example when our client sees +attack it starts the weapon fire animations, plays the gunshot sound and then resets. While the only one seeing this effect is the client, it can freak the client out and probably cause them to complain.

I found a server cvar that actually forces the client to turn prediction off. The cvar is sv_client_predict. Any client that joins after setting this cvar to 0 (-1 to disable it) will have prediction turned off. Unfortunately this forces us to disable an important feature to reduce the lagged feeling.

cl_predict is the client cvar, unfortunately it is flagged as a cheat. I haven't experimented with it much, but maybe we can use this to toggle prediction per-client.
__________________
Greyscale is offline
psychonic

BAFFLED
Join Date: May 2008
Old 01-05-2010 , 21:44   Re: OnPlayerRunCmd tip
Reply With Quote #2

Can't you just block the buttons with a PreThink hook with SDK Hooks?
psychonic is offline
CrimsonGT
Veteran Member
Join Date: Oct 2007
Location: Gainesville, FL
Old 01-05-2010 , 22:02   Re: OnPlayerRunCmd tip
Reply With Quote #3

Ive talked with robin about this before, and turning off prediction is a horrible idea. You can feel a huge difference when you have 0 ping, imagine having 50+ with no prediction.

Psychonic is correct, blocking actions in prethink is the preferred approach.
CrimsonGT is offline
Greyscale
SourceMod Plugin Approver
Join Date: Dec 2007
Location: strYoMommasHouse[you];
Old 01-05-2010 , 22:14   Re: OnPlayerRunCmd tip
Reply With Quote #4

Quote:
Originally Posted by psychonic View Post
Can't you just block the buttons with a PreThink hook with SDK Hooks?
Orly? Well then nevermind. haha

I thought those were basically synonymous.

CrimsonGT: I disabled it on my local test server and didn't notice anything, but I did realize that it would cause a very noticeable effect on clients with say 50 ping. This was just a discovery I made and thought maybe we could expand on it by messing with cl_predict. This way we could enable/disable when we want.
__________________
Greyscale is offline
DontWannaName
Veteran Member
Join Date: Jun 2007
Location: VALVe Land, WA
Old 01-05-2010 , 23:57   Re: OnPlayerRunCmd tip
Reply With Quote #5

I decided to force users to leave prediction on, the default is to let them turn it off.
__________________

DontWannaName is offline
exvel
SourceMod Donor
Join Date: Jun 2006
Location: Russia
Old 01-06-2010 , 00:45   Re: OnPlayerRunCmd tip
Reply With Quote #6

Quote:
Originally Posted by CrimsonGT View Post
Psychonic is correct, blocking actions in prethink is the preferred approach.
What the difference between blocking them in PreThink or through OnPlayerRunCmd?
__________________
For admins: My plugins

For developers: Colors library
exvel is offline
Send a message via ICQ to exvel
Greyscale
SourceMod Plugin Approver
Join Date: Dec 2007
Location: strYoMommasHouse[you];
Old 01-06-2010 , 01:55   Re: OnPlayerRunCmd tip
Reply With Quote #7

I'm guessing PreThink is before OnPlayerRunCmd?

If it stops the client from predicting, then it must.
__________________
Greyscale is offline
CrimsonGT
Veteran Member
Join Date: Oct 2007
Location: Gainesville, FL
Old 01-06-2010 , 02:05   Re: OnPlayerRunCmd tip
Reply With Quote #8

PreThink occurs prior to any action being sent to the client. Using OnPlayerRunCmd is too late as the client has already started predicting the action, and while it wont actually happen they see it start. For example, if you block attack they will see the gun fire but it wont actually fire on the server.
CrimsonGT is offline
exvel
SourceMod Donor
Join Date: Jun 2006
Location: Russia
Old 01-06-2010 , 02:27   Re: OnPlayerRunCmd tip
Reply With Quote #9

Quote:
Originally Posted by CrimsonGT View Post
PreThink occurs prior to any action being sent to the client. Using OnPlayerRunCmd is too late as the client has already started predicting the action, and while it wont actually happen they see it start. For example, if you block attack they will see the gun fire but it wont actually fire on the server.
Yeap, I know that. But anyway, PreThink fires before OnPlayerRunCmd in the same frame, right? So it doesn't matter for client which of them fired the first because AFAIK client starts prediction without server permission. So changing buttons in PreThink does the same effect as in OnPlayerRunCmd. But OnPlayerRunCmd is built in the core and can be used without extension.
Or PreThink can actually block predictable buttons without lag for client? If this is true I can't imagine how prediction system works.
__________________
For admins: My plugins

For developers: Colors library

Last edited by exvel; 01-06-2010 at 03:37.
exvel is offline
Send a message via ICQ to exvel
G@ngst@r
Member
Join Date: Dec 2009
Old 01-06-2010 , 03:03   Re: OnPlayerRunCmd tip
Reply With Quote #10

Prediction was created for clients, that lag. For example if player pressed forward button, there is very big chance, that player will walk forward, so client's game become to update world with client's prediction with out server world update and permission. If server returned another world state (for example some plugin blocked walking forward) client's world will be updated again, but player will be returned to the old position.

Both OnPreThink and OnPlayerRunCmd are fired when server received client's data (if prediction is ON, clients have already walked forward) and ready to update world with client's command "forward".

For example to force client to do taunt when attack fired, the right way is to force bind "mouse1" "taunt" (this wont cause any lags) and then block any attack using SDKHooks or OnPlayerRunCmd.

I have felt lags connected with prediction, while fire was blocked without binding, ever on local server with ping 5, 200 client's fps and 500 server's fps.

There is no better way.

Last edited by G@ngst@r; 01-06-2010 at 03:18.
G@ngst@r is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 18:15.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode