*edit
hmmm, last part of your explanation would not work in this code.
Example, it's 3rd turn -> Joe kills Bob -> Joe kills random guy -> Bob kills Joe, counter will continue normally
*edit
maybe not work at all when more players are killing each others
would not work :(
PHP Code:
StringMap StoreTurns;
public void OnPluginStart() { HookEvent("player_death", player_death); }
public OnMapStart() { // clear array on map change if(StoreTurns != null) delete StoreTurns;
StoreTurns = new StringMap(); }
public player_death(Event event, const char[] name, bool dontBroadcast) { // follow players userid for not mix them int victim_userid = event.GetInt("userid"); int attacker_userid = event.GetInt("attacker");
int victim_index = GetClientOfUserId(victim_userid); int attacker_index = GetClientOfUserId(attacker_userid);
// valid client indexs and in game if(0 < victim_index <= MaxClients || 0 < attacker_index <= MaxClients || !IsClientInGame(victim_index) || !IsClientInGame(attacker_index)) { return; }
// filter bots out, human players only if(IsFakeClient(victim_index) || IsFakeClient(attacker_index)) { return; }
// Find attacker in array by "userid" and collect stored data // data[0] == victim userid // data[1] == in turns counter
int data[2]; char key[32]; Format(key, sizeof(key), "%i", attacker_userid);
if(StoreTurns.GetArray(key, data, sizeof(data[]))) { // if victim's userid doesn't match with stored data, reset counter if(data[0] != victim_userid) { data[1] = 0; }
// Now delete old record and create new one StoreTurns.Remove(key);
// Notice, we swap attacker and victim in data, to match next time in code cycle!! Format(key, sizeof(key), "%i", victim_userid); data[0] = attacker_userid; data[1]++;
StoreTurns.SetArray(key, data, sizeof(data[]));
// you want follow records ? // PrintToChatAll("%N Kills %N - counter %i", attacker_index, victim_index, data[1]);
// These in turns was 5th time now if(data[1] >= 5) { // DO YOUR STUFF HERE PrintToChatAll("%N and %N are now enemies", victim_index, attacker_index); StoreTurns.Remove(key); //delete record } } else {
// Old record not found, create new record // swap victim and attacker !!