AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   client_prethink & posthink - clear explanation on proble (https://forums.alliedmods.net/showthread.php?t=25905)

SubStream 03-23-2006 08:02

client_prethink & posthink - clear explanation on proble
 
I dont particularly understand what prethink means... I know its a function but I dont understand what exactly its forward means... the documentation doesn't make sense to me... I am still tryin to understand it.
  • plugin_init - Forward for plugin initialization // obvious... forward for when the plugin initializes

    client_impulse - Forward for impulses. // again.. obvious... impulses are flashlight spray stuff like that

    server_changelevel - Forward for a server's changelevel. // obvious... when you change maps

    register_touch - Registers a touch action to a function. // I think that means when something touches something else?

    client_PostThink - Forward for PostThink() on a player.// what the hell is postthink???

    client_PreThink - Forward for PreThink() on a player. // and prethink???

So you can see why I am confused how/when to use client_prethink because the other stuff is self explanatory.. but this is not really to me.. could someone explain what exactly is happening when postthink and prethink occur? is it before or after an action or something? its kind of confusing without understanding that. A clear and simple response would be something in the form of...
"client_prethink basically is called when .......... happens" or
"client_prethink is triggered every time ....... occurs"

My only guess is that client_prethink means it reads the function and prethink triggers on its own based upon what is in the function but... im not completely sure... please only people who definetly know what they are talking about respond... like v3x or black rose... or brad... somebody with experience please.

Hawk552 03-23-2006 08:31

PreThink is called every time before a client renders a frame with physics. This means that if the client's FPS is 50, it will be called 50 times a second, just before each frame is actually rendered. This gives you a fraction of a second to change whatever you need to, before the client actually renders the frame.

PostThink works the same way, except it's a fraction of a second after.

SubStream 03-23-2006 09:15

ty very much that was like the most awesome explanation... now I can actually do stuff I couldn't do before cause I understand that :) ty

Brad 03-23-2006 09:20

Just keep in mind that since they are called so frequently, that you want to limit the amount of processing that gets done there.

organizedKaoS 03-23-2006 14:18

Quote:

Originally Posted by Hawk552
PreThink is called every time before a client renders a frame with physics. This means that if the client's FPS is 50, it will be called 50 times a second, just before each frame is actually rendered. This gives you a fraction of a second to change whatever you need to, before the client actually renders the frame.

PostThink works the same way, except it's a fraction of a second after.

Is prethink and posthink the only route to go as far as "changing" a clients actions? example is twisted's multijump plugin. Prethink checks if the player is jumping and pressing his jump button again while not on ground. Is pre/posthink the only way of achieving this kind of "client action modification"? Or is there any other possible way? Thanks :lol:

Hawk552 03-23-2006 15:45

Quote:

Originally Posted by organizedKaoS
Quote:

Originally Posted by Hawk552
PreThink is called every time before a client renders a frame with physics. This means that if the client's FPS is 50, it will be called 50 times a second, just before each frame is actually rendered. This gives you a fraction of a second to change whatever you need to, before the client actually renders the frame.

PostThink works the same way, except it's a fraction of a second after.

Is prethink and posthink the only route to go as far as "changing" a clients actions? example is twisted's multijump plugin. Prethink checks if the player is jumping and pressing his jump button again while not on ground. Is pre/posthink the only way of achieving this kind of "client action modification"? Or is there any other possible way? Thanks :lol:

Not really, although it's easily the most effective. There are a number of other ways I can think of.

Code:
register_forward(FM_PlayerPreThink,"my_func") register_forward(FM_PlayerPostThink,"my_func")

Code:
register_think("player","my_func")

Code:
public server_frame() {     //... }

That's pretty much all I can think of. I think client_PreThink and PostThink are still the best though.

If you're going for optimization and can ommit Engine from the plugin, then I would go with the Fakemeta hooks (first example).

organizedKaoS 03-23-2006 17:09

So the fakemeta hooks would be the next step down from pre/postthink? I am asking because I run runemod and it is a big hog of pre/posthink. If I used the fakemeta forwards, say in twisteds multijump, would I just register the forwards, rename the pre/posthink publics, and point the forwards to the newly named publics? Or if not, could you please post an example....Thanks and much appreciated :lol: :lol: :lol:

Brad 03-23-2006 17:14

The fakemeta hooks are essentially the same as using client_pre/postthink except you don't have to have engine enabled. If you have engine enabled anyway, there's no need to use the fakemeta forwards.

If you did use fakemeta for this, the way you described of implementing it is accurate.

organizedKaoS 03-23-2006 17:29

Quote:

Originally Posted by Brad
The fakemeta hooks are essentially the same as using client_pre/postthink except you don't have to have engine enabled. If you have engine enabled anyway, there's no need to use the fakemeta forwards.

If you did use fakemeta for this, the way you described of implementing it is accurate.

Understandable, like I said, Im running runemod and it uses pre/posthink alot. So would using the fakemeta forwards prevent any clashing? The multijump plugin by twisted has caused my server to crash due to the excess use of pre/posthink of runemod. I will try the fakemeta forwards while waiting for ur response...Thanks again :lol: :lol: :lol:

Hawk552 03-23-2006 18:36

Quote:

Originally Posted by organizedKaoS
Quote:

Originally Posted by Brad
The fakemeta hooks are essentially the same as using client_pre/postthink except you don't have to have engine enabled. If you have engine enabled anyway, there's no need to use the fakemeta forwards.

If you did use fakemeta for this, the way you described of implementing it is accurate.

Understandable, like I said, Im running runemod and it uses pre/posthink alot. So would using the fakemeta forwards prevent any clashing? The multijump plugin by twisted has caused my server to crash due to the excess use of pre/posthink of runemod. I will try the fakemeta forwards while waiting for ur response...Thanks again :lol: :lol: :lol:

They work the same way. The only difference is that Engine calls Pre/PostThink anyways, even if you didn't initialize a forward. This means that it hogs more CPU. It does this for server_frame, and any other resource consuming hooks in it that I forgot.

Fakemeta however does not do this, which makes it favorable for optimization. The functions for Pre/PostThink are slightly less abstracted though.

As Brad said, if you're running Engine anyways, you'd might as well use it.


All times are GMT -4. The time now is 16:30.

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