dcmd to zcmd convert
#1

How can i convert example this to zcmd + sscanf2

example:

Quote:

dcmd_setlaps(playerid,params[])
{
new tmp[256], idx;
tmp = strtok(params, idx);
if(!strlen(tmp) || strval(tmp) <= 0)
{
SendClientMessage(playerid, COLOR_WHITE, "USAGE: /setlaps [amount of laps (min: 1)]");
return 1;
}
if(RaceBuilders[playerid] != 0)
{
Blaps[b(playerid)] = strval(tmp);
format(tmp,sizeof(tmp),"Amount of laps set to %d.", Blaps[b(playerid)]);
SendClientMessage(playerid, COLOR_GREEN, tmp);
return 1;
}
if(RaceAdmin == 1 && IsNotAdmin(playerid)) return 1;
if(RaceActive == 1 || RaceStart == 1) SendClientMessage(playerid, COLOR_RED, "Race already in progress!");
else if(LCurrentCheckpoint == 0) SendClientMessage(playerid, COLOR_YELLOW, "No race loaded.");
else
{
Racelaps=strval(tmp);
format(tmp,sizeof(tmp),"Amount of laps set to %d for current race.", Racelaps);
SendClientMessage(playerid, COLOR_GREEN, tmp);
}
return 1;
}

Reply
#2

Try this?

pawn Code:
CMD:setlaps(playerid,params[])
{
new tmp[256], idx;
tmp = strtok(params, idx);
if(!strlen(tmp) || strval(tmp) <= 0)
{
SendClientMessage(playerid, COLOR_WHITE, "USAGE: /setlaps [amount of laps (min: 1)]");
return 1;
}
if(RaceBuilders[playerid] != 0)
{
Blaps[b(playerid)] = strval(tmp);
format(tmp,sizeof(tmp),"Amount of laps set to %d.", Blaps[b(playerid)]);
SendClientMessage(playerid, COLOR_GREEN, tmp);
return 1;
}
if(RaceAdmin == 1 && IsNotAdmin(playerid)) return 1;
if(RaceActive == 1 || RaceStart == 1) SendClientMessage(playerid, COLOR_RED, "Race already in progress!");
else if(LCurrentCheckpoint == 0) SendClientMessage(playerid, COLOR_YELLOW, "No race loaded.");
else
{
Racelaps=strval(tmp);
format(tmp,sizeof(tmp),"Amount of laps set to %d for current race.", Racelaps);
SendClientMessage(playerid, COLOR_GREEN, tmp);
}
return 1;
}
And don't forget to include zcmd #include <zcmd> under a_samp
Reply
#3

Untesed:

EDIT: @PlayHard , you didn't even add sscanf, and it is still using strtok and tmp ...

pawn Code:
CMD:setlaps(playerid,params[])
{
    new laps, string[128];
   
    if(sscanf(params,"d",laps)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /setlaps [amount of laps (min: 1)]");

    if(RaceBuilders[playerid] != 0)
    {
        format(string,128,"Amount of laps set to %d.", laps);
        SendClientMessage(playerid, COLOR_GREEN, string);
        return 1;
    }
    if(RaceAdmin == 1 && IsNotAdmin(playerid)) return 1;
    if(RaceActive == 1 || RaceStart == 1) return SendClientMessage(playerid, COLOR_RED, "Race already in progress!");
    if(LCurrentCheckpoint == 0) return SendClientMessage(playerid, COLOR_YELLOW, "No race loaded.");
   
    Racelaps = laps;
    format(string,128,"Amount of laps set to %d for current race.", Racelaps);
    SendClientMessage(playerid, COLOR_GREEN, string);
    return 1;
}
Reply
#4

Quote:
Originally Posted by grand.Theft.Otto
View Post
Untesed:

EDIT: @PlayHard , you didn't even add sscanf, and it is still using strtok and tmp ...

pawn Code:
CMD:setlaps(playerid,params[])
{
    new laps, string[128];
   
    if(sscanf(params,"d",laps)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /setlaps [amount of laps (min: 1)]");

    if(RaceBuilders[playerid] != 0)
    {
        format(string,128,"Amount of laps set to %d.", laps);
        SendClientMessage(playerid, COLOR_GREEN, string);
        return 1;
    }
    if(RaceAdmin == 1 && IsNotAdmin(playerid)) return 1;
    if(RaceActive == 1 || RaceStart == 1) return SendClientMessage(playerid, COLOR_RED, "Race already in progress!");
    if(LCurrentCheckpoint == 0) return SendClientMessage(playerid, COLOR_YELLOW, "No race loaded.");
   
    Racelaps = laps;
    format(string,128,"Amount of laps set to %d for current race.", Racelaps);
    SendClientMessage(playerid, COLOR_GREEN, string);
    return 1;
}
Yeah, lol.. Excuse me. Still a beginner and I still don't know what's the different between those guys(And what they're for LOL).
Reply
#5

it complines without error but in-game it dont works
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)