help me for command :((
#1

Код:
CMD:makeadmin(playerid, params[])
{
	new para1,level,string[256], giveplayer[MAX_PLAYER_NAME],sendername[MAX_PLAYER_NAME],idx;
	new tmp[256];
	if(IsPlayerConnected(playerid)) {
		if (sscanf(params, "us", para1, level)) { SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /makeadmin [playerid/PartOfName] [level(1-3)]"); return 1; }
		para1 = ReturnUser(tmp);
		level = strval(tmp);
        tmp = strtok(params, idx);
		if (PlayerInfo[playerid][pAdmin] >= 1337) {
	        if(IsPlayerConnected(para1)) {
			    if(para1 != INVALID_PLAYER_ID) {
					GetPlayerName(para1, giveplayer, sizeof(giveplayer));
					GetPlayerName(playerid, sendername, sizeof(sendername));
					PlayerInfo[para1][pAdmin] = level;
					printf("AdmCmd: %s has promoted %s to a level %d admin.", sendername, giveplayer, level);
					format(string, sizeof(string), "   You have been promoted to a level %d admin by %s", level, sendername);
					SendClientMessage(para1, COLOR_LIGHTBLUE, string);
					format(string, sizeof(string), "   You have promoted %s to a level %d admin.", giveplayer,level);
					SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
		        }
			}
		}
		else { SendClientMessage(playerid, COLOR_GRAD1, "   you are not authorized to use that command!"); }
	}
	return 1;
}
So, after writing /makeadmin extrike 1338 server crashes in a few seconds, I do not know what to do: |
Reply
#2

Instead of putting their name "extrike" try putting their ID?
Reply
#3

pawn Код:
CMD:makeadmin(playerid, params[])
{
    new para1,level,string[128], giveplayer[MAX_PLAYER_NAME],sendername[MAX_PLAYER_NAME];
    if(IsPlayerConnected(playerid)) {
        if (sscanf(params, "ui", para1, level)) { SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /makeadmin [playerid/PartOfName] [level(1-3)]"); return 1; }
        if (PlayerInfo[playerid][pAdmin] >= 1337) {
            if(IsPlayerConnected(para1)) {
                if(para1 != INVALID_PLAYER_ID) {
                    GetPlayerName(para1, giveplayer, sizeof(giveplayer));
                    GetPlayerName(playerid, sendername, sizeof(sendername));
                    PlayerInfo[para1][pAdmin] = level;
                    printf("AdmCmd: %s has promoted %s to a level %d admin.", sendername, giveplayer, level);
                    format(string, sizeof(string), "   You have been promoted to a level %d admin by %s", level, sendername);
                    SendClientMessage(para1, COLOR_LIGHTBLUE, string);
                    format(string, sizeof(string), "   You have promoted %s to a level %d admin.", giveplayer,level);
                    SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
                }
            }
        }
        else { SendClientMessage(playerid, COLOR_GRAD1, "   you are not authorized to use that command!"); }
    }
    return 1;
}
EDIT: sscanf should be "ui"
Reply
#4

Whats the difference?
Reply
#5

well ..
....
Reply
#6

Remove those:
pawn Код:
para1 = ReturnUser(tmp);
level = strval(tmp);
tmp = strtok(params, idx);
Why you use string here?
pawn Код:
if (sscanf(params, "us", para1, level)) { SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /makeadmin [playerid/PartOfName] [level(1-3)]"); return 1; }
Try this:
pawn Код:
if (sscanf(params, "ui", para1, level)) { SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /makeadmin [playerid/PartOfName] [level(1-3)]"); return 1; }
Reply
#7

pawn Код:
CMD:makeadmin(playerid, params[])
{
    if (PlayerInfo[playerid][pAdmin] >= 1337) {
        new para1,level;

        if (sscanf(params, "ud", para1, level)) {
            SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /makeadmin [playerid/PartOfName] [level(1-3)]");
            return 1;
        }
   
        new string[128], giveplayer[MAX_PLAYER_NAME],sendername[MAX_PLAYER_NAME];
        GetPlayerName(para1, giveplayer, sizeof(giveplayer));
        GetPlayerName(playerid, sendername, sizeof(sendername));
       
        PlayerInfo[para1][pAdmin] = level;
       
        printf("AdmCmd: %s has promoted %s to a level %d admin.", sendername, giveplayer, level);
       
        format(string, sizeof(string), "   You have been promoted to a level %d admin by %s", level, sendername);
        SendClientMessage(para1, COLOR_LIGHTBLUE, string);
       
        format(string, sizeof(string), "   You have promoted %s to a level %d admin.", giveplayer,level);
        SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
    } else {
        SendClientMessage(playerid, COLOR_GRAD1, "   you are not authorized to use that command!");
    }
   
    return 1;
}
You had a ton of useless if statements in your code. Try and think logically when writing commands. If a player is sending a command, obviously they are connected. No need to check for things like that.
Reply
#8

Quote:
Originally Posted by samgreen
Посмотреть сообщение
You had a ton of useless if statements in your code. Try and think logically when writing commands. If a player is sending a command, obviously they are connected. No need to check for things like that.
You should check if the targetid is connected and return a message: This player is not connected.
Reply
#9

Quote:
Originally Posted by Mike_Peterson
Посмотреть сообщение
You should check if the targetid is connected and return a message: This player is not connected.
Unnecessary, sscanf already verifies the name / playerid.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)