|
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
|

07-18-2014
, 08:54
Re: [REQ] Give Life
|
#14
|
Ah, missed this, I was so tired when I wrote it.
1. No ideea why I use formatex.
2. Command description doesn't really count....
3. It's not reduntant, but I doesn't make a difference. 
4. It means to start from cell 1, so it's not a char here.
5. After posting this I just realized that I writted it with name and wanted to change to steamid, but I forgot. Now it save by steamid.
6. No ideea why I check if the player is not in server.
PHP Code:
#include < amxmodx > #include < nvault > #include < amxmisc > #include < hamsandwich >
#define RESPAWN_COMMAND "say /respawn" // Command to respawn. #define CHECK_LIVES_COMMAND "say /lives" // Command to see how much lives do you have.
new g_iVault, PlayerLives [ 33 ]
public plugin_init ( ) { register_plugin ( "Lives", "1.0", "HamletEagle" ) g_iVault = nvault_open ( "LivesVault" ) if ( g_iVault == INVALID_HANDLE ) set_fail_state( "Error opening vault file" ) register_concmd ( "amx_give_lives", "CmdGiveLives", ADMIN_SLAY, "|--Give lifes to a player" ) register_concmd ( "amx_take_lives", "CmdTakeLives", ADMIN_SLAY, "|--Give lifes to a player" ) register_clcmd ( CHECK_LIVES_COMMAND, "ClCmdCheckLives", -1, "|-- Check your lives" ) register_clcmd ( RESPAWN_COMMAND , "ClCmdLive", -1, "|-- Use a live" ) }
public plugin_end ( ) nvault_close ( g_iVault )
public client_connect ( id ) LoadLives ( id )
public client_disconnect ( id ) SaveLives ( id )
public LoadLives ( id ) { static szData[ 256 ], iTimestamp new szAuthid [ 35 ] get_user_authid ( id , szAuthid , sizeof szAuthid - 1 ) if( nvault_lookup( g_iVault , szAuthid , szData, sizeof szData -1, iTimestamp ) ) LoadExistingData ( id, szData ) else NewPlayerConnected ( id ) }
public LoadExistingData ( id , szData [256 ] ) { static num [ 6 ] strbreak ( szData, num, sizeof num - 1, szData, sizeof szData - 1 ) PlayerLives [ id ] = str_to_num ( num ) }
public NewPlayerConnected ( id ) { PlayerLives[ id ] += 1 SaveLives ( id ) }
public SaveLives ( id ) { new szAuthId [ 35 ] get_user_authid ( id , szAuthId , sizeof szAuthId - 1 ) static szData[ 256 ] if ( PlayerLives[ id ] < 0 ) PlayerLives [ id ] = 0 formatex( szData, sizeof szData -1, "%i", PlayerLives [ id ] ); nvault_set( g_iVault, szAuthId , szData ) }
public CmdGiveLives ( id, level, cid ) { if ( ! cmd_access ( id, level, cid, 3 ) ) return 1 new szArg1 [ 24 ], szArg2 [ 4 ] read_argv ( 1, szArg1, sizeof szArg1 -1 ) read_argv ( 2, szArg2, sizeof szArg2 -1 ) new LivesToGive = str_to_num ( szArg2 ) if ( szArg1 [ 0 ] == '@' ) { new Team if ( equali ( szArg1 [ 1 ], "CT" ) ) Team = 2 else if ( equali ( szArg1 [ 1 ], "T" ) ) Team = 1 new iPlayers [ 32 ], iPlayersNum, index switch ( Team ) { case 1: get_players ( iPlayers, iPlayersNum, "e" , "TERRORIST" ) case 2: get_players ( iPlayers, iPlayersNum, "e" , "CT" ) default: get_players ( iPlayers, iPlayersNum ) } for ( new i=0; i< iPlayersNum; i++ ) { index = iPlayers [ i ] PlayerLives [ index ] += LivesToGive } } else { new Target = cmd_target ( id, szArg1, 1 ) PlayerLives [ Target ] += LivesToGive } SaveLives ( id ) return 1 }
public CmdTakeLives ( id, level, cid ) { if ( ! cmd_access ( id, level, cid, 3 ) ) return 1 new szArg1 [ 24 ], szArg2 [ 4 ] read_argv ( 1, szArg1, sizeof szArg1 -1 ) read_argv ( 2, szArg2, sizeof szArg2 -1 ) new LivesToTake = str_to_num ( szArg2 ) if ( szArg1 [ 0 ] == '@' ) { new Team if ( equali ( szArg1 [ 1 ], "CT" ) ) Team = 2 else if ( equali ( szArg1 [ 1 ], "T" ) ) Team = 1 new iPlayers [ 32 ], iPlayersNum, index switch ( Team ) { case 1: get_players ( iPlayers, iPlayersNum, "e" , "TERRORIST" ) case 2: get_players ( iPlayers, iPlayersNum, "e" , "CT" ) default: get_players ( iPlayers, iPlayersNum ) } for ( new i=0; i< iPlayersNum; i++ ) { index = iPlayers [ i ] PlayerLives [ index ] -= LivesToTake } } else { new Target = cmd_target ( id, szArg1, 1 ) PlayerLives [ Target ] -= LivesToTake } SaveLives ( id ) return 1 }
public ClCmdCheckLives ( id ) { client_print( id, print_chat, "You have %d li%s remaining.", PlayerLives [ id ], PlayerLives [ id ] == 1 ? "fe" : "ves" ) }
public ClCmdLive ( id ) { if ( is_user_alive ( id ) ) { client_print ( id, print_chat, "You can't use this command while you are alive" ) return 1 } else { PlayerLives [ id ] -- ExecuteHamB(Ham_CS_RoundRespawn, id) client_print ( id, print_chat, "You just respawned" ) } return 0 }
Last edited by HamletEagle; 07-10-2016 at 11:42.
|
|