How to sum damage
#1

Hi, i've been trying to figure out how can i sum damage taken or issued by players similar to A/D servers. I tried doing this way

pawn Код:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
{
        new cstring[128];
        PlayerPlaySound(issuerid,17802,0.0,0.0,0.0);
        new pname[MAX_PLAYER_NAME];
        TextDrawBackgroundColor(Textdraw11[playerid], 255);
        TextDrawFont(Textdraw11[playerid], 1);
        TextDrawLetterSize(Textdraw11[playerid], 0.470000, 1.100000);
        TextDrawColor(Textdraw11[playerid], -14415873);
        TextDrawSetOutline(Textdraw11[playerid], 1);
        TextDrawSetProportional(Textdraw11[playerid], 0);
        GetPlayerName(issuerid, pname, sizeof(pname));
        format(cstring, sizeof(cstring), "%s -(%.0f)", pname, amount++);
        TextDrawSetString(Textdraw11[playerid], cstring);
        TextDrawShowForPlayer(playerid, Textdraw11[playerid]);
        return 1;
}
It shows all good, but only the amount of the damage done in a single event, i wanted it to add the damage. Ex: 48 + 48 + 30 and forth. plz help
Reply
#2

You have to create player variable or save it in pvars

Код:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
{
        new cstring[128];
        PlayerPlaySound(issuerid,17802,0.0,0.0,0.0);
        new pname[MAX_PLAYER_NAME];
        TextDrawBackgroundColor(Textdraw11[playerid], 255);
        TextDrawFont(Textdraw11[playerid], 1);
        TextDrawLetterSize(Textdraw11[playerid], 0.470000, 1.100000);
        TextDrawColor(Textdraw11[playerid], -14415873);
        TextDrawSetOutline(Textdraw11[playerid], 1);
        TextDrawSetProportional(Textdraw11[playerid], 0);
        GetPlayerName(issuerid, pname, sizeof(pname));
        format(cstring, sizeof(cstring), "%s -(%.0f)", pname, amount++);
        TextDrawSetString(Textdraw11[playerid], cstring);
        TextDrawShowForPlayer(playerid, Textdraw11[playerid]);
        SetPVarFloat(issuerid, "damageTaken", GetPVarFloat(issuerid, "damageTaken") + amount);
        return 1;
}
Then if you want get the total amount use:

Код:
new Float:total_damage = GetPVarFloat(issuerid, "damageTaken");
@down - exactly the same code as my ... no comments
Reply
#3

PHP код:
public OnPlayerTakeDamage(playeridissueridFloatamountweaponid)
{
        new 
cstring[128];
        
PlayerPlaySound(issuerid,17802,0.0,0.0,0.0);
        new 
pname[MAX_PLAYER_NAME];
        
TextDrawBackgroundColor(Textdraw11[playerid], 255);
        
TextDrawFont(Textdraw11[playerid], 1);
        
TextDrawLetterSize(Textdraw11[playerid], 0.4700001.100000);
        
TextDrawColor(Textdraw11[playerid], -14415873);
        
TextDrawSetOutline(Textdraw11[playerid], 1);
        
TextDrawSetProportional(Textdraw11[playerid], 0);
        
GetPlayerName(issueridpnamesizeof(pname));
        
format(cstringsizeof(cstring), "%s -(%.0f)"pnameamount++);
        
TextDrawSetString(Textdraw11[playerid], cstring);
        
TextDrawShowForPlayer(playeridTextdraw11[playerid]);
        
SetPVarFloat(issuerid"damageTaken"GetPVarFloat(issuerid"damageTaken") + amount);
        return 
1;

PHP код:
new Float:total_damage GetPVarFloat(issuerid"damageTaken"); 
Reply
#4

would that work the same way for OnPlayerGiveDamage? Cause im using it to sum the player's damage given.
Reply
#5

This is not working. Even though i tried storing its values with GetPVarFloat, it stays the same, i can shoot someone with an AK-47 and the dmg remains +9, when i wanted it to go like 9, 18, 27, 36 until the textdraw hides. I tried Gekas way it didn't change anything lol

pawn Код:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
{

        // Ding System
    PlayerPlaySound(issuerid, 17802, 0.0, 0.0, 0.0);
        // Damage System
    new cstring[128];
    new Float:DamageTaken;
    new Pname[MAX_PLAYER_NAME];
    TextDrawBackgroundColor(Textdraw11[playerid], 255);
    TextDrawFont(Textdraw11[playerid], 1);
    TextDrawLetterSize(Textdraw11[playerid], 0.470000, 1.100000);
    TextDrawColor(Textdraw11[playerid], -14415873);
    TextDrawSetOutline(Textdraw11[playerid], 1);
    TextDrawSetProportional(Textdraw11[playerid], 0);
    GetPlayerName(issuerid, Pname, sizeof(Pname));
    format(cstring, sizeof(cstring), "%s -(%.0f)", Pname, amount);
    TextDrawSetString(Textdraw11[playerid], cstring);
    TextDrawShowForPlayer(playerid, Textdraw11[playerid]);
    GetPVarFloat(playerid, "DamageTaken");
    SetPVarFloat(playerid, "DamageTaken", DamageTaken + amount);
    SetTimerEx("DamageTakenTextdraw", 7500, false,"f", playerid);
    if(issuerid == INVALID_PLAYER_ID)
    {
    TextDrawBackgroundColor(Textdraw11[playerid], 255);
    TextDrawFont(Textdraw11[playerid], 1);
    TextDrawLetterSize(Textdraw11[playerid], 0.470000, 1.100000);
    TextDrawColor(Textdraw11[playerid], -14415873);
    TextDrawSetOutline(Textdraw11[playerid], 1);
    TextDrawSetProportional(Textdraw11[playerid], 0);
    format(cstring, sizeof(cstring), "Collision -(%.0f)",amount);
    TextDrawSetString(Textdraw11[playerid], cstring);
    TextDrawShowForPlayer(playerid, Textdraw11[playerid]);
    }
        return 1;
}
Reply
#6

bump
Reply
#7

Beacuse your code is wrong ... i gave you finished code, but you modified it wrong!

Код:
SetPVarFloat(issuerid, "DamageTaken", GetPVarFloat(issuerid, "DamageTaken") + amount);
issuerid is the attacker player, not playerid!
Reply
#8

Although, with the code above, whenever a player hits me, if i return fire the damage i make will be added with the previous damage he made on me lol.
Reply
#9

Don't use PVars - they're slower.

pawn Код:
static
    Float: Player_DamageTaken[MAX_PLAYERS];

// OnPlayerConnect:
Player_DamageTaken[playerid] = 0.0;

// OnPlayerDeath:
Player_DamageTaken[playerid] = 0.0;

// OnPlayerTakeDamage (damage taken by players):
if (issuerid != INVALID_PLAYER_ID)
{
    Player_DamageTaken[playerid] += amount;
}
Player_DamageTaken[playerid] stores the total amount a player took damage by players. In each round (if you have of course) you can reset it to 0.
Reply
#10

yes, but i only want the players to show the damage as long as they're alive for a temporary amount of time, whenever the timer ends it sets back to 0, thus could you teach me how would i calculate the damage he inflicted or he took, using OnPlayerTakeDamage, and OnPlayerGiveDamage? i can't think of a way to calculate it using static
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)