AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   OnPlayerRunCmd tip (https://forums.alliedmods.net/showthread.php?t=114575)

Greyscale 01-05-2010 21:29

OnPlayerRunCmd tip
 
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.

psychonic 01-05-2010 21:44

Re: OnPlayerRunCmd tip
 
Can't you just block the buttons with a PreThink hook with SDK Hooks?

CrimsonGT 01-05-2010 22:02

Re: OnPlayerRunCmd tip
 
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.

Greyscale 01-05-2010 22:14

Re: OnPlayerRunCmd tip
 
Quote:

Originally Posted by psychonic (Post 1044557)
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.

DontWannaName 01-05-2010 23:57

Re: OnPlayerRunCmd tip
 
I decided to force users to leave prediction on, the default is to let them turn it off.

exvel 01-06-2010 00:45

Re: OnPlayerRunCmd tip
 
Quote:

Originally Posted by CrimsonGT (Post 1044562)
Psychonic is correct, blocking actions in prethink is the preferred approach.

What the difference between blocking them in PreThink or through OnPlayerRunCmd?

Greyscale 01-06-2010 01:55

Re: OnPlayerRunCmd tip
 
I'm guessing PreThink is before OnPlayerRunCmd?

If it stops the client from predicting, then it must.

CrimsonGT 01-06-2010 02:05

Re: OnPlayerRunCmd tip
 
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.

exvel 01-06-2010 02:27

Re: OnPlayerRunCmd tip
 
Quote:

Originally Posted by CrimsonGT (Post 1044722)
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.

G@ngst@r 01-06-2010 03:03

Re: OnPlayerRunCmd tip
 
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.

exvel 01-06-2010 03:38

Re: OnPlayerRunCmd tip
 
Well, now it is clear for me. Like I thought. Thank you. :)

Greyscale 01-06-2010 21:20

Re: OnPlayerRunCmd tip
 
I have never experimented with PreThink so has anyone actually tested these?

Jindo 01-07-2010 07:09

Re: OnPlayerRunCmd tip
 
I've tested PreThink before, and I found that it made no difference whether I used OnGameFrame, PreThink or OnPlayerRunCmd, I tried to block the Sniper Rifle's zoom in TF2 and I found myself constantly zooming in and out when right-click was held down.

CrimsonGT 01-07-2010 08:55

Re: OnPlayerRunCmd tip
 
You can block zoom with prethink, I did it for a mod I was working on with no problems. Im assuming your using SDKHooks or w.e. that extension is called, might wanna make sure its a prehook on Prethink and not a posthook.

Jindo 01-07-2010 16:26

Re: OnPlayerRunCmd tip
 
Quote:

Originally Posted by CrimsonGT (Post 1046301)
You can block zoom with prethink, I did it for a mod I was working on with no problems. Im assuming your using SDKHooks or w.e. that extension is called, might wanna make sure its a prehook on Prethink and not a posthook.

I was using SDKHooks yes, it's likely that this was when I had problems getting it to work properly.


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

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