Problem with checking who has the highest killing spree
#7

Quote:
Originally Posted by Rudy_
Посмотреть сообщение
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.
No need for that dude you only need to check once every death I would personally do something like this.

pawn Код:
#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;
}
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 2 Guest(s)