View Single Post
Author Message
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 07-13-2021 , 13:43   Store Attacker damage in dinamic array for every victim
Reply With Quote #1

Hello,
I am trying to store a player's damage dealt to another player in an dinamic array. Down below I tried to find Attacker's name in array to get an index:
  • if it's returning a valid index, it loops through all Array items to get all the attacker's victims. Afterwards, it checks if the current victim's name is same as the one found ( if there is already the victim's name in the array ) and then it adds the current damage dealt to the victim in the same index in Array. If there is no equality between victim's name and all the entries found in the array, then it pushes another entry with the Attacker's name but other Victim name.
  • if it's returning a negative value, then pushes a new entry in array, a first one, with Attacker's name and his Victim's name with current damage dealt.

I found this after I added debug messages to code ( you can see down below ):

The problem is when it search for attacker's victim name and it finds one in array, instead of creating a new entry with Attacker's name and the new victim's name, it creates an entry with first victim name from array.

Code:
PHP Code:
enum _:PlayerStats
{
    
AttackerName[MAX_NAME_LENGTH],
    
VictimName[MAX_NAME_LENGTH],
    
DamageGiven,
    
DamageReceived
}

    new 
item ArrayFindString(g_aPlayerStatsg_szName[iAttacker])
    new 
index

    
new iData[PlayerStats]

    if(
item != -1)
    {
        
client_print(iAttackerprint_chat"if 1")
        for(new 
iArraySize(g_aPlayerStats); i++)
        {
            
ArrayGetArray(g_aPlayerStatsiiData)

            
index containi(iData[AttackerName], g_szName[iAttacker])

            if(
index != -1)
            {
                
client_print(iAttackerprint_chat"if 2")
                if(
equali(iData[VictimName], g_szName[iVictim]))
                {
                    
client_print(iAttackerprint_chat"if 3")
                    
iData[DamageGiven] += floatround(flDamage)

                    
ArraySetArray(g_aPlayerStatsiiData)

                    continue
                }
                else
                {
                    
client_print(iAttackerprint_chat"else 1")
                    
copy(iData[VictimName], charsmax(iData[VictimName]), g_szName[iVictim])
                    
iData[DamageGiven] = floatround(flDamage)

                    
ArrayPushArray(g_aPlayerStatsiData)

                    break
                }
            }
        }
    }

    
client_print(iAttackerprint_chat"else 2")
    
copy(iData[AttackerName], charsmax(iData[AttackerName]), g_szName[iAttacker])
    
copy(iData[VictimName], charsmax(iData[VictimName]), g_szName[iVictim])
    
iData[DamageGiven] = floatround(flDamage)

    
ArrayPushArray(g_aPlayerStatsiData
Debug messages order and informations:
PHP Code:
First shot to a victim:
To: [19] ~ LKtRN

called

else 
2

Second shot to the first victim
:
To: [43] ~ LKtRN
To
: [24] ~ LKtRN

called
:
if 
1
if 2LKtRN LKtRN
if 3
else 2

Third shot to other victim
:
To: [43] ~ LKtRN
To
: [24] ~ LKtRN
To
: [38] ~ FnRQavErAKxInEhrfp
To
: [38] ~ FnRQavErAKxInEhrfp

called
:
if 
1
if 2LKtRN FnRQavErAKxInEhrfp
else 1
else 
__________________


Accepting Paid Requests, contact PM.

MVP Of The Round View project on GITHUB / AlliedModders
CSGO REMAKE ~ CSGO MOD [STABLE + SOURCE CODE]

Last edited by Shadows Adi; 07-25-2021 at 14:57.
Shadows Adi is offline