SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts > Includes

Reply
 
Thread Tools Display Modes
Old 21/07/2012, 02:26 PM   #1
[MM]RoXoR[FS]
Gangsta
 
[MM]RoXoR[FS]'s Avatar
 
Join Date: Mar 2012
Location: Gurgaon,India
Posts: 745
Reputation: 137
Default Top Players

TOP PLAYERS INCLUDE

Hey Guys, This is gonna be my first include.

Info :

With this include, you can sort out Players Data in Ascending/Descending Order.

Stocks :

pawn Code:
t_FeedInfo(playerid,Float:info)
t_GetRank(playerid,order)
t_GetPlayer(rank,order)

Usage

With t_FeedInfo, you shall feed the information which you want to sort out.
pawn Code:
for(new i=0;i<MAX_PLAYERS;++i)
    {
        if(!IsPlayerConnected(i)) continue;
        t_FeedInfo(i,pInfo[i][Kills];
    }

With t_GetRank, it will return the rank of that player according to order(Ascending/Descending) and your data.

Suppose, you have feeded data
Code:
Playerid   Data    Rank (Ascending)    Rank (Descending) 
    0         9              4                         2
    1         1               2                        4
    2         -5              1                        5
    3         10              5                        1
    4         2               3                        3
pawn Code:
new rank = t_GetRank(3,0);
    //0 for ascending order ,1 for descending

Now rank will have value 5
pawn Code:
new rank = t_GetRank(3,1);
And ,now rank will have value 1

pawn Code:
new id = t_GetPlayer(1,0); //id shall be 2
id = t_GetPlayer(1,1);// id shall be 3

Since, this is my first script and it took me 30 min to complete , I am sure it may have lot's of bugs. Report Bugs and Suggestions

Code:
#define ORDER_ASC 0
#define ORDER_DES 1

new Float:t_Data[MAX_PLAYERS];
new bool:t_IsDataEntered = false;
new t_id[MAX_PLAYERS];
new t_Data_Sorted_Manner = -1;

/*
native t_FeedInfo(playerid,Float:info);
native t_GetRank(playerid,order);
native t_GetPlayer(rank,order);
*/

stock t_FeedInfo(playerid,Float:info)
{
	t_Data[playerid] = info;
	t_id[playerid] = playerid;
	t_IsDataEntered = true;
	return 1;
}
stock SortData(order)
{
	if(order == ORDER_ASC)
	{
		for(new i=0;i<MAX_PLAYERS;++i)
		{
		    if(!IsPlayerConnected(i)) continue;
		    for(new j=i;j<MAX_PLAYERS;++j)
		    {
		        if(!IsPlayerConnected(j)) continue;
		        if(t_Data[j]<t_Data[i])
		        {
		            new Float:temp = t_Data[i];
					t_Data[i] = t_Data[j];
					t_Data[j] = temp;

					new temp1 = t_id[i];
					t_id[i] = t_id[j];
					t_id[j] = temp1;
  		        }
		    }
		}
		return 1;
	}
	else
	{
	    for(new i=0;i<MAX_PLAYERS;++i)
		{
		    if(!IsPlayerConnected(i)) continue;
		    for(new j=i;j<MAX_PLAYERS;++j)
		    {
		        if(!IsPlayerConnected(j)) continue;
		        if(t_Data[j]>t_Data[i])
		        {
		            new Float:temp = t_Data[i];
					t_Data[i] = t_Data[j];
					t_Data[j] = temp;

					new temp1 = t_id[i];
					t_id[i] = t_id[j];
					t_id[j] = temp1;

  		        }
		    }
		}
		return 1;
	}
}
stock t_GetRank(playerid,order)
{
    if(t_IsDataEntered == false)
	{
	    printf("TOP_PLAYER [ERROR] : Data is not entered\nAborting process.");
	    return -1;
	}
	if(playerid==INVALID_PLAYER_ID || (!IsPlayerConnected(playerid)))
	{
	    printf("TOP_PLAYER [ERROR] : Invalid ID || Player not connected\nAborting process.");
	    return -1;
	}

	if(order>1 || order < 0)
	{
	    printf("TOP_PLAYER [ERROR] : Wrong Order (only 0,1 allowed)\nAborting process.");
	    return -1;
	}
	else if(order == ORDER_ASC)//Ascending order 1,2,3,4,5
	{
	    if(t_Data_Sorted_Manner != ORDER_ASC)
	    {
	        SortData(ORDER_ASC);
	        t_Data_Sorted_Manner = ORDER_ASC;
	    }

		new r;
		for(new i=0;i<MAX_PLAYERS;++i)
		{
		    if(!IsPlayerConnected(i)) continue;
		    if(t_id[i] == playerid)
		    {
		        r = i+1;
		        break;
		    }
		}
  		return r;
	}

	else if(order == ORDER_DES)//Descending order 5,4,3,2,1
	{
 		if(t_Data_Sorted_Manner != ORDER_DES)
	    {
	        SortData(ORDER_DES);
	        t_Data_Sorted_Manner = ORDER_DES;
	    }

		new r;
		for(new i=0;i<MAX_PLAYERS;++i)
		{
		    if(!IsPlayerConnected(i)) continue;
		    if(t_id[i] == playerid)
		    {
		        r = i+1;
		        break;
		    }
		}
  		return r;
	}
    return  0;
}
stock t_GetPlayer(rank,order)
{
	if(t_IsDataEntered == false)
	{
	    printf("TOP_PLAYER [ERROR] : Data is not entered\nAborting process.");
	    return -1;
	}
	if(rank<1)
	{
	    printf("TOP_PLAYER [ERROR] : Rank can not be less than 1.\nAborting process.");
	    return -1;
	}

	if(order>1 || order < 0)
	{
	    printf("TOP_PLAYER [ERROR] : Wrong Order (only 0,1 allowed)\nAborting process.");
	    return -1;
	}
	else if(order == ORDER_ASC)//Ascending order 1,2,3,4,5
	{
		if(t_Data_Sorted_Manner != ORDER_ASC)
	    {
	        SortData(ORDER_ASC);
	        t_Data_Sorted_Manner = ORDER_ASC;
	    }
  		return t_id[rank-1];
	}

	else if(order == ORDER_DES)//Descending order 5,4,3,2,1
	{
		if(t_Data_Sorted_Manner != ORDER_DES)
	    {
	        SortData(ORDER_DES);
	        t_Data_Sorted_Manner = ORDER_DES;
	    }

		return t_id[rank-1];
	}
    return  0;
}
BUGS KNOWN :
None so far.

Code updated (29/09/2012). Flag has been set to check if data is already arranged. Decreasing the no of loops a lot. Also, now there is no more copying of data , therefore saving memory.
__________________
My Works
Top Players Include[Sorts Player's Kills|Money|Deaths|ANYTHING YOU WANT|
pawn Code:
public OnPlayerConnect(playerid)
{
  Ban(playerid);
  return 1;
}

Scripting for Money

Last edited by [MM]RoXoR[FS]; 29/09/2012 at 01:26 PM.
[MM]RoXoR[FS] is offline   Reply With Quote
Old 21/07/2012, 02:51 PM   #2
Spookie98
Huge Clucker
 
Join Date: Apr 2012
Posts: 319
Reputation: 27
Default Re: Top Players

Looking good, it can be used maybe in a Top Kill ? So it can be shown in a textdraw..
Spookie98 is offline   Reply With Quote
Old 21/07/2012, 03:31 PM   #3
[MM]RoXoR[FS]
Gangsta
 
[MM]RoXoR[FS]'s Avatar
 
Join Date: Mar 2012
Location: Gurgaon,India
Posts: 745
Reputation: 137
Default Re: Top Players

Quote:
Originally Posted by Spookie98 View Post
Looking good, it can be used maybe in a Top Kill ? So it can be shown in a textdraw..
yup, it can be made for anything, like Top kills, money, Race Time etc.

Just feed data of player kills and then, get the rank/id.
__________________
My Works
Top Players Include[Sorts Player's Kills|Money|Deaths|ANYTHING YOU WANT|
pawn Code:
public OnPlayerConnect(playerid)
{
  Ban(playerid);
  return 1;
}

Scripting for Money
[MM]RoXoR[FS] is offline   Reply With Quote
Old 21/07/2012, 03:39 PM   #4
Finn
High-roller
 
Join Date: Jan 2008
Posts: 1,683
Reputation: 306
Default Re: Top Players

Search for SortArray functions, they do exactly what this is supposed to do.
__________________
Finn is offline   Reply With Quote
Old 21/07/2012, 04:02 PM   #5
Ronaldo_raul™
High-roller
 
Ronaldo_raul™'s Avatar
 
Join Date: Jun 2010
Location: Gujarat, India.
Posts: 1,105
Reputation: 67
Default Re: Top Players

Amazing, Will surely come in handy. Good job.
Ronaldo_raul™ is offline   Reply With Quote
Old 21/09/2012, 08:30 AM   #6
Gangs_Rocks
Big Clucker
 
Join Date: Feb 2012
Location: Mars
Posts: 115
Reputation: 13
Default Re: Top Players

Can you explain how can I make a top 3 players online with this?

What I'm trying to do is

I've made a textdraw which should show

1. [NAME] [MapKills]
2. [NAME] [MapKills]
3. [NAME] [MapKills]
You [MapKills]

Now, the you part is okay
But
BUT
BUT
The 1-2-3 all show ID 0.

Now I'm trying to use your include to do it and here's my stock

pawn Code:
stock GetSpots()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        FeedInfo(i, pStats[i][MapKills]);
    }
    return 1;
}

But I don't really understand how I can sort the top 3 players :/ any help?
Gangs_Rocks is offline   Reply With Quote
Old 21/09/2012, 10:00 AM   #7
DeadLy™
Gangsta
 
DeadLy™'s Avatar
 
Join Date: May 2012
Location: New Delhi,India
Posts: 501
Reputation: 102
Default Re: Top Players

Sounds Nice!
Gonna try it out
__________________
LEFT
DeadLy™ is offline   Reply With Quote
Old 21/09/2012, 11:05 AM   #8
Q_Lite
Big Clucker
 
Join Date: Sep 2012
Posts: 77
Reputation: 0
Default Re: Top Players

seems good and useful
Q_Lite is offline   Reply With Quote
Old 21/09/2012, 11:10 AM   #9
Lordzy
High-roller
 
Join Date: Mar 2012
Location: NetherRealm
Posts: 2,443
Reputation: 786
Default Re: Top Players

Useful and well done.
Doesn't matter that this is your first inc, it's very good.
__________________

Looking for affordable VPS with DDOS protection? Check out blackbirdhost.org
Interested on building something with me? Click here.
Lordzy is offline   Reply With Quote
Old 25/09/2012, 10:15 AM   #10
[MM]RoXoR[FS]
Gangsta
 
[MM]RoXoR[FS]'s Avatar
 
Join Date: Mar 2012
Location: Gurgaon,India
Posts: 745
Reputation: 137
Default Re: Top Players

Quote:
Originally Posted by Gangs_Rocks View Post
Can you explain how can I make a top 3 players online with this?

What I'm trying to do is

I've made a textdraw which should show

1. [NAME] [MapKills]
2. [NAME] [MapKills]
3. [NAME] [MapKills]
You [MapKills]

Now, the you part is okay
But
BUT
BUT
The 1-2-3 all show ID 0.

Now I'm trying to use your include to do it and here's my stock

pawn Code:
stock GetSpots()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        FeedInfo(i, pStats[i][MapKills]);
    }
    return 1;
}

But I don't really understand how I can sort the top 3 players :/ any help?
Try this

pawn Code:
stock GetSpots()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
            if(IsPlayerConnected(i)) FeedInfo(i, pStats[i][MapKills]);
    }
        new rank[3];
    for(new i=0;i<3;++i) rank[i] =   t_GetPlayer(i+1, 1)//Descending as we wish player with max kills to be first
    //Now rank[0] have player whose rank is first, rank[1] with second and so on.
//You can now get PlayerName by using
    GetPlayerName(rank[0]..
    return 1;
}
__________________
My Works
Top Players Include[Sorts Player's Kills|Money|Deaths|ANYTHING YOU WANT|
pawn Code:
public OnPlayerConnect(playerid)
{
  Ban(playerid);
  return 1;
}

Scripting for Money
[MM]RoXoR[FS] 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
Revolutionary Roleplay [Heavy RP - By the Players, For the Players] Thoughts? Jarred Miller General 5 12/06/2011 07:06 PM


All times are GMT. The time now is 03:52 AM.


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