Raised This Month: $ Target: $400
 0% 

PlayerPrethink, cause lags...?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
xbatista
Veteran Member
Join Date: Mar 2008
Location: Lithuania
Old 04-15-2009 , 13:00   PlayerPrethink, cause lags...?
Reply With Quote #1

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?

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

xbatista is offline
Send a message via Skype™ to xbatista
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 04-15-2009 , 13:07   Re: PlayerPrethink, cause lags...?
Reply With Quote #2

It's not the forward itself which can cause lags but what you put into.
Arkshine is offline
Empowers
BANNED
Join Date: Feb 2009
Location: Ukraine
Old 04-15-2009 , 14:17   Re: PlayerPrethink, cause lags...?
Reply With Quote #3

Read this and optimize your code
Empowers is offline
Send a message via ICQ to Empowers
xbatista
Veteran Member
Join Date: Mar 2008
Location: Lithuania
Old 04-15-2009 , 14:24   Re: PlayerPrethink, cause lags...?
Reply With Quote #4

I don't understand those calls... :/

EDIT: I optimized code

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)
        } 

Last edited by xbatista; 04-15-2009 at 14:42.
xbatista is offline
Send a message via Skype™ to xbatista
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 02:26.


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