top 3 players by damage
#1

So I made something easy , a script which tells everyone top 3 players every 15 minutes (by damage).

Код:
forward CountPlayerDamage(playerid);
public CountPlayerDamage(playerid)
{

    new TopString[3][128], string[250];
    
    SendClientMessageToAll(-1, "{e6b3ff}*** Top 3 Players by damage");
	SendClientMessageToAll(-1, TopString[0]);
	SendClientMessageToAll(-1, TopString[1]);
	SendClientMessageToAll(-1, TopString[2]);
	
	for(new i = 0; i != p; ++i) {
	if(i == 0) format(TopString[0], 128, "{e6b3ff}*** 1st: %s %d damage", PlayerName[i], PlayerDamage[i]);
	else if(i == 1) format(TopString[1], 128, "{e6b3ff}*** 2nd: %s %d damage", PlayerName[i], PlayerDamage[i]);
	else if(i == 2) format(TopString[2], 128, "{e6b3ff}*** 3rd: %s %d damage", PlayerName[i], PlayerDamage[i]);
	}

    format(string, sizeof(string), "{e6b3ff}*** Your damage was %.2f, made in 15 minutes.", PlayerDamage[playerid]);
    SendClientMessage(playerid, -1, string);
    PlayerDamage[playerid] = 0;

    return 1;
}
It was all inside a timer which as I said, every 15 minutes there will be again another top 3 players by damage. I in half created it but also used taking a look at some codes already done at samp forums. (Just to get a better idea and some examples to elaborate better what I want to make), I get only 1 error which is

Код:
C:\Users\fomina.janett1919\Desktop\gtadm\gamemodes\gtadm.pwn(5521) : error 017: undefined symbol "p"
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Error.
Line 5521:

Код:
for(new i = 0; i != p; ++i) {
I'm not really used to make kind of stuff, so I really wonder... if I did it correctly. Would be really pleased if you fix this code up or tell me whats wrong with a tip to make it work.
Reply
#2

Код:
for(new i = 0; i < MAX_PLAYERS; i++)
{ 
    if(IsPlayerConnected(i))
    {
	if(i == 0) format(TopString[0], 128, "{e6b3ff}*** 1st: %s %d damage", PlayerName[i], PlayerDamage[i]);
	else if(i == 1) format(TopString[1], 128, "{e6b3ff}*** 2nd: %s %d damage", PlayerName[i], PlayerDamage[i]);
	else if(i == 2) format(TopString[2], 128, "{e6b3ff}*** 3rd: %s %d damage", PlayerName[i], PlayerDamage[i]);
    }
}
Reply
#3

I'm requesting help again, tested it but, I did 300 dmg and another guy did 500 dmg, he was second and I was first:

1st plane 300 dmg
2nd truck 500 dmg

I think I'm missing something in that code.
Reply
#4

anyone ?
Reply
#5

Quote:
Originally Posted by severance
Посмотреть сообщение
anyone ?
Haha it's because you used it by PLAYER IDs: id 0 = 1st, id 1 = 2nd.. if you id 20 you are 20th place LMAO


So I will give you something that will work 100% this code is in my server and tesed with no issues!

Код:
public BestPlayers()
{
	//We are using the variable " Kills[playerid] " you can anything else instead
		
        new id1 = -1,id2 = -1,id3 = -1,pkills = -100;
        
        //Getting 1st place
        for(new i; i <MAX_PLAYERS; i++)if(Kills[i] > pkills && Kills[i] != 0) id1 = i;
        
        //Getting 2nd place
        pkills = -100;
        for(new i; i <MAX_PLAYERS; i++)if(Kills[i] > pkills && i != id1 && Kills[i] != 0) id2 = i;
        
        //Getting 3rd place
        pkills = -100;
        for(new i; i <MAX_PLAYERS; i++)if(Kills[i] > pkills && i != id2 && i != id1 && Kills[i] != 0) id3= i;

        SendClientMessageToAll(-1, "-------------- Best 3 Players with most kills ---------------");
        if(id1==-1 && id2==-1 && id3==-1)return SendClientMessageToAll(0xff0000aa,"There are no players with kills")
        
        //Using 1st place
	if(id1 != -1 && Kills[id1] != 0) SendFMsgToAll(0xff0000aa, "%s {ffffff}KILLS: {ff0000}%d {ffffff}|1st Place|",GetName(id1),Kills[id1]);
        else SendClientMessageToAll(0xff0000aa, "- No One In 1st Place -");

        //Using 2nd place
        if(id2 != -1 && Kills[id2] != 0) SendFMsgToAll(0xff0000aa, "%s {ffffff}KILLS: {ff0000}%d {ffffff}|2nd Place|",GetName(id2),Kills[id2]);
        else SendClientMessageToAll(0xff0000aa, "- No One In 2nd Place -");
        
        //Using 3rd place
        if(id3 != -1 && Kills[id3] != 0) SendFMsgToAll(0xff0000aa, "%s {ffffff}KILLS: {ff0000}%d {ffffff}|3rd Place|",GetName(id3),Kills[id3]);
        else SendClientMessageToAll(0xff0000aa, "- No One In 3rd Place -");
}
Enjoy ( :
Reply
#6

Thanks ! almost done:
PHP код:
forward CountPlayerDamage(playerid);
public 
CountPlayerDamage(playerid)
{
    new 
id1 = -1,id2 = -1,id3 = -1,pPlayerDamage = -100;
    for(new 
i<MAX_PLAYERSi++)if(PlayerDamage[i] > pPlayerDamage && PlayerDamage[i] != 0id1 i;
    
pPlayerDamage = -100;
    for(new 
i<MAX_PLAYERSi++)if(PlayerDamage[i] > pPlayerDamage && != id1 && PlayerDamage[i] != 0id2 i;
    
pPlayerDamage = -100;
    for(new 
i<MAX_PLAYERSi++)if(PlayerDamage[i] > pPlayerDamage && != id2 && != id1 && PlayerDamage[i] != 0id3i;
    
SendClientMessageToAll(-1"{e6b3ff}*** Top 3 Players by damage");
    if(
id1 != -&& PlayerDamage[id1] != 0SendClientMessageToAll(-1"*** 1st: %s %d damage",PlayerName(id1), PlayerDamage[id1]);
    if(
id2 != -&& PlayerDamage[id2] != 0SendClientMessageToAll(-1"*** 2dn: %s %d damage",PlayerName(id2), PlayerDamage[id2]);
    if(
id3 != -&& PlayerDamage[id3] != 0SendClientMessageToAll(-1"*** 3rd: %s %d damage",PlayerName(id3), PlayerDamage[id3]);
    
    new 
string[115];
    
format(stringsizeof(string), "{00b300}*** You did a total of %.2f damage."PlayerDamage[playerid]);
    
SendClientMessage(playerid, -1string);
    
    
PlayerDamage[playerid] = 0;
    
    return 
1;

PHP код:
C:\Users\fomina.janett1919\Desktop\gtadm\gamemodes\gtadm.pwn(5587) : error 012invalid function callnot a valid address
C
:\Users\fomina.janett1919\Desktop\gtadm\gamemodes\gtadm.pwn(5587) : warning 215expression has no effect
C
:\Users\fomina.janett1919\Desktop\gtadm\gamemodes\gtadm.pwn(5587) : error 001expected token";"but found ")"
C:\Users\fomina.janett1919\Desktop\gtadm\gamemodes\gtadm.pwn(5587) : error 029invalid expressionassumed zero
C
:\Users\fomina.janett1919\Desktop\gtadm\gamemodes\gtadm.pwn(5587) : fatal error 107too many error messages on one line 
Code 5587:

PHP код:
if(id1 != -&& PlayerDamage[id1] != 0SendClientMessageToAll(-1"*** 1st: %s %d damage",PlayerName(id1), PlayerDamage[id1]); 
Maybe you know what's wrong there?
Reply
#7

Define this below your includes:
Код:
new fstr[128];
#define SendFMsgToAll(%0,%1,%2) format(fstr, sizeof(fstr), %1, %2) && SendClientMessageToAll(%0, fstr)
Код:
if(id1 != -1 && PlayerDamage[id1] != 0) SendFMsgToAll(-1, "*** 1st: %s %d damage",PlayerName(id1), PlayerDamage[id1]);
Reply
#8

Quote:
Originally Posted by NeXTGoD
Посмотреть сообщение
Define this below your includes:
Код:
new fstr[128];
#define SendFMsgToAll(%0,%1,%2) format(fstr, sizeof(fstr), %1, %2) && SendClientMessageToAll(%0, fstr)
Код:
if(id1 != -1 && PlayerDamage[id1] != 0) SendFMsgToAll(-1, "*** 1st: %s %d damage",PlayerName(id1), PlayerDamage[id1]);
Done, but still same error
Reply
#9

Quote:
Originally Posted by ******
Посмотреть сообщение
Get md-sort, it sorts players by any defined criteria and then you can just take the first three.
Got any tutorials explaining the sort stuff?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)