Problem with checking who has the highest killing spree
#1

I can't really build in my mind, on how this is logically supposed to be. I wanted to check whose player is the highest killing spree, to declare them "Bersek", although, with this code, it only works on whomever joins first. Basically, my main struggle is to understand how i can compare the variables between the playerid according to everyone else. Help is always appreciated

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

Try this. Not sure..
pawn Код:
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;
}
Reply
#3

The script should loop through everyone, correct me if i am wrong, if playerid equals i, then it should skip. checking if i isn't playerid, is the same thing, in which would be wrong all the same? O.o
Reply
#4

anyone help please?
Reply
#5

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

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.
Reply
#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
#8

Quote:
Originally Posted by Pottus
Посмотреть сообщение
No need for that dude you only need to check once every death I would personally do something like this.
Hm.. yeah that's much better, thanks :P
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)