COMMAND:makepremium(playerid, params[]) { if(IsPlayerAdmin(playerid)) { if(IsPlayerConnected(playerid)) { new playerfile[128], pname[MAX_PLAYER_NAME]; GetPlayerName(playerid, pname, sizeof(pname)); format(playerfile, sizeof(playerfile), "Premium/Users/%s.ini",pname); if(dini_Exists(playerfile)) return dini_IntSet(playerfile, "Level", 1); } else SendClientMessage(playerid, red, "Error: You must be an Admin to use that command."); } return 1; }
new targetID; if(sscanf(params, "u", targetID)) { //the admin didn't respect the syntax (he didn't write [/makepremium <player>]) } else { //a value has been set to the targetID variable, but it can be either valid (player found) or invalid (player not found) if(!IsPlayerConnected(targetID)) { //target player is not connected } else { //target player is connected and ready to receive the Premium status, insert all your messages and stuff here } }
I didn't got what you want to do . You said that this commands wont work like /makepremium ID and it's working only if the person who wants premium have to do the command ?
|
You have to extract the "user" param from the "params" string. For this, since you're already using ZCMD, I'd recommend installing (or using, if you have already installed it) SSCANF: https://sampforum.blast.hk/showthread.php?tid=570927 .
Use the "u" specifier, so you'll get something like this: Код:
new targetID; if(sscanf(params, "u", targetID)) { //the admin didn't respect the syntax (he didn't write [/makepremium <player>]) } else { //a value has been set to the targetID variable, but it can be either valid (player found) or invalid (player not found) if(!IsPlayerConnected(targetID)) { //target player is not connected } else { //target player is connected and ready to receive the Premium status, insert all your messages and stuff here } } Also, some off-topic note: saving data in files (dini) is outdated, consider moving to a database saving system. |
COMMAND:makepremium(playerid, params[]) { if(IsPlayerAdmin(playerid)) { if(IsPlayerConnected(playerid)) { new targetID; if(sscanf(params, "u", targetID)) { SendClientMessage(playerid, red, "Error: You must enter [/makepremium <player>])"); } else { if(!IsPlayerConnected(targetID)) { SendClientMessage(playerid, red, "Error: User is not online!"); } else { new playerfile[128], pname[MAX_PLAYER_NAME]; GetPlayerName(playerid, pname, sizeof(pname)); format(playerfile, sizeof(playerfile), "Premium/Users/%s.ini",pname); if(dini_Exists(playerfile)) return dini_IntSet(playerfile, "Level", 1); else SendClientMessage(playerid, red, "Error: You must be an Admin to use that command."); } } } } return 1; }
COMMAND:makepremium(playerid, params[]) { if(!IsPlayerConnected(playerid)) return 1; if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, red, "Error: You must be an Admin to use that command."); new targetID; if(sscanf(params, "u", targetID)) return SendClientMessage(playerid, red, "Error: Syntax error."); if(!IsPlayerConnected(targetID)) return SendClientMessage(playerid, red, "Error: Player not connected."); new playerfile[128], pname[MAX_PLAYER_NAME]; GetPlayerName(targetID, pname, sizeof(pname)); format(playerfile, sizeof(playerfile), "Premium/Users/%s.ini", pname); if(dini_Exists(playerfile)) return dini_IntSet(playerfile, "Level", 1); SendClientMessage(playerid, -1, "You have given Premium to a player"); SendClientMessage(targetID, -1, "You have received Premium from an Admin."); return 1; }
Here you go. I've added only the basic stuff, you can format the strings before sending them so you can include the target player name in the message sent to the admin, for example.
Код:
COMMAND:makepremium(playerid, params[]) { if(!IsPlayerConnected(playerid)) return 1; if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, red, "Error: You must be an Admin to use that command."); new targetID; if(sscanf(params, "u", targetID)) return SendClientMessage(playerid, red, "Error: Syntax error."); if(!IsPlayerConnected(targetID)) return SendClientMessage(playerid, red, "Error: Player not connected."); new playerfile[128], pname[MAX_PLAYER_NAME]; GetPlayerName(targetID, pname, sizeof(pname)); format(playerfile, sizeof(playerfile), "Premium/Users/%s.ini", pname); if(dini_Exists(playerfile)) return dini_IntSet(playerfile, "Level", 1); SendClientMessage(playerid, -1, "You have given Premium to a player"); SendClientMessage(targetID, -1, "You have received Premium from an Admin."); return 1; } |
new string[64], pname[24]; GetPlayerName(playerid, pname, sizeof(pname)); format(string, sizeof(string), "My name is %s", pname); SendClientMessage(playerid, -1, string);
The code you posted should work too.
To include variables in strings (such as player names), use the "format" function: https://sampwiki.blast.hk/wiki/Format Код:
new string[64], pname[24]; GetPlayerName(playerid, pname, sizeof(pname)); format(string, sizeof(string), "My name is %s", pname); SendClientMessage(playerid, -1, string); |
COMMAND:makepremium(playerid, params[]) { if(!IsPlayerConnected(playerid)) return 1; if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, red, "Error: You must be an Admin to use that command."); new targetID; if(sscanf(params, "u", targetID)) return SendClientMessage(playerid, red, "Error: Syntax error."); if(!IsPlayerConnected(targetID)) return SendClientMessage(playerid, red, "Error: Player not connected."); new playerfile[128], pname[MAX_PLAYER_NAME]; GetPlayerName(targetID, pname, sizeof(pname)); format(playerfile, sizeof(playerfile), "Premium/Users/%s.ini", pname); if(dini_Exists(playerfile)) return dini_IntSet(playerfile, "Level", 1); SendClientMessage(playerid, -1, "You have given Premium to a player"); new adminname[128], pname2[24]; GetPlayerName(playerid, pname2, sizeof(pname2)); format(adminname,sizeof(adminname),"You have received Premium from Admin %s", pname2); SendClientMessage(targetID, COLOR_YELLOW, adminname); return 1; }