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_iRegularScores[ CsTeams ];
new g_iKnifeBattleScores[ CsTeams ];
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[ 2 ] , iScore;
get_msg_arg_string( 1 , szTeam , charsmax( szTeam ) );
iScore = get_msg_arg_int( 2 );
switch ( szTeam[ 0 ] )
{
case 'T':
{
if ( g_bInKnifeBattle == true )
{
if ( iScore > iPrevTScore )
set_msg_arg_int( 2 , ARG_SHORT , ++g_iKnifeBattleScores[ CS_TEAM_T ] );
iPrevTScore = iScore;
}
else
{
g_iRegularScores[ CS_TEAM_T ] = iScore - g_iKnifeBattleScores[ CS_TEAM_T ];
set_msg_arg_int( 2 , ARG_SHORT , g_iRegularScores[ CS_TEAM_T ] );
}
}
case 'C':
{
if ( g_bInKnifeBattle == true )
{
if ( iScore > iPrevCTScore )
set_msg_arg_int( 2 , ARG_SHORT , ++g_iKnifeBattleScores[ CS_TEAM_CT ] );
iPrevCTScore = iScore;
}
else
{
g_iRegularScores[ CS_TEAM_CT ] = iScore - g_iKnifeBattleScores[ CS_TEAM_CT ];
set_msg_arg_int( 2 , ARG_SHORT , g_iRegularScores[ CS_TEAM_CT ] );
}
}
}
}
public StartKnifeBattle()
{
client_print( 0 , print_chat , "* Knife battle started" );
g_bInKnifeBattle = true;
g_iKnifeBattleScores[ CS_TEAM_T ] = 0;
g_iKnifeBattleScores[ CS_TEAM_CT ] = 0;
cs_set_team_score( CS_TEAM_T , 0 );
cs_set_team_score( CS_TEAM_CT , 0 );
}
public StopKnifeBattle()
{
client_print( 0 , print_chat , "* Knife battle ended" );
g_bInKnifeBattle = false;
cs_set_team_score( CS_TEAM_T , g_iRegularScores[ CS_TEAM_T ] );
cs_set_team_score( CS_TEAM_CT , g_iRegularScores[ CS_TEAM_CT ] );
}
cs_set_team_score( CsTeams:cstTeam , iScore )
{
if ( CS_TEAM_T <= cstTeam <= CS_TEAM_CT )
{
message_begin( MSG_ALL , g_MsgTeamScore , {0,0,0} );
write_string( cstTeam == CS_TEAM_T ? "TERRORIST" : "CT" );
write_short( iScore );
message_end();
}
}
__________________