Help Convert cmd
#1

tmp = strtok(cmdtext, idx);
if(!strlen(tmp))


i need help with them texes

Example:
Код:
	if(strcmp(cmd, "/givecookie", true) == 0)
	{
        if(IsPlayerConnected(playerid))
        {
            if(PlayerInfo[playerid][pAdmin] < 4)
            {
            	SendClientMessage(playerid, COLOR_GRAD1, "   You are not authorized to use that command !");
				return 1;
			}
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp))
			{
				SendClientMessage(playerid, COLOR_WHITE, "USAGE: /givecookie [playerid/PartOfName] [reason]");
				return 1;
			}
			giveplayerid = ReturnUser(tmp);
			if(IsPlayerConnected(giveplayerid))
			{
			    if(giveplayerid != INVALID_PLAYER_ID)
			    {
					new length = strlen(cmdtext);
					while ((idx < length) && (cmdtext[idx] <= ' '))
					{
						idx++;
					}
					new offset = idx;
					new result[64];
					while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
					{
						result[idx - offset] = cmdtext[idx];
						idx++;
					}
					result[idx - offset] = EOS;
					if(!strlen(result))
					{
						SendClientMessage(playerid, COLOR_WHITE, "USAGE: /givecookie [playerid/PartOfName] [reason]");
						return 1;
					}
					PlayerInfo[giveplayerid][pCookies] += 1;
					format(string, sizeof(string), "AdmCmd: %s has been given a cookie by %s, reason: %s", PlayerName(giveplayerid), PlayerName(playerid), (result));
					SendClientMessageToAll(COLOR_LIGHTRED, string);
			    }
			}
            else
			{
  				SendClientMessage(playerid, COLOR_GREY, "   That player is Offline !");
  				return 1;
			}
        }
        return 1;
	}

How to convert like this new length = strlen(cmdtext);
or this

tmp = strtok(cmdtext, idx);
if(!strlen(tmp))



HOW while ((idx < length) && (cmdtext[idx] <= ' '))
Reply
#2

This can be more easy using sscanf and ZCMD.



pawn Код:
CMD:givecookie ( playerid , params [] )
{
    if ( !PlayerInfo [ playerid ] [ pAdmin ] < 4 ) return SendClientMessage ( playerind , COLOR_GRAD1 , "Your are not authorizes to use that command!" ) ;
    new ID , Str [ 128 ] ;
    if ( !IsPlayerConnected ( ID ) ) return SendClientMessage ( playerid , -1 , "Invalid Player ID" ) ;
    if ( sscanf ( params , "us[128]" , ID , Str ) ) return SendClientMessage ( playerid , -1 , "Usage : /givecookie [ID] [Reason]" ) ;
    else
    {
    new pName [ MAX_PLAYER_NAME ] , vName [ MAX_PLAYER_NAME ] , string [ 128 ] ;
    GetPlayerName ( playerid , pName , MAX_PLAYER_NAME ) ;
    GetPlayerName ( ID , vName , MAX_PLAYER_NAME ) ;
    PlayerInfo [ giveplayerid ][ pCookies ] += 1;
    format ( string , 128 , "AdmCmd: %s has been given a cookie by %s, reason: %s" , pName , vName , Str );
    SendClientMessageToAll ( -1 , string ) ;
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)