#1

Hello guys, I'm new here.. i'm asking for some help.. i want to convert 2 commands from strcmp to z_cmd (CMD
I don't have that much knowledge about CMD i used to script with strcmp only.
Here is the first one.


new cmd[64],tmp[64],idx;
cmd = strtok(cmdtext,idx);
if(!strcmp(cmd, "/playergps", true))
{
tmp = strtok(cmdtext,idx);
if(!strlen(tmp)) return SendClientMessage(playerid, 0xFFFFFFAA, "[Tip]: Type /playergps [playerid]");
if(!strcmp(tmp, "off", true))
{
if(HaveGPS[playerid])
{
KillTimer(GPSTimer[playerid]);
HaveGPS[playerid] = false;
GPSTimer[playerid] = 0;
DisablePlayerCheckpoint(playerid);
SendClientMessage(playerid, 0xFFFF00AA, "[Server]: GPS disabled.");
}
else SendClientMessage(playerid, 0xFF0000AA, "[Server]: Your GPS is turned off.");
return 1;
}
if(IsPlayerConnected(strval(tmp)))
{
if(strval(tmp) != playerid)
{
if(HaveGPS[playerid])
{
KillTimer(GPSTimer[playerid]);
HaveGPS[playerid] = false;
GPSTimer[playerid] = 0;
}
GPSTimer[playerid] = SetTimerEx("GPSUpdate", 500, true, "dd", playerid,strval(tmp));
HaveGPS[playerid] = true;
new str[128],nick[24];
GetPlayerName(strval(tmp),nick,24);
format(str,128,"[Server]: GPS enabled. Target: %s (ID: %d).",nick,strval(tmp));
SendClientMessage(playerid, 0xFFFF00AA, str);
}
else SendClientMessage(playerid, 0xFF0000AA, "[Error]: You cant type your own ID.");
}
else SendClientMessage(playerid, 0xFF0000AA, "[Error]: This ID isnt connected.");
return 1;
}

The Second

new index, cmd12[20];
cmd12 = strtok(cmdtext, index);
if (strcmp("/showrules", cmdtext, true, 10) == 0)
{
new tmp12[20];
tmp12 = strtok(cmdtext, index);
if(!strlen(tmp)) return SendClientMessage(playerid, 0xFF0000AA, "[Tip]: Type /showrules <ID>.");
if(!IsAdmin(playerid, 1)) return SendClientMessage(playerid, COLOR_RED, "[Error]: You are not admin.");
if(!IsPlayerConnected(strval(tmp))) return SendClientMessage(playerid, 0xFF0000AA, "[Error]: Player not found.");
new Float,Float:y,Float:z;
PlayerPlaySound(playerid,1133,x,y,z);
new LongString[ 1024 ];
new Str1[ ] =
format( LongString, 1024, "%s%s", Str1 );
ShowPlayerDialog(strval(tmp12), INFO_BOX, DIALOG_STYLE_MSGBOX, " ", LongString, "Agree", "");
SendClientMessage(strval(tmp12), COLOR_WHITE, "[Server]: An admin forced you to read the server rules.");
return 1;
}
Reply
#2

pawn Code:
CMD:playergps(playerid, cmdtext[])
{
    if(isnull(cmdtext) || strlen(cmdtext) > 4) return SendClientMessage(playerid, 0xFFFFFFAA, "[Tip]: Type /playergps [playerid]");
    if(!strcmp(cmdtext, "off", true))
    {
        if(HaveGPS[playerid])
        {
            KillTimer(GPSTimer[playerid]);
            HaveGPS[playerid] = false;
            GPSTimer[playerid] = 0;
            DisablePlayerCheckpoint(playerid);
            SendClientMessage(playerid, 0xFFFF00AA, "[Server]: GPS disabled.");
        }
        else SendClientMessage(playerid, 0xFF0000AA, "[Server]: Your GPS is turned off.");
        return 1;
    }
    new playa = strval(cmdtext);
    if(IsPlayerConnected(playa))
    {
        if(playa != playerid)
        {
            if(HaveGPS[playerid])
            {
                KillTimer(GPSTimer[playerid]);
                HaveGPS[playerid] = false;
                GPSTimer[playerid] = 0;
            }
            GPSTimer[playerid] = SetTimerEx("GPSUpdate", 500, true, "dd", playerid,playa);
            HaveGPS[playerid] = true;
            new str[128],nick[24];
            GetPlayerName(playa,nick,24);
            format(str,128,"[Server]: GPS enabled. Target: %s (ID: %d).",nick,playa);
            SendClientMessage(playerid, 0xFFFF00AA, str);
        }
        else SendClientMessage(playerid, 0xFF0000AA, "[Error]: You cant type your own ID.");
    }
    else SendClientMessage(playerid, 0xFF0000AA, "[Error]: This ID isnt connected.");
    return 1;
}
now you can try convert second cmd
Reply
#3

Thank you!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)