Convert to if strcmp instead of ZCMD
#1

Can anyone convert this to if strcmp?? do it and you'll get a reputation

Код:
CMD:addpickup(playerid, params[])
{
	new ModelID, Type;
	if(unformat(params,"dd",ModelID,Type)) return SendClientMessage(playerid, 0xFFFFFF,"USAGE: /AddPickup < Pickup ID > < Type >");

	new Float:X,Float:Y,Float:Z;
	GetPlayerPos(playerid,X,Y,Z);
	CreateSavedPickup(ModelID,Type,X,Y,Z);
	new Msg[128];
	format(Msg,sizeof(Msg),"Pickup Successfully Created. (Model: %d) (Type: %d)",ModelID,Type);
	SendClientMessage(playerid, 0xFFFFFF,Msg);
	return 1;
}

CMD:removepickup(playerid, params[])
{
	new PickupID;
	if(unformat(params,"d",PickupID)) return SendClientMessage(playerid, 0xFFFFFF,"USAGE: /RemovePickup < Pickup ID >");
	if(!IsValidDynamicPickup(pInfo[PickupID][PID])) return SendClientMessage(playerid, 0xFFFFFFF, "ERROR: Pickup Does Not Exist!");

	DestroyDynamicPickup(pInfo[PickupID][PID]);

	format(pFile, sizeof(pFile), PICKUPFILE, PickupID);
	if(dini_Exists(pFile))
	{
		dini_Remove(pFile);
		dini_IntSet(pIDFile, "Total Pickups:", dini_Int(pIDFile, "Total Pickups:")-1);
	}

	new Msg[128];
	format(Msg,sizeof(Msg),"Pickup ID: %d Was 1Destroyed!",PickupID);
	SendClientMessage(playerid, 0xFFFFFFF,Msg);
	return 1;
}
THANK YOU, HELP ME AND YOU'LL GET A REPUTATION!.
Reply
#2

Have you ever looked up why people use command processors like ZCMD and YCMD instaid of strcmp?

Hell no, if anyone is willing to convert these commands to strcmp they deserve a slap in the face.
Reply
#3

For first, why do you want to change that, ZCMD is more faster than strcmp..
Whatever..

You need this function:
pawn Код:
strtok(const string[], &index)
{
    new length = strlen(string);
    while ((index < length) && (string[index] <= ' '))
    {
        index++;
    }
 
    new offset = index;
    new result[20];
    while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
    {
        result[index - offset] = string[index];
        index++;
    }
    result[index - offset] = EOS;
    return result;
}
Add this to the OnPlayerCommandText callback(at the beginning of the callback):
pawn Код:
new cmd[128], idx;
cmd = strtok(cmdtext, idx);
The commands would be like this:
pawn Код:
if(!strcmp(cmd, "/addpickup", true))
{
    new tmp[128], pID, tID;
    tmp = strtok(cmdtext, idx);
    if(!strlen(tmp)) return SendClientMessage(playerid, 0xFFFFFF,"USAGE: /AddPickup < Pickup ID > < Type >");
    pID = strval(tmp);
   
    tmp = strtok(cmdtext, idx);
    if(!strlen(tmp)) return SendClientMessage(playerid, 0xFFFFFF,"USAGE: /AddPickup < Pickup ID > < Type >");
    tID = strval(tmp);
   
    new Float:X, Float:Y, Float:Z;
    GetPlayerPos(playerid, X, Y, Z);
    CreateSavedPickup(pID, tID, X, Y, Z);
    new Msg[128];
    format(Msg, sizeof Msg, "Pickup Successfully Created. (Model: %d) (Type: %d)", pID, tID);
    SendClientMessage(playerid, 0xFFFFFF, Msg);
    return 1;
}
pawn Код:
if(!strcmp(cmd, "/removepickup", true))
{
    new tmp[128], PickupID;
    if(!strlen(tmp)) return SendClientMessage(playerid, 0xFFFFFF,"USAGE: /RemovePickup < Pickup ID >");
    PickupID = strval(tmp);
   
    if(!IsValidDynamicPickup(pInfo[PickupID][PID])) return SendClientMessage(playerid, 0xFFFFFFF, "ERROR: Pickup Does Not Exist!");

    DestroyDynamicPickup(pInfo[PickupID][PID]);

    format(pFile, sizeof(pFile), PICKUPFILE, PickupID);
    if(dini_Exists(pFile))
    {
        dini_Remove(pFile);
        dini_IntSet(pIDFile, "Total Pickups:", dini_Int(pIDFile, "Total Pickups:")-1);
    }

    new Msg[128];
    format(Msg,sizeof(Msg),"Pickup ID: %d Was 1Destroyed!",PickupID);
    SendClientMessage(playerid, 0xFFFFFFF,Msg);
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)