public BersekCheck(playerid)
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(i == playerid) continue;
else
{
if(playerVariables[playerid][pCurrentSpree] > playerVariables[i][pCurrentSpree])
{
bersek[playerid] = true;
SetPlayerColor(playerid, COLOR_LIGHTRED);
}
}
new pname[MAX_PLAYER_NAME];
GetPlayerName(playerid, pname, MAX_PLAYER_NAME);
format(szMessage, 256, "[%d]%s is a menace and has turned into bersek, killing them will earn extra money.", playerid, pname);
SendClientMessageToAll(COLOR_RED, szMessage);
}
return 1;
}
public BersekCheck(playerid)
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(i != playerid)
{
if(playerVariables[playerid][pCurrentSpree] > playerVariables[i][pCurrentSpree])
{
bersek[playerid] = true;
SetPlayerColor(playerid, COLOR_LIGHTRED);
}
}
new pname[MAX_PLAYER_NAME];
GetPlayerName(playerid, pname, MAX_PLAYER_NAME);
format(szMessage, 256, "[%d]%s is a menace and has turned into bersek, killing them will earn extra money.", playerid, pname);
SendClientMessageToAll(COLOR_RED, szMessage);
}
return 1;
}
public BersekCheck()
{
new index;
index = 0;
for(new i=0; i< MAX_PLAYERS; i++) // foreach would be better
{
if(playerVariables[i][pCurrentSpree] > playerVariables[index][pCurrentSpree])
index = i;
}
new pname[MAX_PLAYER_NAME];
new szMessage[128];
GetPlayerName(index, pname, MAX_PLAYER_NAME);
format(szMessage, sizeof(szMessage), "[%d]%s is a menace and has turned into bersek, killing them will earn extra money.", index, pname);
SendClientMessageToAll(COLOR_RED, szMessage);
return 1;
}
Use a timer, of like 1 seconds which will call ' public BersekCheck(playerid) ' every 1 second and thus the player with the most streak will be updated.
|
#define BERSERK_THRESHOLD 5
static BerserkPlayerID;
public BersekCheck(playerid, bool:newplayer=false)
{
// Find a new berserk player
if(newplayer)
{
playerid = GetHighestSpreeID();
if(playerVariables[playerid][pCurrentSpree] >= BERSERK_THRESHOLD) SetBerserkPlayer(playerid);
}
else
{
// Was player was already berserk?
if(BerserkPlayerID != playerid)
{
// Player must have at least the threshold to get a berserk
if(playerVariables[playerid][pCurrentSpree] >= BERSERK_THRESHOLD)
{
// Automatically berserk if no berserk player or playerid is higher than berserk player
if(playerVariables[BerserkPlayerID][pCurrentSpree] == INVALID_PLAYER_ID ||
playerVariables[playerid][pCurrentSpree] > playerVariables[BerserkPlayerID][pCurrentSpree]) SetBerserkPlayer(playerid);
}
}
}
return 1;
}
SetBerserkPlayer(playerid)
{
BerserkPlayerID = playerid;
new pname[MAX_PLAYER_NAME];
GetPlayerName(playerid, pname, MAX_PLAYER_NAME);
format(szMessage, 256, "[%d]%s is a menace and has turned into bersek, killing them will earn extra money.", playerid, pname);
SendClientMessageToAll(COLOR_RED, szMessage);
return 1;
}
GetHighestSpreeID()
{
new highspree, playerid = INVALID_PLAYER_ID;
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(!IsPlayerConnected(continue);
if(playerVariables[i][pCurrentSpree] > highspree)
{
playerid = i;
highspree = playerVariables[i][pCurrentSpree]
}
}
return playerid;
}
// Check if berserk player disconnected if so find a new berserk player
public OnPlayerDisconnect(playerid, reason)
{
if(BerserkPlayerID == playerid)
{
SendClientMessageToAll(COLOR_RED, "Berserk Player Left The Server!");
BersekCheck(INVALID_PLAYER_ID, true);
BerserkPlayerID = INVALID_PLAYER_ID;
}
return 1;
}
No need for that dude you only need to check once every death I would personally do something like this.
|