AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   New vs static for deathmsg (https://forums.alliedmods.net/showthread.php?t=273168)

mforce 10-14-2015 03:57

New vs static for deathmsg
 
New vs static for deathmsg
What's better for deathmsg?

PHP Code:

public plugin_init() {
    
register_event("DeathMsg""halal""a")
}

public 
halal() {
    static 
killervictimheadshotweapon[32];
    
killer read_data(1);
    
victim read_data(2);
    
headshot read_data(3);
    
read_data(4weaponcharsmax(weapon));
    
    if (!
is_user_connected(killer) || !is_user_connected(victim) || killer == victim || get_user_team(killer) == get_user_team(victim)) return;
    
    if(
killer != victim && headshot) {
        if (
containi(weapon"awp")) player_data[killer][AWP_KILLS] += HEADSHOT_POINT;
        else if (
containi(weapon"scout")) player_data[killer][SCOUT_KILLS] += HEADSHOT_POINT;
        else if (
containi(weapon"deagle")) player_data[killer][DEAGLE_KILLS] += HEADSHOT_POINT;
        else if (
containi(weapon"usp")) player_data[killer][USP_KILLS] += HEADSHOT_POINT;
        else if (
containi(weapon"glock")) player_data[killer][GLOCK_KILLS] += HEADSHOT_POINT;
        else if (
containi(weapon"knife")) player_data[killer][KNIFE_KILLS] += HEADSHOT_POINT;
        
set_hudmessage(02550, -0.90.1506.01.0);
        
show_hudmessage(killer"+%i Pont"HEADSHOT_POINT);
    }
    else if(
killer != victim) {
        if (
containi(weapon"awp")) player_data[killer][AWP_KILLS] += KILL_POINT;
        else if (
containi(weapon"scout")) player_data[killer][SCOUT_KILLS] += KILL_POINT;
        else if (
containi(weapon"deagle")) player_data[killer][DEAGLE_KILLS] += KILL_POINT;
        else if (
containi(weapon"usp")) player_data[killer][USP_KILLS] += KILL_POINT;
        else if (
containi(weapon"glock")) player_data[killer][GLOCK_KILLS] += KILL_POINT;
        else if (
containi(weapon"knife")) player_data[killer][KNIFE_KILLS] += KILL_POINT;
        
set_hudmessage(02550, -0.90.1506.01.0);
        
show_hudmessage(killer"+%i Pont"KILL_POINT);
    }



NiHiLaNTh 10-14-2015 04:57

Re: New vs static for deathmsg
 
Why are you checking if killer != victim, if you checked it in the statement above?
And consider using tries instead of various "if" checks.

mforce 10-14-2015 05:50

Re: New vs static for deathmsg
 
PHP Code:

public halal() {
    static 
killervictimheadshotweapon[32];
    
killer read_data(1);
    
victim read_data(2);
    
headshot read_data(3);
    
read_data(4weaponcharsmax(weapon));
    
    if (!
is_user_connected(killer) || !is_user_connected(victim) || killer == victim || get_user_team(killer) == get_user_team(victim)) return;
    
    if(
headshot) {
        if (
equali(weapon"awp")) player_data[killer][AWP_KILLS] += HEADSHOT_POINT;
        else if (
equali(weapon"scout")) player_data[killer][SCOUT_KILLS] += HEADSHOT_POINT;
        else if (
equali(weapon"deagle")) player_data[killer][DEAGLE_KILLS] += HEADSHOT_POINT;
        else if (
equali(weapon"usp")) player_data[killer][USP_KILLS] += HEADSHOT_POINT;
        else if (
equali(weapon"glock18")) player_data[killer][GLOCK_KILLS] += HEADSHOT_POINT;
        else if (
equali(weapon"knife")) player_data[killer][KNIFE_KILLS] += HEADSHOT_POINT;
        
        
set_hudmessage(02550, -0.90.1506.01.0);
        
show_hudmessage(killer"+%i Pont"HEADSHOT_POINT);
    }
    else {
        if (
containi(weapon"awp")) player_data[killer][AWP_KILLS] += KILL_POINT;
        else if (
equali(weapon"scout")) player_data[killer][SCOUT_KILLS] += KILL_POINT;
        else if (
equali(weapon"deagle")) player_data[killer][DEAGLE_KILLS] += KILL_POINT;
        else if (
equali(weapon"usp")) player_data[killer][USP_KILLS] += KILL_POINT;
        else if (
equali(weapon"glock18")) player_data[killer][GLOCK_KILLS] += KILL_POINT;
        else if (
equali(weapon"knife")) player_data[killer][KNIFE_KILLS] += KILL_POINT;
        
        
set_hudmessage(02550, -0.90.1506.01.0);
        
show_hudmessage(killer"+%i Pont"KILL_POINT);
    }



fysiks 10-14-2015 09:07

Re: New vs static for deathmsg
 
Quote:

Originally Posted by mforce (Post 2352907)
New vs static for deathmsg
What's better for deathmsg?

It's unlikely to matter because DeathMsg isn't called all that often.

Arkshine 10-14-2015 09:41

Re: New vs static for deathmsg
 
Anything which is not called per frame is not called often, so using "new" is fine, but "static" could be used on large array depending how often it's called.


All times are GMT -4. The time now is 22:17.

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