Quote:
Originally Posted by eyal282
attacker is the CLIENT INDEX of the person who made the kill.
A client index is a slot of an entity that is reserved for online players only, and once a client leaves, his client index can be reused by the next player to join. Your code will not save how you want it to.
|
Yhea, you're right.
I changed my code to this:
PHP Code:
public Action Event_PlayerDeath(Event event, const char[] name, bool dontBroadcast) {
int victim = GetClientOfUserId(event.GetInt("userid"));
int attacker = GetClientOfUserId(event.GetInt("attacker"));
int assist = GetClientOfUserId(event.GetInt("assister"));
char str[40], str2[40], attackerStr[40], assistStr[40], victimName[40], attackerName[40], assistName[40];
GetClientName(victim, victimName, sizeof(victimName));
GetClientName(attacker, attackerName, sizeof(attackerName));
GetClientName(assist, assistName, sizeof(assistName));
IntToString(attacker, attackerStr, sizeof(attackerStr));
Format(str, sizeof(str), "/players/%s.txt", attackerStr);
if(victim == attacker || attacker == 0){
return;
}
Handle attackerFile = OpenFile(str, "r");
if(attackerFile == INVALID_HANDLE) return;
if(!attackerFile){
CloseHandle(attackerFile);
attackerFile = OpenFile(str, "w");
WriteFileLine(attackerFile, "0");
}
CloseHandle(attackerFile);
attackerFile = OpenFile(str, "w+");
int attackerPoints;
attackerPoints = ReadFileLine(attackerFile, attackerStr, sizeof(attackerStr));
attackerPoints += 10;
IntToString(attackerPoints, attackerStr, sizeof(attackerStr));
WriteFileLine(attackerFile, attackerStr);
CloseHandle(attackerFile);
PrintToChatAll("#%s killed #%i | Points: #%i", attackerName, victimName, attackerPoints);
if(assist){
IntToString(assist, assistStr, sizeof(assistStr));
Format(str2, sizeof(str2), "/players/%s.txt", assistStr);
Handle assistFile = OpenFile(str2, "r");
if(assistFile == INVALID_HANDLE) return;
if(!assistFile){
CloseHandle(assistFile);
assistFile = OpenFile(str2, "w");
WriteFileLine(assistFile, "0");
}
CloseHandle(assistFile);
assistFile = OpenFile(str2, "w+");
int assistPoints;
assistPoints = ReadFileLine(assistFile, assistStr, sizeof(assistStr));
assistPoints += 2;
IntToString(assistPoints, assistStr, sizeof(assistStr));
WriteFileLine(assistPoints, assistStr);
CloseHandle(assistFile);
PrintToChatAll("#%s helped killing #%s | Points: #%i", assistName, victimName, assistPoints);
}
}
No errors, but don't create any file and don't print the message :/