Raised This Month: $ Target: $400
 0% 

Solved Save score of each team


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-27-2018 , 20:54   Re: Save score of each team
Reply With Quote #1

If I understand correctly you do not need to store the scores in a file since you only temporarily need to store them eg. not between maps/shut down/different day etc. This code is basically taking the team scoring out of the servers hands and overriding the scoreboard with variable values. If you want to actually set team scores you can use orpheu or something.

This will use the scoreboard as normal for gameplay. When you want to start a knife battle use the /start chat command. The team scores will reset to 0:0 and will keep score accordingly for each team. When done with the knife battle, use the /stop command. Scores will go back to what they were before the knife battle started. Additional conditions can be added based on the scores of each team.

Map start, T=0 CT=0
Regular play results in T=3 CT=6
Knife battle start, T=0 CT=0
Knife battle results in T=6 CT =2
Knife battle end, scores go back to T=3 CT=6

PHP Code:
#include <amxmodx>
#include <cstrike>

new const Version[] = "0.1";

new 
g_iRegularScoresCsTeams ];
new 
g_iKnifeBattleScoresCsTeams ];
new 
bool:g_bInKnifeBattle;
new 
g_MsgTeamScore;

public 
plugin_init() 
{
    
register_plugin"Knife Battle Scoring" Version "bugsy" );
    
    
register_message( ( g_MsgTeamScore get_user_msgid"TeamScore" ) ) , "TeamScoreMessage" );

    
register_clcmd"say /start" "StartKnifeBattle" );
    
register_clcmd"say /stop" "StopKnifeBattle" );
}

public 
TeamScoreMessage()
{
    static 
iPrevTScore iPrevCTScore;
    new 
szTeam] , iScore;
    
    
get_msg_arg_stringszTeam charsmaxszTeam ) );
    
iScore get_msg_arg_int);
    
    switch ( 
szTeam] )
    {
        case 
'T':
        {
            if ( 
g_bInKnifeBattle == true )
            {
                if ( 
iScore iPrevTScore )
                    
set_msg_arg_intARG_SHORT , ++g_iKnifeBattleScoresCS_TEAM_T ] );
                    
                
iPrevTScore iScore;
            }
            else
            {
                
g_iRegularScoresCS_TEAM_T ] = iScore g_iKnifeBattleScoresCS_TEAM_T ];
                
set_msg_arg_intARG_SHORT g_iRegularScoresCS_TEAM_T ] );
            }
        }
        case 
'C':
        {
            if ( 
g_bInKnifeBattle == true )
            {
                if ( 
iScore iPrevCTScore )
                    
set_msg_arg_intARG_SHORT , ++g_iKnifeBattleScoresCS_TEAM_CT ] );
                
                
iPrevCTScore iScore;
            }
            else
            {
                
g_iRegularScoresCS_TEAM_CT ] = iScore g_iKnifeBattleScoresCS_TEAM_CT ];
                
set_msg_arg_intARG_SHORT g_iRegularScoresCS_TEAM_CT ] );
            }    
        }
    }
}    
    
public 
StartKnifeBattle()
{
    
client_printprint_chat "* Knife battle started" );
    
    
g_bInKnifeBattle true;
    
    
g_iKnifeBattleScoresCS_TEAM_T ] = 0;
    
g_iKnifeBattleScoresCS_TEAM_CT ] = 0;
    
    
cs_set_team_scoreCS_TEAM_T );
    
cs_set_team_scoreCS_TEAM_CT );
}

public 
StopKnifeBattle()
{
    
client_printprint_chat "* Knife battle ended" );
    
    
g_bInKnifeBattle false;
    
    
cs_set_team_scoreCS_TEAM_T g_iRegularScoresCS_TEAM_T ] );
    
cs_set_team_scoreCS_TEAM_CT g_iRegularScoresCS_TEAM_CT ] );
}

cs_set_team_scoreCsTeams:cstTeam iScore )
{     
    if ( 
CS_TEAM_T <= cstTeam <= CS_TEAM_CT )
    {
        
message_beginMSG_ALL g_MsgTeamScore , {0,0,0} );
        
write_stringcstTeam == CS_TEAM_T "TERRORIST" "CT" );
        
write_shortiScore );
        
message_end();
    }

__________________

Last edited by Bugsy; 04-27-2018 at 21:44.
Bugsy is offline
iceeedr
Veteran Member
Join Date: Apr 2017
Location: Brazil
Old 04-28-2018 , 00:38   Re: Save score of each team
Reply With Quote #2

Quote:
Originally Posted by Bugsy View Post
If I understand correctly you do not need to store the scores in a file since you only temporarily need to store them eg. not between maps/shut down/different day etc. This code is basically taking the team scoring out of the servers hands and overriding the scoreboard with variable values. If you want to actually set team scores you can use orpheu or something.

This will use the scoreboard as normal for gameplay. When you want to start a knife battle use the /start chat command. The team scores will reset to 0:0 and will keep score accordingly for each team. When done with the knife battle, use the /stop command. Scores will go back to what they were before the knife battle started. Additional conditions can be added based on the scores of each team.

Map start, T=0 CT=0
Regular play results in T=3 CT=6
Knife battle start, T=0 CT=0
Knife battle results in T=6 CT =2
Knife battle end, scores go back to T=3 CT=6

PHP Code:
#include <amxmodx>
#include <cstrike>

new const Version[] = "0.1";

new 
g_iRegularScoresCsTeams ];
new 
g_iKnifeBattleScoresCsTeams ];
new 
bool:g_bInKnifeBattle;
new 
g_MsgTeamScore;

public 
plugin_init() 
{
    
register_plugin"Knife Battle Scoring" Version "bugsy" );
    
    
register_message( ( g_MsgTeamScore get_user_msgid"TeamScore" ) ) , "TeamScoreMessage" );

    
register_clcmd"say /start" "StartKnifeBattle" );
    
register_clcmd"say /stop" "StopKnifeBattle" );
}

public 
TeamScoreMessage()
{
    static 
iPrevTScore iPrevCTScore;
    new 
szTeam] , iScore;
    
    
get_msg_arg_stringszTeam charsmaxszTeam ) );
    
iScore get_msg_arg_int);
    
    switch ( 
szTeam] )
    {
        case 
'T':
        {
            if ( 
g_bInKnifeBattle == true )
            {
                if ( 
iScore iPrevTScore )
                    
set_msg_arg_intARG_SHORT , ++g_iKnifeBattleScoresCS_TEAM_T ] );
                    
                
iPrevTScore iScore;
            }
            else
            {
                
g_iRegularScoresCS_TEAM_T ] = iScore g_iKnifeBattleScoresCS_TEAM_T ];
                
set_msg_arg_intARG_SHORT g_iRegularScoresCS_TEAM_T ] );
            }
        }
        case 
'C':
        {
            if ( 
g_bInKnifeBattle == true )
            {
                if ( 
iScore iPrevCTScore )
                    
set_msg_arg_intARG_SHORT , ++g_iKnifeBattleScoresCS_TEAM_CT ] );
                
                
iPrevCTScore iScore;
            }
            else
            {
                
g_iRegularScoresCS_TEAM_CT ] = iScore g_iKnifeBattleScoresCS_TEAM_CT ];
                
set_msg_arg_intARG_SHORT g_iRegularScoresCS_TEAM_CT ] );
            }    
        }
    }
}    
    
public 
StartKnifeBattle()
{
    
client_printprint_chat "* Knife battle started" );
    
    
g_bInKnifeBattle true;
    
    
g_iKnifeBattleScoresCS_TEAM_T ] = 0;
    
g_iKnifeBattleScoresCS_TEAM_CT ] = 0;
    
    
cs_set_team_scoreCS_TEAM_T );
    
cs_set_team_scoreCS_TEAM_CT );
}

public 
StopKnifeBattle()
{
    
client_printprint_chat "* Knife battle ended" );
    
    
g_bInKnifeBattle false;
    
    
cs_set_team_scoreCS_TEAM_T g_iRegularScoresCS_TEAM_T ] );
    
cs_set_team_scoreCS_TEAM_CT g_iRegularScoresCS_TEAM_CT ] );
}

cs_set_team_scoreCsTeams:cstTeam iScore )
{     
    if ( 
CS_TEAM_T <= cstTeam <= CS_TEAM_CT )
    {
        
message_beginMSG_ALL g_MsgTeamScore , {0,0,0} );
        
write_stringcstTeam == CS_TEAM_T "TERRORIST" "CT" );
        
write_shortiScore );
        
message_end();
    }

Wow!! Thanks for this Bugsy, however there is a bug..when the round ends and starts a new one, the old scoreboard back..and for my case your example was not the best solution in my opinion, could you help me just save the value of my global in the vault for later use? I already tried but I took a beating ... the score was ct = 2 tr = 2, in the debug appeared 49 49: S
iceeedr is offline
Send a message via Skype™ to iceeedr
Reply



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 04:32.


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