SA-MP Forums Archive
Command - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Command (/showthread.php?tid=218743)



Command - KotoK - 30.01.2011

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;



Re: Command - PeteShag - 31.01.2011

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;
}



Re: Command - Antonio [G-RP] - 31.01.2011

zcmd and sscanf are the way to go.


Re: Command - KotoK - 31.01.2011

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!


Re: Command - JamesC - 31.01.2011

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.


Re: Command - KotoK - 31.01.2011

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;
    }



Re: Command - PeteShag - 31.01.2011

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;
 }