[HELP] Detecting most kills?
#1

Hi, i want to create a kill time with a most kills detector. But don't know how can i do a system like that. There will be a timer (refreshes per minute), and timer will say " %d minutes left, %s leads with %d kills! ".

Any ideas?
Reply
#2

Yeah, it was just an example. But i still don't know what kind of counter i should use (don't know how to compare players' kills, have no idea). The kill time will start, then the counter will start to count each player's own kills. The highest one will win. I will be very glad if you give me an example code.
Reply
#3

Quote:
Originally Posted by ******
Посмотреть сообщение
It's really not hard to make a counter:

pawn Код:
++gPlayerKills[playerid];
Exactly.

pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    playerKills[playerid]++; //I actually didn't know you could put the ++ in front of the variable, thanks Y Less.
    return 1;
}

COMMAND:yourcheck(playerid, params[])
{
    for(new i = 0; i < MAX_PLAYERS; i++) //you should be using foreach, but this works too.
    {
    if(playerKills[i] > playerKills[i]) //I'm actually not sure about this part, I don't know if it'll work or not.. but this is the part where you place your check.
    {
    //blah.
    }
    }
    return 1;
}
Reply
#4

Quote:
Originally Posted by Sky4D
Посмотреть сообщение
Exactly.

----Pawn Code--------
Some edits about it

pawn Код:
new playerKills[MAX_PLAYERS];//at OnPlayerConnect you should set it at 0 "playerKills[playerid] = 0;"

public OnPlayerDeath(playerid, killerid, reason)
{
    playerKills[killerid]++; //killer should get a plus, not the player that die
    return 1;
}

COMMAND:yourcheck(playerid, params[])
{
    new mostkills = INVALID_PLAYER_ID;
    for(new i = 0; i < MAX_PLAYERS; i++) //you should be using foreach, but this works too.
    {
        if(playerKills[i] > playerKills[mostkills]) mostkills = i;
    }
    printf("The ID with most kills is: %d", mostkills");
    return 1;
}
This should work fine. btw i would prefer using PVars.
Reply
#5

Quote:
Originally Posted by Dark_Kostas
Посмотреть сообщение
Some edits about it

pawn Код:
new playerKills[MAX_PLAYERS];//at OnPlayerConnect you should set it at 0 "playerKills[playerid] = 0;"

public OnPlayerDeath(playerid, killerid, reason)
{
    playerKills[killerid]++; //killer should get a plus, not the player that die
    return 1;
}

COMMAND:yourcheck(playerid, params[])
{
    new mostkills = INVALID_PLAYER_ID;
    for(new i = 0; i < MAX_PLAYERS; i++) //you should be using foreach, but this works too.
    {
        if(playerKills[i] > playerKills[mostkills]) mostkills = i;
    }
    printf("The ID with most kills is: %d", mostkills");
    return 1;
}
This should work fine. btw i would prefer using PVars.
Thanks, I was kind of wondering how to go about that too, after I replied, I stared at my code for like 5 minutes going "Hm... is this even going to work?" :P
Reply
#6

Quote:
Originally Posted by ******
Посмотреть сообщение
pawn Код:
new
    gLeader = -1,
    gHighScore = 0,
    gScore[MAX_PLAYERS];


public OnPlayerDeath(playerid, killerid, reason)
{
    ++gScore[killerid];
    if (gScore[killerid] > gHighScore)
    {
        gHighScore = gScore[killerid];
        gLeader = killerid;
    }
    return 1;
}
That will do away with the loop by keeping track of the leader. Note that this code will require additional code in OnPlayerConnect and OnPlayerDisconnect for when people leave and join so the leader is known to be on the server.

And "++var;" is the pre-increment operator, "var++;" is the post-increment operator and they are different, though the difference doesn't matter in this code example.
Alright, thanks a bunch for explaining it.
Reply
#7

Thanks all of you, problem has been solved.

@******, thnaks for explaining, its the easiest way thought. I 've fixed it with another way, but i'll change it with yours, ty.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)