SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 09/07/2020, 04:58 AM   #1
Steve57
Little Clucker
 
Join Date: Oct 2017
Posts: 8
Reputation: 1
Default Storing Damage taken from each player

Well, What i am trying to do is storing damage taken from each player into a temp variable the problem is i am kinda confused how can this work. I just need a tip with a short example code. I have tried many ways but i couldn't figure it out really.
Steve57 is offline   Reply With Quote
Old 09/07/2020, 06:47 AM   #2
YouShootIDodge
Big Clucker
 
Join Date: May 2019
Posts: 74
Reputation: 15
Default Re: Storing Damage taken from each player

https://wiki.sa-mp.com/wiki/OnPlayerTakeDamage

Code:
new player_damage [MAX_PLAYERS]; // A global array

public OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid, bodypart)
{
    player_damage [playerid] += amount;
    return 1;
}

public OnPlayerDisconnect (playerid, reason)
{
    // save here if you want
    player_damage [playerid] = 0;
    return 1;
}
YouShootIDodge is offline   Reply With Quote
Old 09/07/2020, 06:56 AM   #3
cosinus
Little Clucker
 
Join Date: Apr 2020
Location: Indonesia
Posts: 17
Reputation: 7
Default Re: Storing Damage taken from each player

I guess you want to know when someone die who's taking part,

My solutions is implement simple queue algorithm to manipulate array,
you need to store array for each player.

pawn Code:
#define MAX_DAMAGE_STORED 20

enum Info_Damage {
     damagerId,
     Float:damageTaken
}
new TakenDamage[MAX_PLAYERS][MAX_DAMAGE_STORED][Info_Damage];
new CurrentQueue[MAX_PLAYERS];

pawn Code:
public OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid, bodypart)
{
    if(issuerid != INVALID_PLAYER_ID)
    {
          TakenDamage[playerid][CurrentQueue[playerid]][damagerId] = issuerid;
          TakenDamage[playerid][CurrentQueue[playerid]][damageTaken] = amount;

          CurrentQueue[playerid] = (CurrentQueue[playerid] + 1) % MAX_DAMAGE_STORED; // Update queue pointer
    }
    return 0;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    if(killerid != INVALID_PLAYER_ID)
    {
        static const resetDamageInfo[Info_Damage]; // Empty array
        for(new i = 0; i < MAX_DAMAGE_STORED; i++) {
              // Do stuff here such giving reward for each damager

              // Reset stored damage and damager
              TakenDamage[playerid][i] = resetDamageInfo;
        }
    }
    return 1;
}
cosinus is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Storing Damage amount Flamehaze7 Scripting Help 4 05/03/2017 11:29 PM
MySQL storing player password NeXoR Scripting Help 4 25/04/2016 09:35 PM
storing offline player ip into a variable SalmaN97 Scripting Help 13 03/11/2015 03:59 AM
[Help]Player damage when vehicle damage jujuv Help Archive 6 28/12/2010 12:25 AM
Storing player weapons Alex_Valde Help Archive 0 21/11/2010 04:26 PM


All times are GMT. The time now is 05:44 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.