Command
#1

How this should look on zcmd + scanf ?

Код:
if(strcmp(cmd,"/appearance",true) == 0)
	{
    	if(IsPlayerConnected(playerid))
    	{
		GetPlayerName(playerid, sendername, sizeof(sendername));
		new length = strlen(cmdtext);
		while ((idx < length) && (cmdtext[idx] <= ' '))
		{
			idx++;
		}
		new offset = idx;
		new result[128];
		while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
		{
			result[idx - offset] = cmdtext[idx];
			idx++;
		}
		result[idx - offset] = EOS;
		if(!strlen(result))
		{
			SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /appearance [Description]");
			return 1;
		}
        strmid(PlayerInfo[playerid][pApp], result, 0, strlen(result), 255);
    	SendClientMessage(playerid,COLOR_GREY,"You have adjusted your appearance.");
    	return 1;
Reply
#2

Smaller.

pawn Код:
command(appearance, playerid, params[])
{
    new desc[128];
    if(sscanf(params, "s[128]", desc)) return SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /appearance [Description]");
    strmid(PlayerInfo[playerid][pApp], desc, 0, strlen(desc), 255);
    SendClientMessage(playerid,COLOR_GREY,"You have adjusted your appearance.");
    return 1;
}


or

command(appearance, playerid, params[])
{
    if(sscanf(params, "s[128]", params)) return SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /appearance [Description]");
    strmid(PlayerInfo[playerid][pApp], params, 0, strlen(params), 255);
    SendClientMessage(playerid,COLOR_GREY,"You have adjusted your appearance.");
    return 1;
}
Reply
#3

zcmd and sscanf are the way to go.
Reply
#4

Quote:
Originally Posted by PeteShag
Посмотреть сообщение
Smaller.

pawn Код:
command(appearance, playerid, params[])
{
    new desc[128];
    if(sscanf(params, "s[128]", desc)) return SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /appearance [Description]");
    strmid(PlayerInfo[playerid][pApp], desc, 0, strlen(desc), 255);
    SendClientMessage(playerid,COLOR_GREY,"You have adjusted your appearance.");
    return 1;
}
Works fine, thank you!
Reply
#5

You really don't need sscanf if there is only one parameter.

pawn Код:
CMD:appearance( playerid, params[] )
{
    if( !isnull( params ) )
    {
        strcat( PlayerInfo[playerid][pApp], params, sizeof( PlayerInfo[playerid][pApp] ) );
        SendClientMessage(playerid,COLOR_GREY,"You have adjusted your appearance.");
    }
    else
    {
        SendClientMessage( playerid, COLOR_GRAD2, "USAGE: /appearance [Description]");
    }
}
Untested.
Reply
#6

And how about this? Sorry I am kinda dumb at zcmd + sscanf.

pawn Код:
if(strcmp(cmd, "/describe", true) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
            if(gPlayerLogged[playerid] == 0)
            {
                SendClientMessage(playerid, COLOR_GREY, "   You need to login first !");
                return 1;
            }
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp))
            {
                SendClientMessage(playerid, COLOR_WHITE, "HINT: /describe [playerid/PartOfName]");
                return 1;
            }
            giveplayerid = ReturnUser(tmp);
            if(IsPlayerConnected(giveplayerid))
            {
                if(giveplayerid != INVALID_PLAYER_ID)
                {
                    GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
                    format(string, sizeof(string), "%s's appearance:", giveplayer);
                    SendClientMessage(playerid, COLOR_WHITE, string);
                    format(string, sizeof(string), "%s", PlayerInfo[giveplayerid][pApp]);
                    SendClientMessage(playerid, COLOR_PURPLE, string);
                    return 1;
                }
            }
        }
        return 1;
    }
Reply
#7

He/She/It asked for sscanf though.

pawn Код:
command(describe, playerid, params[])
{
    new name[MAX_PLAYER_NAME], id;
    if(gPlayerLogged[playerid] == 0) return SendClientMessage(playerid, COLOR_GREY, "   You need to login first !");
    if(sscanf(params, "u", id)) return SendClientMessage(playerid, COLOR_WHITE, "HINT: /describe [playerid/PartOfName]");
    GetPlayerName(playerid, name, sizeof(name));
    format(string, sizeof(string), "%s's appearance:", name);
    SendClientMessage(playerid, COLOR_WHITE, string);
    format(string, sizeof(string), "%s", PlayerInfo[id][pApp]);
    SendClientMessage(playerid, COLOR_PURPLE, string);
    return 1;
 }
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)