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_aPlayerStats, g_szName[iAttacker])
new index
new iData[PlayerStats]
if(item != -1)
{
client_print(iAttacker, print_chat, "if 1")
for(new i; i < ArraySize(g_aPlayerStats); i++)
{
ArrayGetArray(g_aPlayerStats, i, iData)
index = containi(iData[AttackerName], g_szName[iAttacker])
if(index != -1)
{
client_print(iAttacker, print_chat, "if 2")
if(equali(iData[VictimName], g_szName[iVictim]))
{
client_print(iAttacker, print_chat, "if 3")
iData[DamageGiven] += floatround(flDamage)
ArraySetArray(g_aPlayerStats, i, iData)
continue
}
else
{
client_print(iAttacker, print_chat, "else 1")
copy(iData[VictimName], charsmax(iData[VictimName]), g_szName[iVictim])
iData[DamageGiven] = floatround(flDamage)
ArrayPushArray(g_aPlayerStats, iData)
break
}
}
}
}
client_print(iAttacker, print_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_aPlayerStats, iData)
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 2, LKtRN / 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 2, LKtRN / FnRQavErAKxInEhrfp
else 1
else 2
__________________