AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved trying to decrease "client_preThink" CPU usage (https://forums.alliedmods.net/showthread.php?t=330884)

kww 02-24-2021 23:56

trying to decrease "client_preThink" CPU usage
 
Is there any way to decrease CPU load as much as possible?
(bhop as usual)
PHP Code:

public client_PreThink(id
{
    if(
get_pcvar_num(mp_bhop_ban)) {
        if(
gBhop[id] == 1gBhop[id] = 0
    
}
    
    if(
gBhop[id] == 0)
        return 
PLUGIN_HANDLED
    
    entity_set_float
(idEV_FL_fuser20.0)        
    
    if (
entity_get_int(idEV_INT_button) & 2) {    
        new 
flags entity_get_int(idEV_INT_flags)
    
        if (
flags FL_WATERJUMP)
            return 
PLUGIN_CONTINUE
        
if ( entity_get_int(idEV_INT_waterlevel) >= )
            return 
PLUGIN_CONTINUE
        
if ( !(flags FL_ONGROUND) )
            return 
PLUGIN_CONTINUE
                    
        
if (gAutojump[id] == 1) {
            new 
Float:velocity[3]
            
            
entity_get_vector(idEV_VEC_velocityvelocity)
            
            
velocity[2] += 250.0
            
            entity_set_vector
(idEV_VEC_velocityvelocity)
        }
        
        
entity_set_int(idEV_INT_gaitsequence6)
    }
    
    return 
PLUGIN_HANDLED



CrazY. 02-25-2021 06:41

Re: trying to decrease "client_preThink" CPU usage
 
You can probably replace client_PreThink with Ham_Player_Jump.
Both are called once per frame but Ham_Player_Jump only if a player has the jump key held

Code:

/**
        * Players have all the attributes of normal entities, in addition to these.
        */
       
        /**
        * Description:                Typically called every frame when a player has jump held.
        * Forward params:        function(this)
        * Return type:                None.
        * Execute params:        ExecuteHam(Ham_Player_Jump, this);
        */
        Ham_Player_Jump,


Natsheh 02-25-2021 06:46

Re: trying to decrease "client_preThink" CPU usage
 
Always declare variables in forwards that is being called many times per second using static, change players Boolean variables to bitsum booleans, returning in prethink is ignored so best just to return plugin_continue.

OciXCrom 02-25-2021 07:30

Re: trying to decrease "client_preThink" CPU usage
 
Quote:

returning in prethink is ignored so best just to return plugin_continue.
If it's ignored, what's the point of returning anything? Just do a blank return.

Natsheh 02-25-2021 08:44

Re: trying to decrease "client_preThink" CPU usage
 
Blank return is a plugin continue, but also you're right it should be just return.

loiraolhosazul 02-25-2021 09:02

Re: trying to decrease "client_preThink" CPU usage
 
maybe a check of 0.1 is better, because prethink is according to the player's frames

Natsheh 02-25-2021 09:37

Re: trying to decrease "client_preThink" CPU usage
 
Quote:

Originally Posted by loiraolhosazul (Post 2738243)
maybe a check of 0.1 is better, because prethink is according to the player's frames

depending on what he's trying to achieve.

OciXCrom 02-25-2021 10:03

Re: trying to decrease "client_preThink" CPU usage
 
Like CrazY said, using PreThink for auto-bunnyhop is not a 2021 way of making plugins.
Ham_Player_Jump is the right solution.

kww 02-25-2021 11:49

Re: trying to decrease "client_preThink" CPU usage
 
Quote:

Originally Posted by OciXCrom (Post 2738252)
Like CrazY said, using PreThink for auto-bunnyhop is not a 2021 way of making plugins.
Ham_Player_Jump is the right solution.

hamsandwich is pretty hard for me to understand T_T

OciXCrom 02-25-2021 13:16

Re: trying to decrease "client_preThink" CPU usage
 
It's literally 1 line of code. Understanding PreThink and CPU usage but not HamSandwich doesn't make much sense.

Code:
RegisterHam(Ham_Player_Jump, "player", "OnPlayerJump", 1) public OnPlayerJump(id) {     // your code here... }


All times are GMT -4. The time now is 23:49.

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