Raised This Month: $59 Target: $400
 14% 

Top Flags [08/01/2020]


Post New Thread Reply   
 
Thread Tools Display Modes
iceeedr
Veteran Member
Join Date: Apr 2017
Location: Brazil
Old 09-29-2018 , 12:05   Re: Top Flags [27/09/2018]
Reply With Quote #21

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 is offline
Send a message via Skype™ to iceeedr
iceeedr
Veteran Member
Join Date: Apr 2017
Location: Brazil
Old 09-29-2018 , 12:05   Re: Top Flags [27/09/2018]
Reply With Quote #22

Quote:
Originally Posted by SomewhereLost View Post
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
__________________
iceeedr is offline
Send a message via Skype™ to iceeedr
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 09-30-2018 , 12:06   Re: Top Flags [27/09/2018]
Reply With Quote #23

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

__________________
Bugsy is offline
iceeedr
Veteran Member
Join Date: Apr 2017
Location: Brazil
Old 09-30-2018 , 13:13   Re: Top Flags [27/09/2018]
Reply With Quote #24

Quote:
Originally Posted by Bugsy View Post
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.
__________________
iceeedr is offline
Send a message via Skype™ to iceeedr
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 09-30-2018 , 13:47   Re: Top Flags [27/09/2018]
Reply With Quote #25

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.
__________________
Bugsy is offline
iceeedr
Veteran Member
Join Date: Apr 2017
Location: Brazil
Old 09-30-2018 , 15:32   Re: Top Flags [27/09/2018]
Reply With Quote #26

Quote:
Originally Posted by Bugsy View Post
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.
__________________
iceeedr is offline
Send a message via Skype™ to iceeedr
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 09-30-2018 , 16:24   Re: Top Flags [27/09/2018]
Reply With Quote #27

Move all variable declarations and redundant code (get_pcvar_string(), read_flags()) out of the for loop.
__________________
Bugsy is offline
iceeedr
Veteran Member
Join Date: Apr 2017
Location: Brazil
Old 09-30-2018 , 16:35   Re: Top Flags [27/09/2018]
Reply With Quote #28

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

Ops sorry, updated.
__________________
iceeedr is offline
Send a message via Skype™ to iceeedr
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 09-30-2018 , 17:05   Re: Top Flags [27/09/2018]
Reply With Quote #29

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

Last edited by Bugsy; 09-30-2018 at 17:10.
Bugsy is offline
iceeedr
Veteran Member
Join Date: Apr 2017
Location: Brazil
Old 09-30-2018 , 19:17   Re: Top Flags [27/09/2018]
Reply With Quote #30

Quote:
Originally Posted by Bugsy View Post
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.
__________________
iceeedr is offline
Send a message via Skype™ to iceeedr
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 10:07.


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