PDA

View Full Version : player with best online killings


Sarti
07/10/2017, 09:43 PM
stock bestkill()
{

new string[120];

new Player;


for(new i=0; i<MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{

if(BKills[i] < 1)
{
format(string, sizeof(string), "Best Player Killer Of Day None , Kills:
(0)",PlayerInfo[PlayerÇ[pName],Player,BKills[Player]);
SendClientMessageToAll(COLOR_BEST, string);
}
else
{
if(BKills[i] > BKills[Player]) Player = i;
format(string, sizeof(string), "Best Player Killer Of Day %s(%d), Kills: (%d)",PlayerInfo[Player]
[pName],Player,BKills[Player]);
SendClientMessageToAll(COLOR_BEST, string);

}
}
}

when 2 players have the same kills when running stock does not detect anyone as best killer
HELP!

Sew_Sumi
07/10/2017, 11:55 PM
When this does work, it will spam the shit out of you every time it picks up a player higher than the 'best', it will show another line.

The format line, and the SendClientMessageToAll should be OUTSIDE the loop.

Sarti
08/10/2017, 12:11 AM
I understand but if there are 2 players with the same kills does not come out any better, I would like one at least

SyS
08/10/2017, 03:17 AM
find the largest kills amount by looping and then loop again to concat the details of player having same amount of largest kills to a string and show that string as a message.

Sarti
08/10/2017, 05:26 PM
find the largest kills amount by looping and then loop again to concat the details of player having same amount of largest kills to a string and show that string as a message.

could you give me an example please

RIDE2DAY
09/10/2017, 10:20 AM
GetBestKillerID()
{
new kills = 0;
new killerid = INVALID_PLAYER_ID;

for(new x = 0, t = GetPlayerPoolSize(); x <= t; x++)
{
if(!IsPlayerConnected(x)) continue;

if(p_Kills[x] > kills)
{
kills = p_Kills[x];
killerid = x;
}
}

return killerid;
}

// - Somewhere - //
new name[24];
new message[144];

new best_killer_id = GetBestKillerID();

GetPlayerName(best_killer_id, name, sizeof(name));

format(message, sizeof(message), "Player [%d]%s is the best killer ever, with an amount of %d kills.", best_killer_id, name, p_Kills[best_killer_id]);
SendClientMessageToAll(-1, message);
Dude, this isn't tested but I think it should work.

Sarti
13/10/2017, 01:05 AM
GetBestKillerID()
{
new kills = 0;
new killerid = INVALID_PLAYER_ID;

for(new x = 0, t = GetPlayerPoolSize(); x <= t; x++)
{
if(!IsPlayerConnected(x)) continue;

if(p_Kills[x] > kills)
{
kills = p_Kills[x];
killerid = x;
}
}

return killerid;
}

// - Somewhere - //
new name[24];
new message[144];
new premio = 50000
new best_killer_id = GetBestKillerID();

GetPlayerName(best_killer_id, name, sizeof(name));

format(message, sizeof(message), "Player [%d]%s is the best killer ever, with an amount of %d kills.", best_killer_id, name, p_Kills[best_killer_id]);
SendClientMessageToAll(-1, message);
format(string, sizeof(string), "[SERVER]:
Congratulations, You've Been The Highest Killer Player Of The Day, bonus: {00C017}$%d. +3 Score",Premio);
SendClientMessage(best_killer_id, 0x00CA97FF, string);
GivePlayerCash(best_killer_id,Premio);
Dude, this isn't tested but I think it should work.


It worked for me but now when I receive the prize the prize is repeated for players connected
example:
if there are 20 players, the prize for the best killer is repeated 20 times

Sew_Sumi
13/10/2017, 01:13 AM
if there are 20 players, the prize for the best killer is repeated 20 times

That's what I said about before... Obviously you've got this inside a loop by simply copy-pasting it in the wrong place...

raydx
13/10/2017, 09:47 AM
Add break; to the end of your loop.

Sew_Sumi
13/10/2017, 10:33 AM
Add break; to the end of your loop.

Can you not guess... It's pretty clear what the issue is if you know what is going on.

OverflowJ
13/10/2017, 02:54 PM
new highestkills=0;
new mykills[MAX_PLAYERS] = 0;
new topfragger;


public OnPlayerDeath(playerid, killerid, reason)
{
mykills[killerid]++;

if (mykills[killerid] > highestkills)
{
highestkills = mykills[killerid];
topfragger = killerid;
}

return 1;
}

Did I help?

Prokill911
13/10/2017, 05:17 PM
It worked for me but now when I receive the prize the prize is repeated for players connected
example:
if there are 20 players, the prize for the best killer is repeated 20 times

Simply multiple the prize by the amount of players online.

PrizeMultiplyer() {
new activeplayers = 0
for(new i=0;i<MAX_PLAYERS;i++) {
if(IsPlayerConnectEx(i)) {
activeplayers++;
}
}
return activeplayers;
}


new prize = 5000;
new prizetotal = PrizeMultiplyer();
new giveprize = prizetotal * prize;
GivePlayerMoney(winnerid, giveprize);

Not tested. just an example

Sew_Sumi
14/10/2017, 12:27 AM
What RIDE2DAY posted is the best method...

OP, show what code you've got currently, and ignore these guys that are simply rep-hunting/throwing up guesses...

Sarti
14/10/2017, 09:09 PM
What RIDE2DAY posted is the best method...

OP, show what code you've got currently, and ignore these guys that are simply rep-hunting/throwing up guesses...


GetBestKillerID()
{
new kills = 0;
new killerid = INVALID_PLAYER_ID;

for(new x = 0, t = GetPlayerPoolSize(); x <= t; x++)
{
if(!IsPlayerConnected(x)) continue;

if(Best_Killer[x] > kills)
{
kills = Best_Killer[x];
killerid = x;
}
}

return killerid;
}

stock MejoresJugadores()
{

new string[256];
new Premio;

new best_killer_id = GetBestKillerID();

for(new i=0; i<MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
if(Best_Killer[i] < 1)
{
format(string, sizeof(string), "~r~~h~Best Killer ~p~None ~w~Score: ~g~0",i);
TextDrawSetString(Mejor2, string);
TextDrawShowForAll(Mejor2);
}
else
{

Premio = 5267*Best_Killer[best_killer_id];
format(string, sizeof(string), "~r~~h~Best Killer ~p~%s(%d) ~w~Score: ~g~+%d",PlayerInfo[best_killer_id][pName],best_killer_id,Best_Killer[best_killer_id]);
TextDrawSetString(Mejor2, string);
TextDrawShowForAll(Mejor2);
format(string, sizeof(string), "[SERVER]: Congratulation, You Are The Best Killer, Bonus: {00C017}$%d. +3 Score",Premio);
SendClientMessage(best_killer_id, 0x00CA97FF, string);
GivePlayerCash(best_killer_id,Premio);
PlayerInfo[best_killer_id][pScore] += 3;
}
}
}
return 1;
}


I have it that way because I need it when nobody is the best killer comes the message "No one has been the best killer of the day"

Sew_Sumi
15/10/2017, 07:44 AM
I have it that way because I need it when nobody is the best killer comes the message "No one has been the best killer of the day"

You could quite simply have put...

if(BestKillerID==INVALID_PLAYER_ID)


That's not a real reason to rip apart his code and break it...

Sarti
16/10/2017, 12:50 AM
You could quite simply have put...

if(BestKillerID==INVALID_PLAYER_ID)


That's not a real reason to rip apart his code and break it...

Where

Sew_Sumi
16/10/2017, 01:30 AM
Where do you think it goes, because this is simple...

I'll chuck this up, but seriously, this sort of thing, if someone hands you code, at leaast try and learn it rather than simply copying it, pasting it, seeing it doesn't work the way you wanted it, and reverting it to what you had which was broken.

new best_killer_id = GetBestKillerID();

if(best_killer_id==INVALID_PLAYER_ID)
{
format(message, sizeof(message), "There is no best killer at this time");
}
else
{
GetPlayerName(best_killer_id, name, sizeof(name));
format(message, sizeof(message), "Player [%d]%s is the best killer ever, with an amount of %d kills.", best_killer_id, name, p_Kills[best_killer_id]);
}
SendClientMessageToAll(-1, message);

This, also, is untested, but should at least be workable.