AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   New Plugin Submissions (https://forums.alliedmods.net/forumdisplay.php?f=26)
-   -   Top Flags [08/09/2021] (https://forums.alliedmods.net/showthread.php?t=310322)

iceeedr 09-29-2018 11:05

Re: Top Flags [27/09/2018]
 
New version released.

Code:

1.2 [29/09/2018]
* Added a cvar tf_day_reset
* Added the automatic creation of the configuration file "topflags" in the configs folder, it is no longer necessary to edit the sma.


iceeedr 09-29-2018 11:05

Re: Top Flags [27/09/2018]
 
Quote:

Originally Posted by SomewhereLost (Post 2617274)
Automatic top15 reset is a god level addition to this plugin, I like it.

Thanks for using the plugin, test the new version and tell me if you encounter any problems :)

Bugsy 09-30-2018 11:06

Re: Top Flags [27/09/2018]
 
With the current implementation, stats will only get reset on servers where the map never changes. I understand this may be by design but if you fix this one thing, it can be used on any server. You should then re-check everyone on round start or something, instead of spawn:
PHP Code:

set_task(86400.0"CheckDate", .flags "b"

These should be constants or use #define:
PHP Code:

new PLUGIN [] = "Top Flags"
new VERSION [] = "1.2"
new AUTHOR [] = "iceeedR" 

Indentation issues:
Code:
if(!isTop[id]) {      client_print_color(id, print_team_red, "^x04[TopFlags]^x03: You are on^x04 TOP%d^x03 and have won the^x04 VIP flags.", get_pcvar_num(VarRank))     client_print_color(0, print_team_red,"^x04[TopFlags]^x03: %s is in^x04 TOP%d^x03 and won the^x04 VIP flags.", szName, get_pcvar_num(VarRank))       remove_user_flags(id, ADMIN_USER)      set_user_flags(id, flags)     isTop[id] = true } public plugin_cfg() {     auto_exec_config("TopFlags") }

Slight change, and you should use HAM_ returns in a HamSandwich event.
PHP Code:

public CheckPlayerRank(id)
{
    if(!
is_user_alive(id)) return PLUGIN_HANDLED

    set_task
(1.0"DelayedFlags"id TaskDelay)
    return 
PLUGIN_CONTINUE
}
//to
public CheckPlayerRank(id)
{
    if( 
is_user_aliveid ) ) 
    {
        
set_task(1.0"DelayedFlags"id TaskDelay)
    }



iceeedr 09-30-2018 12:13

Re: Top Flags [27/09/2018]
 
Quote:

Originally Posted by Bugsy (Post 2617471)
With the current implementation, stats will only get reset on servers where the map never changes. I understand this may be by design but if you fix this one thing, it can be used on any server. You should then re-check everyone on round start or something, instead of spawn:
PHP Code:

set_task(86400.0"CheckDate", .flags "b"

These should be constants or use #define:
PHP Code:

new PLUGIN [] = "Top Flags"
new VERSION [] = "1.2"
new AUTHOR [] = "iceeedR" 

Indentation issues:
Code:
if(!isTop[id]) {      client_print_color(id, print_team_red, "^x04[TopFlags]^x03: You are on^x04 TOP%d^x03 and have won the^x04 VIP flags.", get_pcvar_num(VarRank))     client_print_color(0, print_team_red,"^x04[TopFlags]^x03: %s is in^x04 TOP%d^x03 and won the^x04 VIP flags.", szName, get_pcvar_num(VarRank))       remove_user_flags(id, ADMIN_USER)      set_user_flags(id, flags)     isTop[id] = true } public plugin_cfg() {     auto_exec_config("TopFlags") }

Slight change, and you should use HAM_ returns in a HamSandwich event.
PHP Code:

public CheckPlayerRank(id)
{
    if(!
is_user_alive(id)) return PLUGIN_HANDLED

    set_task
(1.0"DelayedFlags"id TaskDelay)
    return 
PLUGIN_CONTINUE
}
//to
public CheckPlayerRank(id)
{
    if( 
is_user_aliveid ) ) 
    {
        
set_task(1.0"DelayedFlags"id TaskDelay)
    }




Thanks for your notes, but in my tests round start does not have the top updated yet, so I would have to put a Delay in the same way, what would be the real benefit with this change? All the rest I changed as you pointed me out, as for the indentation I do not know why it happened since I wrote it from the beginning in the sublime text, but thank you.

Bugsy 09-30-2018 12:47

Re: Top Flags [27/09/2018]
 
Regarding calling at round start versus spawn, not a noticeable benefit I guess, it would be get_cvar_string() not getting re-called for every person since the values would be re-used for everyone. Plus I think it would be cleaner to check everyone in 1 function call versus having the game call the same function at one time for every player.

iceeedr 09-30-2018 14:32

Re: Top Flags [27/09/2018]
 
Quote:

Originally Posted by Bugsy (Post 2617490)
Regarding calling at round start versus spawn, not a noticeable benefit I guess, it would be get_cvar_string() not getting re-called for every person since the values would be re-used for everyone. Plus I think it would be cleaner to check everyone in 1 function call versus having the game call the same function at one time for every player.

Ok, I agree with you, take another look please and tell me what you think.

Bugsy 09-30-2018 15:24

Re: Top Flags [27/09/2018]
 
Move all variable declarations and redundant code (get_pcvar_string(), read_flags()) out of the for loop.

iceeedr 09-30-2018 15:35

Re: Top Flags [27/09/2018]
 
Quote:

Originally Posted by Bugsy (Post 2617517)
Move all variable declarations and redundant code (get_pcvar_string(), read_flags()) out of the for loop.


Ops sorry, updated.

Bugsy 09-30-2018 16:05

Re: Top Flags [27/09/2018]
 
You need to review the function in entirety when making a change. You should not be exiting the function within the loop based on a condition that affects 1 player, replace the return X with continue.

Code:
    for(new i; i < iNum; i++)     {         id = iPlayers[i]         if(get_user_flags(id) & iFlagsRestrictToCheck)         return PLUGIN_HANDLED  <- replace with continue, and indent.         //If you want to require the player to have ALL of the flags in the cvar, replace with the below.         //Your code will skip them if they have one or more of the flags and not require all. If this is how you want it then disregard.         if ( ( get_user_flags(id) & iFlagsRestrictToCheck ) == iFlagsRestrictToCheck )                 continue;         iRank = get_user_stats(id, stats, bodyhits)                 get_user_name(id, szName, charsmax(szName))                 if(iRank <= get_pcvar_num(VarRank))         {             if(!isTop[id])             {                 client_print_color(id, print_team_red, "^x04[TopFlags]^x03: You are on^x04 TOP%d^x03 and have won the^x04 VIP flags.", get_pcvar_num(VarRank))                 client_print_color(0, print_team_red,"^x04[TopFlags]^x03: %s is in^x04 TOP%d^x03 and won the^x04 VIP flags.", szName, get_pcvar_num(VarRank))                   remove_user_flags(id, ADMIN_USER)                 set_user_flags(id, flags)                 isTop[id] = true             }             //Remove this             return PLUGIN_HANDLED         }         else         {             if(isTop[id])             {                 client_print_color(id, print_team_red,"^x04[TopFlags]^x03: You left the^x04 TOP%d^x03 and lost the^x04 VIP flags.", get_pcvar_num(VarRank))                 client_print_color(0, print_team_red,"^x04[TopFlags]^x03: %s left the^x04 TOP%d^x03 and lost the^x04 VIP flags.", szName, get_pcvar_num(VarRank))                 remove_user_flags(id, flags)                 set_user_flags(id, ADMIN_USER)                 isTop[id] = false             }         }     }

iceeedr 09-30-2018 18:17

Re: Top Flags [27/09/2018]
 
Quote:

Originally Posted by Bugsy (Post 2617522)
You need to review the function in entirety when making a change. You should not be exiting the function within the loop based on a condition that affects 1 player, replace the return X with continue.

Code:
    for(new i; i < iNum; i++)     {         id = iPlayers[i]         if(get_user_flags(id) & iFlagsRestrictToCheck)         return PLUGIN_HANDLED  <- replace with continue, and indent.         //If you want to require the player to have ALL of the flags in the cvar, replace with the below.         //Your code will skip them if they have one or more of the flags and not require all. If this is how you want it then disregard.         if ( ( get_user_flags(id) & iFlagsRestrictToCheck ) == iFlagsRestrictToCheck )                 continue;         iRank = get_user_stats(id, stats, bodyhits)                 get_user_name(id, szName, charsmax(szName))                 if(iRank <= get_pcvar_num(VarRank))         {             if(!isTop[id])             {                 client_print_color(id, print_team_red, "^x04[TopFlags]^x03: You are on^x04 TOP%d^x03 and have won the^x04 VIP flags.", get_pcvar_num(VarRank))                 client_print_color(0, print_team_red,"^x04[TopFlags]^x03: %s is in^x04 TOP%d^x03 and won the^x04 VIP flags.", szName, get_pcvar_num(VarRank))                   remove_user_flags(id, ADMIN_USER)                 set_user_flags(id, flags)                 isTop[id] = true             }             //Remove this             return PLUGIN_HANDLED         }         else         {             if(isTop[id])             {                 client_print_color(id, print_team_red,"^x04[TopFlags]^x03: You left the^x04 TOP%d^x03 and lost the^x04 VIP flags.", get_pcvar_num(VarRank))                 client_print_color(0, print_team_red,"^x04[TopFlags]^x03: %s left the^x04 TOP%d^x03 and lost the^x04 VIP flags.", szName, get_pcvar_num(VarRank))                 remove_user_flags(id, flags)                 set_user_flags(id, ADMIN_USER)                 isTop[id] = false             }         }     }


Thanks for all the notes Bugsy, I believe I have learned a lot from this, I guarantee that in my next "adventures" I will be better.


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

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