/* RTS COMPLEMENT
Showcase of RTS API
by Nextra
version 1.0.1
This file is provided as is (no warranties).
*/
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <cstrike>
#include <rememberthescore>
new g_msgid_ScoreInfo, bool:g_RTSEnabled = true;
public plugin_init( )
{
register_plugin( "RTS Complement", "1.0.1", "Nextra" );
// Some basic functions to showcase the features/powers of the RTS API
register_clcmd( "add_score" , "_add_score" , ADMIN_RCON, "Add to the score of yourself" );
register_clcmd( "add_deaths", "_add_deaths" , ADMIN_RCON, "Add to the deaths of yourself" );
register_clcmd( "save_score", "_save_score" , ADMIN_RCON, "Save your own score to the db" );
g_msgid_ScoreInfo = get_user_msgid( "ScoreInfo" );
}
/* We could do stuff with the player now since we know that the player has been authorized
* and his score has been set from the db, but since this is only showcasing the functions
* provided we will only log what happened and do nothing more. */
public rts_user_authorized( id )
{
new szName[32];
get_user_name( id, szName, charsmax(szName) );
log_amx( "User %s (%d) was authorized by RTS. Set score: %d, deaths: %d.", szName, id, get_user_frags( id ), cs_get_user_deaths( id ) );
}
// These two forwards tell us that the operating state of rts has changed. We'll issue some basic things.
public rts_plugin_inactive( type )
{
if( !type ) // RTS paused
{
g_RTSEnabled = false;
}
else // RTS set itself failed, no reason to continue.
{
set_fail_state( "[RTSC] RTS set itself failed. Aborting any further operation." );
}
}
public rts_plugin_active( )
g_RTSEnabled = true;
// Just a basic score adding routine coupled with RTS's updating function to notify it of the change.
public _add_score( id, level, cid )
{
if( !cmd_access( id, level, cid, 1 ) )
{
return PLUGIN_HANDLED;
}
else if( !g_RTSEnabled ) // RTS is not currently running, we should not continue
{
console_print( id, "RTS is not currently running." );
return PLUGIN_HANDLED;
}
// Getting the amount we should change
new szAmt[16], iAmt, iNegative = 0;
read_argv( 1, szAmt, charsmax(szAmt) );
if( szAmt[0] == '-' )
{
iNegative = 1;
}
if( is_str_num( szAmt[iNegative] ) )
{
iAmt = str_to_num( szAmt );
}
else
{
console_print( id, "Invalid amount specified." );
return PLUGIN_HANDLED;
}
if( rts_is_authorized( id ) ) // We require the user to be authorized.
{
set_pev( id, pev_frags, float( get_user_frags( id ) + iAmt ) );
rts_update_score( id ); // RTS will update its internal score tracking.
} // It reloads according to get_user_frags( id ) and therefore implements our change.
else
{
// We could take further action but again, only a showcase. We'll just log.
log_amx( "[RTS] Attempted deaths update on player %d but he was not authorized.", id );
}
msg_score( id ); // This will draw the information on the scoreboard.
console_print( id, "Score updated." );
return PLUGIN_HANDLED;
}
// Just a basic deaths adding routine coupled with RTS's updating function to notify it of the change.
public _add_deaths( id, level, cid )
{
if( !cmd_access( id, level, cid, 1 ) )
{
return PLUGIN_HANDLED;
}
else if( !g_RTSEnabled ) // RTS is not currently running, we should not continue
{
console_print( id, "RTS is not currently running." );
return PLUGIN_HANDLED;
}
// Getting the amount we should change
new szAmt[16], iAmt, iNegative = 0;
read_argv( 1, szAmt, charsmax(szAmt) );
if( szAmt[0] == '-' )
{
iNegative = 1;
}
if( is_str_num( szAmt[iNegative] ) )
{
iAmt = str_to_num( szAmt );
}
else
{
console_print( id, "Invalid amount specified." );
return PLUGIN_HANDLED;
}
if( rts_is_authorized( id ) ) // We require the user to be authorized.
{
cs_set_user_deaths( id, cs_get_user_deaths( id ) + iAmt );
rts_update_score( id ); // RTS will update its internal score tracking.
} // It reloads according to cs_get_user_deaths( id ) and therefore implements our change.
else
{
// We could take further action but again, only a showcase. We'll just log.
log_amx( "[RTS] Attempted deaths update on player %d but he was not authorized.", id );
}
msg_score( id ); // This will draw the information on the scoreboard.
console_print( id, "Deaths updated." );
return PLUGIN_HANDLED;
}
// This will save the score into the database instantly through RTS. Nothing more, nothing less.
public _save_score( id, level, cid )
{
if( !cmd_access( id, level, cid, 0 ) )
{
return PLUGIN_HANDLED;
}
else if( !g_RTSEnabled )
{
console_print( id, "RTS is not currently running." );
return PLUGIN_HANDLED;
}
rts_save_score( id ); // This will instantly save the current score to the database. Should not be necessary most of the time.
console_print( id, "Score saved." );
return PLUGIN_HANDLED;
}
/* We'll update the score on the scoreboard since RTS will not do that for us. ;)
* NOTE: If we do this by using emessages we _DO NOT_ have to notify RTS of changes by calling
* rts_update_score at any time. Since RTS catches its information through this very message, it updates itself
* when receiving other plugins score messages (which is achieved by using emessages) */
msg_score( id )
{
message_begin( MSG_ALL, g_msgid_ScoreInfo );
write_byte( id );
write_short( get_user_frags( id ) );
write_short( cs_get_user_deaths( id ) );
write_short( 0 );
write_short( get_user_team( id ) );
message_end( );
}