|
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
|

10-18-2015
, 11:52
Re: [HELP]Save Group Damage
|
#5
|
Here's something you can work with. This needs more work, but it's a good starting point for what I think you are trying to do:
Edit: Made minor fixes and added full commenting.
PHP Code:
#include <amxmodx> #include <amxmisc> #include <hamsandwich>
new const Version[] = "0.1b";
const MAX_TEAMS = 10; //The most teams the plugin can support. const UNASSIGNED = -1; //This indicates that the player is not on a team.
enum TeamInfo { TeamName[ 20 ], MemberCount, TotalDamage, TeamCaptain } new g_Teams[ MAX_TEAMS ][ TeamInfo ]; new g_PlayerTeam[ MAX_PLAYERS + 1 ] = { UNASSIGNED , ... };
public plugin_init() { register_plugin( "Team Example" , Version , "bugsy" ); RegisterHam( Ham_TakeDamage , "player" , "TakeDamage" ); register_concmd( "amx_createteam" , "CreateTeam" , ADMIN_ALL , "<team name> - Create a team" ); register_concmd( "amx_addmember" , "AddMember" , ADMIN_ALL , "<player name> - Add member to your team" ); register_concmd( "amx_removemember" , "RemoveMember" , ADMIN_ALL , "<player name> - Remove member from your team" ); }
public client_disconnect( id ) { //Disconnecting player is on a team and the player is a team captain if ( ( g_PlayerTeam[ id ] != UNASSIGNED ) && ( id == g_Teams[ g_PlayerTeam[ id ] ][ TeamCaptain ] ) ) { //Tell the team that the captain has disconnected? //Set team captain to unassigned since player disconnected g_Teams[ g_PlayerTeam[ id ] ][ TeamCaptain ] = UNASSIGNED; }
//Set disconnecting player team to unassigned g_PlayerTeam[ id ] = UNASSIGNED; } public CreateTeam( id ) { new iFindEmptySlot , szArg[ 32 ]; if ( !read_argv( 1 , szArg , charsmax( szArg ) ) ) { console_print( id , "* You must specify a team name!" ); return PLUGIN_HANDLED; } //Loop through all team slots and see if any are available for use. To do this we are checking //the first character of the name string, if it is EOS (end of string constant) then it is //available. When this is found, the loop is exited and iFindEmptySlot is the index of the slot. for ( iFindEmptySlot = 0 ; iFindEmptySlot < MAX_TEAMS ; iFindEmptySlot++ ) { //Check if first character of name string is blank if ( g_Teams[ iFindEmptySlot ][ TeamName ][ 0 ] == EOS ) break; } //This means the loop cycled eveyr slot and no expty slots are available if ( iFindEmptySlot == ( MAX_TEAMS - 1 ) ) { console_print( id , "* Sorry, no more teams can be created." ); return PLUGIN_HANDLED; } //Team can be created. Copy the string that the user typed into the teams array slot in the //TeamName field. copy( g_Teams[ iFindEmptySlot ][ TeamName ] , charsmax( g_Teams[][ TeamName ] ) , szArg ); console_print( id , "* Team [%s] has been created! Please add members." , szArg ); //Team was just created so it only has 1 member which is the creator g_Teams[ iFindEmptySlot ][ MemberCount ] = 1; //Set team captain to the creator g_Teams[ iFindEmptySlot ][ TeamCaptain ] = id; //Set players team index to the slot that was just used to create the team g_PlayerTeam[ id ] = iFindEmptySlot;
return PLUGIN_HANDLED; }
public AddMember( id ) { new szArg[ 32 ] ,iNewPlayer; if ( !read_argv( 1 , szArg , charsmax( szArg ) ) ) { console_print( id , "* You must specify a player name!" ); return PLUGIN_HANDLED; } if ( !( iNewPlayer = cmd_target( id , szArg ) ) ) return PLUGIN_HANDLED; //Player is trying to add a member to his team but he is not on a team. if ( g_PlayerTeam[ id ] == UNASSIGNED ) { console_print( id , "* You are not on a team." ); return PLUGIN_HANDLED; } //Player is trying to add a member to his team but he is not the captain. if ( id != g_Teams[ g_PlayerTeam[ id ] ][ TeamCaptain ] ) { console_print( id , "* You must be the captain to add members." ); return PLUGIN_HANDLED; } //The player being added is already on a team. if ( g_PlayerTeam[ iNewPlayer ] != UNASSIGNED ) { console_print( id , "* That player is already on a team, he must leave his team first." ); return PLUGIN_HANDLED; } //Player successfully added to team get_user_name( iNewPlayer , szArg , charsmax( szArg ) ); console_print( id , "* %s has joined the [%s] team!" , szArg , g_Teams[ g_PlayerTeam[ id ] ][ TeamName ] ); //Set players team index to the same team as the player using this command. g_PlayerTeam[ iNewPlayer ] = g_PlayerTeam[ id ]; //Increase the team count by 1. g_Teams[ g_PlayerTeam[ id ] ][ MemberCount ]++; return PLUGIN_HANDLED; }
public RemoveMember( id ) { new szArg[ 32 ] , iPlayer; if ( !read_argv( 1 , szArg , charsmax( szArg ) ) ) { console_print( id , "* You must specify a player name!" ); return PLUGIN_HANDLED; } if ( !( iPlayer = cmd_target( id , szArg , 0 ) ) ) return PLUGIN_HANDLED; //To remove a team member the player must be either the captain or the player who wants to leave the team. if ( ( id != g_Teams[ g_PlayerTeam[ id ] ][ TeamCaptain ] ) && ( id != iPlayer ) ) { console_print( id , "* You must be the leaving member or the team captain to remove members." ); return PLUGIN_HANDLED; } //The player being removed is not on a team. if ( g_PlayerTeam[ iPlayer ] == UNASSIGNED ) { console_print( id , "* That player is not on a team" ); return PLUGIN_HANDLED; } get_user_name( iPlayer , szArg , charsmax( szArg ) ); //If the captain is online, inform him that a player left his team. if ( g_Teams[ g_PlayerTeam[ iPlayer ] ][ TeamCaptain ] != UNASSIGNED ) { console_print( g_Teams[ g_PlayerTeam[ iPlayer ] ][ TeamCaptain ] , "* %s has left the [%s] team!" , szArg , g_Teams[ g_PlayerTeam[ iPlayer ] ][ TeamName ] ); }
console_print( iPlayer , "* You have left the [%s] team!" , g_Teams[ g_PlayerTeam[ iPlayer ] ][ TeamName ] ); //Reduce team count by 1 g_Teams[ g_PlayerTeam[ iPlayer ] ][ MemberCount ]--; //Set players team index to unassigned g_PlayerTeam[ iPlayer ] = UNASSIGNED;
return PLUGIN_HANDLED; }
public TakeDamage( iVictim , iInflictor , iAttacker , Float:fDamage , DmgBits ) { //We only want to add total damage to players who are on a team if ( g_PlayerTeam[ iAttacker ] != UNASSIGNED ) { //This adds damage to the correct team by indexing the teams variable using the //players team index variable. //If the team was created in slot 3 then g_PlayerTeam[ iAttacker ] equals 3 //You then pass this value into g_Teams[] to get to the correct team slot to then //add the damage. g_Teams[ g_PlayerTeam[ iAttacker ] ][ TotalDamage ] += floatround( fDamage ); TeamDamagePrint( iAttacker ); } }
public TeamDamagePrint( iAttacker ) { new iPlayers[ 32 ] , iNum , iPlayer; get_players( iPlayers , iNum , "ch" ); //Loop through all players and announce damage recorded for players on the same team as the attacker. for ( new i = 0 ; i < iNum ; i++ ) { iPlayer = iPlayers[ i ]; if ( g_PlayerTeam[ iPlayer ] == g_PlayerTeam[ iAttacker ] ) { client_print( iPlayer , print_chat , "* Your team [%s] now has %d total damage!" , g_Teams[ g_PlayerTeam[ iAttacker ] ][ TeamName ] , g_Teams[ g_PlayerTeam[ iAttacker ] ][ TotalDamage ] ); } } }
__________________
Last edited by Bugsy; 10-19-2015 at 19:37.
Reason: Minor fixes
|
|