SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 07/10/2017, 09:43 PM   #1
Sarti
Little Clucker
 
Sarti's Avatar
 
Join Date: Oct 2016
Posts: 11
Reputation: 0
Default player with best online killings

Code:
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!
Sarti is offline   Reply With Quote
Old 07/10/2017, 11:55 PM   #2
Sew_Sumi
Banned
 
Join Date: Jun 2008
Location: Azerbaijan
Posts: 6,243
Reputation: 525
Default Re: player with best online killings

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.
Sew_Sumi is offline   Reply With Quote
Old 08/10/2017, 12:11 AM   #3
Sarti
Little Clucker
 
Sarti's Avatar
 
Join Date: Oct 2016
Posts: 11
Reputation: 0
Default Re: player with best online killings

I understand but if there are 2 players with the same kills does not come out any better, I would like one at least
Sarti is offline   Reply With Quote
Old 08/10/2017, 03:17 AM   #4
SyS
High-roller
 
SyS's Avatar
 
Join Date: Oct 2015
Posts: 1,939
Reputation: 504
Default Re: player with best online killings

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.
SyS is offline   Reply With Quote
Old 08/10/2017, 05:26 PM   #5
Sarti
Little Clucker
 
Sarti's Avatar
 
Join Date: Oct 2016
Posts: 11
Reputation: 0
Default Re: player with best online killings

Quote:
Originally Posted by SyS View Post
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
Sarti is offline   Reply With Quote
Old 09/10/2017, 10:20 AM   #6
RIDE2DAY
Huge Clucker
 
RIDE2DAY's Avatar
 
Join Date: Jul 2015
Location: Modena, Italy
Posts: 213
Reputation: 381
Default Re: player with best online killings

PHP Code:
GetBestKillerID()
{
    new 
kills 0;
    new 
killerid INVALID_PLAYER_ID;

    for(new 
0GetPlayerPoolSize(); <= tx++)
    {
        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_idnamesizeof(name));

format(messagesizeof(message), "Player [%d]%s is the best killer ever, with an amount of %d kills."best_killer_idnamep_Kills[best_killer_id]);
SendClientMessageToAll(-1message); 
Dude, this isn't tested but I think it should work.
RIDE2DAY is offline   Reply With Quote
Old 13/10/2017, 01:05 AM   #7
Sarti
Little Clucker
 
Sarti's Avatar
 
Join Date: Oct 2016
Posts: 11
Reputation: 0
Post Re: player with best online killings

Quote:
Originally Posted by RIDE2DAY View Post
PHP Code:
GetBestKillerID()
{
    new 
kills 0;
    new 
killerid INVALID_PLAYER_ID;

    for(new 
0GetPlayerPoolSize(); <= tx++)
    {
        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_idnamesizeof(name));

format(messagesizeof(message), "Player [%d]%s is the best killer ever, with an amount of %d kills."best_killer_idnamep_Kills[best_killer_id]);
SendClientMessageToAll(-1message);
format(stringsizeof(string), "[SERVER]:
Congratulations, You've Been The Highest Killer Player Of The Day, bonus: {00C017}$%d. +3 Score"
,Premio);
SendClientMessage(best_killer_id0x00CA97FFstring);
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
Sarti is offline   Reply With Quote
Old 13/10/2017, 01:13 AM   #8
Sew_Sumi
Banned
 
Join Date: Jun 2008
Location: Azerbaijan
Posts: 6,243
Reputation: 525
Default Re: player with best online killings

Quote:
Originally Posted by Sarti View Post
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...
Sew_Sumi is offline   Reply With Quote
Old 13/10/2017, 09:47 AM   #9
raydx
Huge Clucker
 
raydx's Avatar
 
Join Date: Feb 2017
Posts: 203
Reputation: 73
Default Re: player with best online killings

Add break; to the end of your loop.
raydx is offline   Reply With Quote
Old 13/10/2017, 10:33 AM   #10
Sew_Sumi
Banned
 
Join Date: Jun 2008
Location: Azerbaijan
Posts: 6,243
Reputation: 525
Default Re: player with best online killings

Quote:
Originally Posted by raydx View Post
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.
Sew_Sumi is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
no player online AroseKhanNiazi Scripting Help 4 03/05/2014 08:38 AM
how to use dini save online player in to file every time player enter or out Chrisli520 Scripting Help 1 31/10/2013 07:04 AM
[FilterScript] BRecord - Online Player Peak Recording - View your player peak fast, accurate and easily! [MWR]Blood Filterscripts 10 29/10/2012 02:43 PM
Player online Speed Help Archive 2 15/08/2011 09:11 PM
Online Player Map Claude_CJ_Vercetti Help Archive 1 26/04/2011 12:23 PM


All times are GMT. The time now is 07:05 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.