AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How to get selected player from mysql? (https://forums.alliedmods.net/showthread.php?t=308758)

jonatat 07-02-2018 12:42

How to get selected player from mysql?
 
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!

maqi 07-02-2018 12:47

Re: How to get selected player from mysql?
 
In your menu handler just make another menu using the info parameter of the first menu passing userid for example

jonatat 07-02-2018 12:48

Re: How to get selected player from mysql?
 
Quote:

Originally Posted by maqi (Post 2600580)
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!

maqi 07-02-2018 12:53

Re: How to get selected player from mysql?
 
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 :D

Also, why is your code not indented ?

shauli 07-02-2018 13:27

Re: How to get selected player from mysql?
 
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.


All times are GMT -4. The time now is 12:38.

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