Raised This Month: $12 Target: $400
 3% 

Creating ranking system


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
shavit
AlliedModders Donor
Join Date: Dec 2011
Location: Israel
Old 03-22-2013 , 12:31   Creating ranking system
Reply With Quote #1

PHP Code:
void:UpdateRank(client)
{
    new 
String:auth[32];
    
GetClientAuthString(clientauth32);
    
    new 
String:query[256];
    
Format(query256"SELECT * FROM playerpoints ORDER BY points DESC");
    
    
SQL_TQuery(gH_SQLdbUpdateRankCallbackqueryclientDBPrio_High);
}

public 
UpdateRankCallback(Handle:ownerHandle:hndl, const String:error[], any:client)
{
    if(
hndl == INVALID_HANDLE)
    {
        
LogError("SQL Error on UpdateRank: %s"error);
        
        return;
    }
    
    new 
rank;
    
    while(
SQL_HasResultSet(hndl) && SQL_FetchRow(hndl))
    {
        
rank++;
    }
    
    
gI_Cache_ClientRank[client] = rank;
    
    
CloseHandle(hndl);

Seems like it doesn't work.

This is how the database looks like:
http://i.imgur.com/EDUE5Dz.png


It always returns the number of rows.
__________________
retired
shavit is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 03-22-2013 , 12:36   Re: Creating ranking system
Reply With Quote #2

Have you ever look examples from ...addons\sourcemod\scripting\testsuite\ ?
There is simple plugins source, sqltest.sp
Bacardi is offline
shavit
AlliedModders Donor
Join Date: Dec 2011
Location: Israel
Old 03-22-2013 , 12:53   Re: Creating ranking system
Reply With Quote #3

Quote:
Originally Posted by Bacardi View Post
Have you ever look examples from ...addons\sourcemod\scripting\testsuite\ ?
There is simple plugins source, sqltest.sp
Haven't found anything related.
__________________
retired
shavit is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 03-22-2013 , 14:02   Re: Creating ranking system
Reply With Quote #4

ok, I assume you try get player rank position by counting all players above... ?
But you have not using player auth at all.

Anyway, could this way work ?
http://stackoverflow.com/questions/1...after-order-by

Could we make variable in query and let the mysql do the work ?
I go eat.
__________________
Do not Private Message @me
Bacardi is offline
shavit
AlliedModders Donor
Join Date: Dec 2011
Location: Israel
Old 03-22-2013 , 14:14   Re: Creating ranking system
Reply With Quote #5

Quote:
Originally Posted by Bacardi View Post
ok, I assume you try get player rank position by counting all players above... ?
But you have not using player auth at all.

Anyway, could this way work ?
http://stackoverflow.com/questions/1...after-order-by

Could we make variable in query and let the mysql do the work ?
I go eat.
PHP Code:
Format(query256"SELECT `auth` FROM `playerpoints` ORDER BY `points` DESC"); 
Still doesn't work
__________________
retired

Last edited by shavit; 03-22-2013 at 14:20.
shavit is offline
thetwistedpanda
Good Little Panda
Join Date: Sep 2008
Old 03-22-2013 , 14:51   Re: Creating ranking system
Reply With Quote #6

You never limit the scope to the client auth. You always select all data. WHERE auth = 's'
__________________

Last edited by thetwistedpanda; 03-22-2013 at 14:51.
thetwistedpanda is offline
shavit
AlliedModders Donor
Join Date: Dec 2011
Location: Israel
Old 03-22-2013 , 14:58   Re: Creating ranking system
Reply With Quote #7

Quote:
Originally Posted by thetwistedpanda View Post
You never limit the scope to the client auth. You always select all data. WHERE auth = 's'
PHP Code:
Format(query256"SELECT * FROM `playerpoints` WHERE auth = '%s' ORDER BY `points` DESC"auth); 
Still doesn't work, I think that I don't understand SQL at all..

I mean, now it returns 1.
__________________
retired

Last edited by shavit; 03-22-2013 at 16:19.
shavit is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 03-22-2013 , 17:45   Re: Creating ranking system
Reply With Quote #8

I found something http://thinkdiff.net/mysql/how-to-ge...g-mysql-query/



- Query all auth, name, points etc. etc. SELECT *
- But if you want only rank position SELECT rank. And no, don't create column rank in playerpoints table
PHP Code:
SET @rownum 0;

SELECT *
FROM
(
    
SELECT @rownum := @rownum AS rankauthpointsname
    FROM playerpoints ORDER BY points DESC
)
AS 
result WHERE auth 'STEAM_0:0:54832373' 

plugin code `rank`


*edit More more...
This version not need @variable. And same thing, not need create column rank


PHP Code:
SELECT COUNT(*) AS rankauthpointsname
FROM
(
    
SELECT pointsauthnameCOUNT(*)
    
FROM playerpoints
    GROUP BY points
)
AS 
result WHERE points >= ( SELECT points FROM playerpoints WHERE auth='STEAM_0:0:9999' 
plugin code `rank` 2


*third example
PHP Code:
SELECT(
SELECT COUNT(*)+1 FROM playerpoints AS b WHERE b.points a.points
) AS rank a.*
FROM playerpoints AS a
WHERE a
.auth 'STEAM_0:1:14141' 
Attached Thumbnails
Click image for larger version

Name:	rankmysql.png
Views:	422
Size:	28.6 KB
ID:	117482   Click image for larger version

Name:	rankmysql2.png
Views:	351
Size:	17.2 KB
ID:	117509  

Last edited by Bacardi; 03-23-2013 at 07:10.
Bacardi is offline
shavit
AlliedModders Donor
Join Date: Dec 2011
Location: Israel
Old 03-22-2013 , 17:51   Re: Creating ranking system
Reply With Quote #9

Quote:
Originally Posted by Bacardi View Post
I found something http://thinkdiff.net/mysql/how-to-ge...g-mysql-query/



- Query all auth, name, points etc. etc. SELECT *
- But if you want only rank position SELECT rank. And no, don't create column rank in playerpoints table
PHP Code:
SET @rownum := 0;

SELECT *
FROM
(
    
SELECT @rownum := @rownum AS rankauthpointsname
    FROM playerpoints ORDER BY points DESC
)
AS 
result WHERE auth 'STEAM_0:0:54832373' 
Try with plugin
PHP Code:
Format(query300"SET @rownum := 0;SELECT `rank`, `auth`, `points`, `name` FROM(SELECT @rownum := @rownum + 1 AS `rank`, `auth`, `points`, `name` FROM `playerpoints` ORDER BY `points` DESC)AS result WHERE `auth` = '%s' "auth); 
PHP Code:
void:UpdateRank(client)
{
    new 
String:auth[32];
    
GetClientAuthString(clientauth32);
    
    new 
String:query[512];
    
Format(query512"SET @rownum := 0;SELECT `rank`, `auth`, `points`, `name` FROM(SELECT @rownum := @rownum + 1 AS `rank`, `auth`, `points`, `name` FROM `playerpoints` ORDER BY `points` DESC)AS result WHERE `auth` = '%s' "auth);  
    
    
SQL_TQuery(gH_SQLdbUpdateRankCallbackqueryclientDBPrio_High);
}

public 
UpdateRankCallback(Handle:ownerHandle:hndl, const String:error[], any:client)
{
    if(
hndl == INVALID_HANDLE)
    {
        
LogError("SQL Error on UpdateRank: %s"error);
        
        return;
    }
    
    new 
rank;
    
    while(
SQL_HasResultSet(hndl) && SQL_FetchRow(hndl))
    {
        
rank++;
    }
    
    
gI_Cache_ClientRank[client] = rank;
    
    
CloseHandle(hndl);

Gives me the result as 0.
Edit: Causes SQL error because rank doesn't exist, and you told me to not create it. I'm confused.
__________________
retired

Last edited by shavit; 03-22-2013 at 17:59.
shavit is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 03-22-2013 , 18:07   Re: Creating ranking system
Reply With Quote #10

*Here
I hate long topics... quote quote quote quote
__________________
Do not Private Message @me

Last edited by Bacardi; 03-22-2013 at 21:00.
Bacardi is offline
Reply



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

Forum Jump


All times are GMT -4. The time now is 10:08.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode