Raised This Month: $ Target: $400
 0% 

How to get selected player from mysql?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
jonatat
Senior Member
Join Date: Dec 2017
Old 07-02-2018 , 12:42   How to get selected player from mysql?
Reply With Quote #1

I wanna made a top 5 users with menu_create and if i press on player show custom stats. Example:

I write /top5 i get menu from mysql by points:

TOP USERS MENIU
1) USER1 [300 points]
2) USER2 [100 points]
3) USER3 [25 points]

And if i press number 1 i get:

USER1 STATISTICS
4102 kills
265 deaths
654hs

and etc... I have made like this:

PHP Code:
public sqlLoadTop()
{
new 
Handle:hQuery;
hQuery SQL_PrepareQuery(g_sql"SELECT player_name, points FROM users ORDER BY points DESC LIMIT 5;");

if(!
SQL_Execute(hQuery))
checkError(hQuery1);
else if(
SQL_NumResults(hQuery))
{
g_top_menu menu_create("TOP 5 PLAYERS""menu_Top5Nothing");

g_block_top_menu 0;

new 
sData[128];
new 
player_name[32];
new 
sPosition[2];
new 
points[128];

new 
iPosition;

while(
SQL_MoreResults(hQuery))
{
++
iPosition;

SQL_ReadResult(hQuery0player_namecharsmax(player_name));
SQL_ReadResult(hQuery1pointscharsmax(points));

num_to_str(iPositionsPositioncharsmax(sPosition));

formatex(sDatacharsmax(sData), "%s \y[\r%s\y]"player_namepoints);

menu_additem(g_top_menusDatasPosition);

SQL_NextRow(hQuery);
}

menu_setprop(g_top_menuMPROP_NEXTNAME"Next");
menu_setprop(g_top_menuMPROP_BACKNAME"Back");
menu_setprop(g_top_menuMPROP_EXITNAME"Exit");

SQL_FreeHandle(hQuery);
}
else
{
g_block_top_menu 1;
SQL_FreeHandle(hQuery);
}
return 
PLUGIN_HANDLED;
}

public 
checkError(const Handle:hQuery, const query_num)
{
SQL_QueryError(hQueryg_sql_errorcharsmax(g_sql_error));

log_to_file("error_sql.log""- error: %d - code: %s"query_numg_sql_error);

SQL_FreeHandle(hQuery);
}

public 
clcmd_Top15(id)
{
if(!
is_user_connected(id))
return 
PLUGIN_HANDLED;

if(
g_block_top_menu)
{
return 
PLUGIN_HANDLED;
}

menu_display(idg_top_menu);

return 
PLUGIN_HANDLED;
}

public 
menu_Top5Nothing(idmenuiditem)
{
if(!
is_user_connected(id) || item == MENU_EXIT)
return 
PLUGIN_HANDLED;

clcmd_Top15(id);
return 
PLUGIN_HANDLED;

But i dont know how to get submenu by player like in my example. Any help? Thanks guys!
jonatat is offline
maqi
Senior Member
Join Date: Apr 2017
Location: Serbia
Old 07-02-2018 , 12:47   Re: How to get selected player from mysql?
Reply With Quote #2

In your menu handler just make another menu using the info parameter of the first menu passing userid for example
__________________
stuff

Last edited by maqi; 07-02-2018 at 12:47.
maqi is offline
jonatat
Senior Member
Join Date: Dec 2017
Old 07-02-2018 , 12:48   Re: How to get selected player from mysql?
Reply With Quote #3

Quote:
Originally Posted by maqi View Post
In your menu handler just make another menu using the info parameter of the first menu passing userid for example
Can u make a example? I need stay on the right road Thanks for answer!

Last edited by jonatat; 07-02-2018 at 12:49.
jonatat is offline
maqi
Senior Member
Join Date: Apr 2017
Location: Serbia
Old 07-02-2018 , 12:53   Re: How to get selected player from mysql?
Reply With Quote #4

Check out menu_item_getinfo, you are already passing something called position, so you might wanna add something like userid to that string and parse it later, however I don't see you using the position so I don't see the point of it.

Try to make it yourself, I can put you on the right path later

Also, why is your code not indented ?
__________________
stuff

Last edited by maqi; 07-02-2018 at 12:53.
maqi is offline
shauli
Member
Join Date: Jun 2018
Old 07-02-2018 , 13:27   Re: How to get selected player from mysql?
Reply With Quote #5

Get also the player's steamid in sqlLoadTop and add it to the item data with menu_additem.
Then in your menu handler, grab that steamid and execute another query.

Last edited by shauli; 07-02-2018 at 13:27.
shauli 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 12:38.


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