• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Pawn] I need some help with my /whois command.
#1
So I am trying to create a /whois command that does the following:



You type '/whois character Sean_Johnson' for example.



As a result, you get this string/msgbox:



SQLID: 10

Account: Stefhan

Characters: Sean_Johnson, Carl_Johnson, Kendl_Johnson

CHRIDS: 40, 41, 49

Level: 10, 5, 8



However, the info required is in two seperate tables (accounts & characters), which is where I get stuck. I simply don't know how to proceed. Can anyone guide me further? What is an?efficient way to do this??Am I even doing it right? I appreciate the assistance.



PHP Code:
CMD:whois(playeridparams[])

{

? ? if(
Account[playerid][Admin] >= 2)

? ? {

? ? ? ? new 
subcmd[30], scmd_params[30];



? ? ? ? if(
sscanf(params"s[30]S()[30]",subcmdscmd_params))

? ? ? ? ? ? return 
SendClientMessage(playeridCOLOR_INFO"/whois [character/chrid/account/sqlid]");





? ? ? ? 
// whois character subcmd

? ? ? ? if(strmatch(subcmd"character"))

? ? ? ? {

? ? ? ? ? ? new 
target[MAX_PLAYER_NAME], str[128];



? ? ? ? ? ? if(
sscanf(params"s[30]s[24]",subcmdtarget))

? ? ? ? ? ? ? ? return 
SendClientMessage(playeridCOLOR_INFO"/whois character [Character_Name(case sensitive)]");



? ? ? ? ? ? new 
query[250];

? ? ? ? ? ? 
mysql_format(MHRP_SQLquerysizeof(query), "SELECT SQLID FROM characters WHERE CharName = '%e'",target);

? ? ? ? ? ? 
mysql_tquery(MHRP_SQLquery"OnWhoIsCharacter""is"playeridtarget);

? ? ? ? }



? ? ? ? 
// whois chrid subcmd

? ? ? ? if(strmatch(subcmd"chrid"))

? ? ? ? {



? ? ? ? }



? ? ? ? 
// whois account subcmd

? ? ? ? if(strmatch(subcmd"account"))

? ? ? ? {

? ? ? ? ? ??

? ? ? ? }



? ? ? ? 
// whois sqlid subcmd

? ? ? ? if(strmatch(subcmd"sqlid"))

? ? ? ? {

? ? ? ? ? ??

? ? ? ? }



? ? ? ? 
// if no strmatch

? ? ? ? else return SendClientMessage(playeridCOLOR_ERROR"That subcommand does not exist.");

? ? }



? ? else return 
SendClientMessage(playerid,COLOR_ERROR,"You do not have the required access to execute this command.");



? ? return 
1;

}



forward OnWhoIsCharacter(playeridtarget[]);

public 
OnWhoIsCharacter(playeridtarget[])

{

? ? if(
cache_num_rows() != 1)

? ? ? ? return 
SendClientMessage(playeridCOLOR_ERROR"That character does not exist.");



? ? new 
targetid;

? ? 
cache_get_value_name_int(0"SQLID"targetid);



? ? 
mysql_format(MHRP_SQLquerysizeof(query), "SELECT CHRID, CharName, Level FROM characters WHERE SQLID = %d LIMIT 3"targetid);

? ? 
mysql_tquery(MHRP_SQLquery"OnWhoIsCharacterProcess""ii"playeridtargetid);

? ? return 
1;

}



forward OnWhoIsCharacterProcess(playeridtargetid);

public 
OnWhoIsCharacterProcess(playeridtargetid)

{

? ? new 
str[500], C_IDC_Name[MAX_PLAYER_NAME], C_LVL;

? ? for( new 
id 0id cache_num_rows(); id)

? ? {

? ? ? ? 
cache_get_value_name_int(id"CHRID"C_ID);

? ? ? ? 
cache_get_value_name(id"CharName"C_Name);

? ? ? ? 
cache_get_value_name_int(id"Level"C_LVL);



? ? ? ? 
format(strsizeof(str), "%d %s %d\n"C_IDC_NameC_LVL);

? ? ? ? 
SendClientMessage(playeridstr);

? ? }



? ? new 
query[250];

? ? 
mysql_format(MHRP_SQLquerysizeof(query), "SELECT Username FROM accounts WHERE SQLID = %d"targetid);

? ? 
mysql_tquery(MHRP_SQLquery);



? ? new 
A_Name[MAX_PLAYER_NAME];

? ? 
cache_get_value_name(0"Username"A_Name[24]);

? ? return 
1;


  Reply
#2
"SELECT c.SQLID, c.CHRID, c.CharName, c.Level, a.Username FROM characters c LEFT JOIN accounts a ON c.SQLID = a.SQLID

WHERE c.SQLID = %d"
  Reply
#3
(2019-04-17, 07:33 PM)mr_sacrimoni Wrote: "SELECT c.SQLID, c.CHRID, c.CharName, c.Level, a.Username FROM characters c LEFT JOIN accounts a ON c.SQLID = a.SQLID

? ?WHERE c.SQLID = %d"



Thanks a lot, I managed to get it working now!
  Reply


Forum Jump: