SA-MP Forums Archive
sscanf & zcmd "multi-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)
+--- Thread: sscanf & zcmd "multi-command" (/showthread.php?tid=602265)



sscanf & zcmd "multi-command" - nerovani - 04.03.2016

So I was creating a multi-command using sscanf and zcmd, but it kept getting stuck after the first stage of the command. (After /editveh faction {whateverid} it returns nothing in the IG chat)

This is the code:
Код:
CMD:editveh(playerid, params[])
{
new vehid;
if(sscanf(params, "s[32]", params)) {SendClientMessage(playerid, -1, "/editveh (option) (vehid)"); SendClientMessage(playerid, -1, "{989898}[OPTIONS]: faction | locked"); return 1;}
if(!strcmp(params, "faction", true, 8))
{
	if(sscanf(params, "s[32]i",params,vehid)) return SendClientMessage(playerid, -1, "/editvehicle faction (vehid)");
	SendClientMessage(playerid, -1, "Vehicle successfully updated.");
}
return 1;
}
Any help/suggestions are much appriciated


Re: sscanf & zcmd "multi-command" - CalvinC - 04.03.2016

Replace the sscanf with isnull.

Код:
CMD:editveh(playerid, params[])
{
    new vehid;
    if(isnull(params)) {SendClientMessage(playerid, -1, "/editveh (option) (vehid)"); SendClientMessage(playerid, -1, "{989898}[OPTIONS]: faction | locked"); return 1;}
    if(!strcmp(params, "faction", true, 7))
    {
        if(sscanf(params, "s[32]i",params,vehid)) return SendClientMessage(playerid, -1, "/editvehicle faction (vehid)");
        SendClientMessage(playerid, -1, "Vehicle successfully updated.");
    }
    return 1;
}
If you haven't defined isnull, put this at the top of your script:
Код:
#if !defined isnull
    #define isnull(%1) ((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
#endif



Re: sscanf & zcmd "multi-command" - saffierr - 04.03.2016

It just lacks on the amount of code


Re: sscanf & zcmd "multi-command" - Jefff - 04.03.2016

pawn Код:
CMD:editveh(playerid, params[])
{
    if(isnull(params))
    {
        SendClientMessage(playerid, -1, "/editveh (option) (vehid)");
        SendClientMessage(playerid, -1, "{989898}[OPTIONS]: faction | locked");
        return 1;
    }
    if(!strcmp(params, "faction", true, 7) && (!params[7] || params[7] == ' '))
    {
        new vehid;
        if(sscanf(params[7],"i",vehid)) return SendClientMessage(playerid, -1, "/editvehicle faction (vehid)");
        SendClientMessage(playerid, -1, "Vehicle successfully updated.");
    }
    return 1;
}



Re: sscanf & zcmd "multi-command" - nerovani - 05.03.2016

It works now, thanks.


Re: sscanf & zcmd "multi-command" - ZToPMaN - 05.03.2016

About your sscanf problem, you made "s" as a varible for your vehid, "s" means string which is not id. You can put "u" instead of "s" and try again.


Re: sscanf & zcmd "multi-command" - nerovani - 05.03.2016

Okay, so everything worked great until I added more "sub-commands".
Код:
CMD:editveh(playerid, params[])
{
new vehid,input;
if(isnull(params)) {UsageMessage(playerid, "/editveh [option] [vehid]"); SendClientMessage(playerid, -1, "{989898}[OPTIONS]: faction | locked | rental | job"); return 1;}
new dFile[128];
new fileid = vehid -1;
format(dFile, sizeof(dFile),VEHICLE_FOLDER,fileid);
if(!strcmp(params, "faction", true, 8))
{
	if(sscanf(params, "s[32]ii",params,vehid,input)) return UsageMessage(playerid, "/editveh faction (vehid) (faction)");
	if(!fexist(dFile)) return ErrorMessage(playerid, "That file does not exist!");
	DVehicles[fileid][vFaction] = input;
	SaveVehicle(fileid);
	InfoMessage(playerid, "Vehicle successfully updated.");
}
else if(!strcmp(params, "locked", true, 7))
{
	if(sscanf(params, "s[32]ii",params,vehid,input)) return UsageMessage(playerid, "/editveh locked (vehid) (1 = YES, 0 = NO)");
	if(!fexist(dFile)) return ErrorMessage(playerid, "That file does not exist!");
	DVehicles[fileid][vLocked] = input;
	SaveVehicle(fileid);
	InfoMessage(playerid, "Vehicle successfully updated.");
}
else if(!strcmp(params, "rental", true, 7))
{
	if(sscanf(params, "s[32]ii",params,vehid,input)) return UsageMessage(playerid, "/editveh rental (vehid) (1 = YES, 0 = NO)");
	if(!fexist(dFile)) return ErrorMessage(playerid, "That file does not exist!");
	DVehicles[fileid][vRental] = input;
	SaveVehicle(fileid);
	InfoMessage(playerid, "Vehicle successfully updated.");
}
else if(!strcmp(params, "job", true, 7))
{
	if(sscanf(params, "s[32]ii",params,vehid,input)) return UsageMessage(playerid, "/editveh job (vehid) (jobid)");
	if(!fexist(dFile)) return ErrorMessage(playerid, "That file does not exist!");
	DVehicles[fileid][vJob] = input;
	SaveVehicle(fileid);
	InfoMessage(playerid, "Vehicle successfully updated.");
}
return 1;
}
Everything works except "job" (/editveh job).
Any suggestions?


Re: sscanf & zcmd "multi-command" - Threshold - 05.03.2016

You see that number on the end of strcmp? Yeah, you need to change that depending on the length of the string you are comparing. In this case "job" is 3 letters, so it should be 3, not 7. Check the wiki page for more info...


Re: sscanf & zcmd "multi-command" - nerovani - 05.03.2016

Thanks, it works.