AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   PlayerPrethink, cause lags...? (https://forums.alliedmods.net/showthread.php?t=90225)

xbatista 04-15-2009 13:00

PlayerPrethink, cause lags...?
 
If I want to use any of buttons,then I must better to use : fw_CmdStart?
And if speed in Cur Weapon?
Can this cause teleportical lags? :mrgreen:

PHP Code:

public fw_PlayerPreThink(id)
{
    if(!
is_user_alive(id))
        return 
FMRES_IGNORED;
    
    static 
Floatvelocity[3], FloatTime
    
static buttonflag
    button 
pev(idpev_button)
    
flag pev(idpev_flags)
    
Time get_gametime()
    
    if (
g_zombie[id] && PlayerClass[id] == 0)
    {
        if ( (!
g_infreezetime) && (button IN_DUCK) && (button IN_ATTACK) && (flag FL_ONGROUND))
        {
            static 
FloatcooldownFloatlheightlforce
            cooldown 
get_pcvar_float(cvar_cooldown)
            
lforce get_pcvar_num(cvar_lforce)
            
lheight get_pcvar_float(cvar_lheight)
            if (
Time cooldown g_LastLeap[id])
            { 
                
emit_sound(idCHAN_ITEMhunter_leap1.0ATTN_NORM0PITCH_NORM);
                
set_pev(idpev_buttonbutton & ~IN_ATTACK)
                
velocity_by_aim(idlforcevelocity)
                
velocity[2] = lheight
                set_pev
(idpev_velocityvelocity)
                
g_LastLeap[id] = Time
            
}
        }
    }
    if (!
g_infreezetime && g_zombie[id] && PlayerClass[id] == 0)
    {
        static 
Float:speed1speed1 get_pcvar_float(cvar_speed_hunter)
        
set_pev(idpev_maxspeedspeed1)
    }
    else if (!
g_infreezetime && g_zombie[id] && PlayerClass[id] == 1)
    {
        static 
Float:speed2speed2 get_pcvar_float(cvar_speed_boomer)
        
set_pev(idpev_maxspeedspeed2)
    }
    else if (!
g_infreezetime && g_zombie[id] && PlayerClass[id] == 2)
    {
        static 
Float:speed3speed3 get_pcvar_float(cvar_speed_smoker)
        
set_pev(idpev_maxspeedspeed3)
    }
    else if (!
g_infreezetime && g_zombie[id] && PlayerClass[id] == 3)
    {
        static 
Float:speed4speed4 get_pcvar_float(cvar_speed_tank)
        
set_pev(idpev_maxspeedspeed4)
    }
    
    return 
FMRES_IGNORED



Arkshine 04-15-2009 13:07

Re: PlayerPrethink, cause lags...?
 
It's not the forward itself which can cause lags but what you put into.

Empowers 04-15-2009 14:17

Re: PlayerPrethink, cause lags...?
 
Read this and optimize your code

xbatista 04-15-2009 14:24

Re: PlayerPrethink, cause lags...?
 
I don't understand those calls... :/

EDIT: I optimized code :D

PHP Code:

public Fwd_CmdStart(iduc_handleseed)
{
    if( !
is_user_alive(id) ) return FMRES_IGNORED;
    
    static 
Floatvelocity[3], FloatTime;
    static 
flag;
    
flag pev(idpev_flags)
    
Time get_gametime()
    new 
button get_uc(uc_handleUC_Buttons);
    
    if (
g_zombie[id] && PlayerClass[id] == 0)
    {
        if ( (!
g_infreezetime) && button IN_DUCK && button IN_ATTACK && (flag FL_ONGROUND))
        {
            static 
FloatcooldownFloatlheightlforce
            cooldown 
get_pcvar_float(cvar_cooldown)
            
lforce get_pcvar_num(cvar_lforce)
            
lheight get_pcvar_float(cvar_lheight)
            if (
Time cooldown g_LastLeap[id])
            { 
                
emit_sound(idCHAN_ITEMhunter_leap1.0ATTN_NORM0PITCH_NORM);
                
set_uc(uc_handleUC_Buttons, (button & ~IN_ATTACK));
                
velocity_by_aim(idlforcevelocity)
                
velocity[2] = lheight
                set_pev
(idpev_velocityvelocity)
                
g_LastLeap[id] = Time
            
}
        }
    }
    
    return 
FMRES_IGNORED;


PHP Code:

public event_cur_weapon(id)
{
    if(!
is_user_alive(id))
        return;
    
    if (
g_zombie[id])
    {    
        new 
weapon read_data(2)
        
        if( 
g_iCurWeapon[id] == weapon )
        {
            
// player hasn't changed his weapon
            // he has just fired or reloaded or zoomed
            // don't add speed to him
            
return;
        }
        
        
g_iCurWeapon[id] = weapon
        
        
if (!g_infreezetime && PlayerClass[id] == 0)
        {
            static 
Float:speed1speed1 get_pcvar_float(cvar_speed_hunter)
            
set_pev(idpev_maxspeedspeed1)
        }
        else if (!
g_infreezetime && PlayerClass[id] == 1)
        {
            static 
Float:speed2speed2 get_pcvar_float(cvar_speed_boomer)
            
set_pev(idpev_maxspeedspeed2)
        }
        else if (!
g_infreezetime && PlayerClass[id] == 2)
        {
            static 
Float:speed3speed3 get_pcvar_float(cvar_speed_smoker)
            
set_pev(idpev_maxspeedspeed3)
        }
        else if (!
g_infreezetime && PlayerClass[id] == 3)
        {
            static 
Float:speed4speed4 get_pcvar_float(cvar_speed_tank)
            
set_pev(idpev_maxspeedspeed4)
        } 



All times are GMT -4. The time now is 02:26.

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