Senior Member
|
05-29-2016
, 10:09
Re: A way to reference two variables to get one result?
|
#6
|
Quote:
Originally Posted by SNCurti
Unfortunately I don't know if that helps, since I need to store 1 variable for 32 players who each can damage 32 players. So the issue is, I need to reference one player that hurts another player, and I need to also store the damage he can do to another 31 players at the same time, and there are another 31 players that have potential to damage players, so they each need 32 slots of players they can hurt and store that damage in.
I don't know if those arrays can help me.
|
Yeah then a multidimensional array would be the only way.
edit: here I changed some stuff around which might have helped. idk.
PHP Code:
#include <sourcemod> #include <sdktools>
#pragma semicolon 1
int finalDamage[MAXPLAYERS + 1] = {0, ...}; int AttackerVictimInfo[MAXPLAYERS + 1][MAXPLAYERS + 1][3];
public Plugin sm_reap = { name = "sm_reap", author = "SNC", description = "Reap plugin, health to victims from attackers.", version = "1.0", url = "http://sg-gaming.net/" };
public OnPluginStart() { // Create reap command LoadTranslations("common.phrases.txt"); RegAdminCmd("sm_reap", cmd_Reap, ADMFLAG_UNBAN); HookEvent("player_hurt", OnPlayerHurt); HookEvent("teamplay_round_start", OnRoundStart); HookEvent("teamplay_game_over", OnRoundEnd); HookEvent("player_death", OnPlayerDeath); }
public Action cmd_Reap(int client, int args) { int arguments = GetCmdArgs(); int reapedHealth; if (arguments == 1 || arguments == 2) { int timeNow = GetTime(); PrintToChatAll("%i", timeNow); char arg1[64]; // Get argument (player who will be reaped(who's health will be taken from)) GetCmdArg(1, arg1, sizeof(arg1)); int clienttaken = FindTarget(client, arg1, false, false); if (clienttaken != -1) { IsPlayerAlive(clienttaken) && IsClientInGame(clienttaken)) // Ruling out invalid clients { reapedHealth = GetClientHealth(clienttaken); if (args == 1) { for (int i = 1; i <= MaxClients; i++) // For loop giving each player hurt by the person being reaped health back { if (IsClientInGame(i) && IsPlayerAlive(i)) { PrintToChatAll("%i", AttackerVictimInfo[clienttaken][i][1]); if ((timeNow - AttackerVictimInfo[clienttaken][i][1]) >= 60) { AttackerVictimInfo[clienttaken][i][2] = 0; } else if ((timeNow - AttackerVictimInfo[clienttaken][i][1]) < 60) { finalDamage[clienttaken] = AttackerVictimInfo[clienttaken][i][2] + finalDamage[clienttaken]; int clientHealth = GetClientHealth(i); int clientMaxHealth = GetEntProp(i, Prop_Send, "m_iMaxHealth"); if (AttackerVictimInfo[clienttaken][i][2] + clientHealth > clientMaxHealth) { if (clientMaxHealth < 400 || clientMaxHealth > 0) // Just a check on health boundaries { SetEntityHealth(i, clientMaxHealth); // Setting health to full } } else { SetEntityHealth(i, AttackerVictimInfo[clienttaken][i][2] + clientHealth); //Setting player health } } } } ShowActivity2(client, "[SM] ", "Player %N has been reaped. All players that have taken damage from %N have been restored.", clienttaken, clienttaken); if (reapedHealth > finalDamage[clienttaken]) { SetEntityHealth(clienttaken, reapedHealth - finalDamage[clienttaken]); } else if (reapedHealth <= finalDamage[clienttaken]) { ForcePlayerSuicide(clienttaken); } } else if (args == 2) { char arg2[64]; // Get argument (player who will be given health from reaped player), if none give back to all GetCmdArg(2, arg2, sizeof(arg2)); int clientgiven = FindTarget(client, arg2, false, false); if (clientgiven != -1 || clientgiven != 0 || IsPlayerAlive(clientgiven) || IsClientInGame(clientgiven)) { PrintToChatAll("%i", AttackerVictimInfo[clienttaken][clientgiven][1]); if ((timeNow - AttackerVictimInfo[clienttaken][clientgiven][1]) >= 60) { AttackerVictimInfo[clienttaken][clientgiven][2] = 0; ShowActivity2(client, "[SM] ", "Invalid target(s). Time hurt out of bounds."); return Plugin_Handled; } else if ((timeNow - AttackerVictimInfo[clienttaken][clientgiven][1]) < 60) { if (reapedHealth > AttackerVictimInfo[clienttaken][clientgiven][2]) { SetEntityHealth(clienttaken, reapedHealth - AttackerVictimInfo[clienttaken][clientgiven][2]); } else if (reapedHealth <= AttackerVictimInfo[clienttaken][clientgiven][2]) { ForcePlayerSuicide(clienttaken); } SlapPlayer(clienttaken, AttackerVictimInfo[clienttaken][clientgiven][2]); // Hurting reaped player int clientHealth = GetClientHealth(clientgiven); //Getting health of player being given health int clientMaxHealth = GetEntProp(clientgiven, Prop_Send, "m_iMaxHealth"); if ((AttackerVictimInfo[clienttaken][clientgiven][2] + clientHealth) > clientMaxHealth) { if (clientMaxHealth < 400 || clientMaxHealth > 0) // Just a check on health boundaries { SetEntityHealth(clientgiven, clientMaxHealth); // Setting health to full } } else { SetEntityHealth(clientgiven, AttackerVictimInfo[clienttaken][clientgiven][2] + clientHealth); } ShowActivity2(client, "[SM] ", "Admin %N used reap on %N. %N has been reaped. The health has been given to %N.", client, clienttaken, clienttaken, clientgiven); // For logging } } else { return Plugin_Handled; } } } else { return Plugin_Handled; } } } else if (args <= 0 || args > 2) { ShowActivity2(client, "[SM] ", "Proper usage: sm_reap <from> <to> or sm_reap <from>"); // For logging } return Plugin_Handled; } public Action OnPlayerHurt(Event event, const char[] name, bool dontBroadcast) { int attackerIndex = GetClientOfUserId(GetEventInt(event, "attacker", 0)); int victimIndex = GetClientOfUserId(GetEventInt(event, "userid", 0)); if (attackerIndex != 1 && attackerIndex != 0 && victimIndex != 1 && victimIndex != 0 && IsClientInGame(attackerIndex) && IsClientInGame(victimIndex)) { AttackerVictimInfo[attackerIndex][victimIndex][1] = GetTime(); AttackerVictimInfo[attackerIndex][victimIndex][2] = AttackerVictimInfo[attackerIndex][victimIndex][2] + GetEventInt(event, "damageamount", 0); } } public Action OnRoundStart(Event event, const char[] name, bool dontBroadcast) { for (int i = 1; i <= MaxClients; i++) { // Just resetting some stuff finalDamage[i] = 0; for (int j = 1; j <= MaxClients; j++) { AttackerVictimInfo[i][j][2] = 0; } } } public Action OnRoundEnd(Event event, const char[] name, bool dontBroadcast) { for (int i = 1; i <= MaxClients; i++) { // Just resetting some stuff finalDamage[i] = 0; for (int j = 1; j <= MaxClients; j++) { AttackerVictimInfo[i][j][2] = 0; AttackerVictimInfo[i][j][1] = 0; } } } public Action OnPlayerDeath(Event event, const char[] name, bool dontBroadcast) { int deadPlayer = GetClientOfUserId(GetEventInt(event, "userid", 0)); for (int i = 1; i <= MaxClients; i++) { AttackerVictimInfo[deadPlayer][i][2] = 0; AttackerVictimInfo[deadPlayer][i][1] = 0; } }
Last edited by sdz; 05-29-2016 at 10:18.
|
|