Sscanf question. - 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 question. (
/showthread.php?tid=544693)
Sscanf question. -
Kebab- - 03.11.2014
Hello community,
I was wondering how am I able to place a sscanf inside a sscanf?
I want to be able to do:
/vehicle 21 delete
Message Are you sure you want to delete your car? Then say "/vehicle 21 delete yes"
/vehicle 21 delete yes
So basically 21 is the vehicle ID, delete is the action and yes is to confirm their action. How am I able to do this?
Re: Sscanf question. -
HY - 03.11.2014
pawn Код:
CMD:vehicle(playerid,params[])
{
SendClientMessage(playerid, -1, "Are you sure you want to delete this vehicle? /Vehicle [ID] Delete !");
return 1;
}
CMD:vehicled(playerid,params[])
{
new veh;
veh = GetPlayerVehicleID(playerid);
if(sscanf(params,"ii", veh)) return SendClientMessage(playerid,-1,"{FF0000}USAGE: {15FF00}/vehicle [ID] Delete Yes");
DestroyVehicle(veh);
return 1;
}
Re: Sscanf question. -
Rudy_ - 03.11.2014
Instead, When you show the Message
'Are you sure you want to delete your car? Type /Yes'
confirmdel[playerid] = 1;
pawn Код:
CMD:yes(playerid, params[])
{
if(confimdel[playerid] == 1)
{
//Delete the car
}
else SendClientMessage(playerid, -1, "NO");
return 1;
}
Re: Sscanf question. -
Kebab- - 03.11.2014
I want it to be a single command. I don't want /yes. I don't think you understand me.
When you type in "/vehicle delete 12" you get a message saying that you need to confirm it by typing "/vehicle delete 12 yes".
Re: Sscanf question. -
Kebab- - 03.11.2014
Ignore post.
Re: Sscanf question. -
Stinged - 03.11.2014
Should work, not tested.
pawn Код:
CMD:vehicle(playerid, params[])
{
new id, action[12];
if (!sscanf(params, "is[12]", id, action))
{
if (!strcmp(action, "delete", true))
{
new yn[4];
if (!sscanf(params, "is[12]s[4]"))
{
if (!strcmp(yn, "yes", true))
{
// entered /vehcile id delete yes
}
}
else
{
SendClientMessage(playerid, -1, "Are you sure you want to delete your car? If so, enter /vehicle [id] delete yes");
}
}
}
else
{
SendClientMessage(playerid, -1, "Usage: /vehicle [id] [action]");
}
return 1;
}
EDIT: I was posting this before you posted the last reply.
Re: Sscanf question. -
Kebab- - 03.11.2014
Hello, still getting an issue. First part work, just the seconnd part doesn't. Here's my code:
Код:
CMD:vehicle(playerid, params[]) {
if(sscanf(params, "is[20]", vehicleID, name))
{
printf("/vehicle [vehicleid] [function");
printf("functions available: delete");
return 1;
}
if(strcmp(name, "delete", true) == 0)
{
new verify[3];
if(sscanf(params, "{is[20]}s[3]", verify))
{
printf("verify please type /vehicle ID delete yes");
return 1;
}
if(strcmp(verify, "yes", true) == 0)
{
printf("car should get deleted.");
}
}
return 1;
}
Re: Sscanf question. -
Kebab- - 03.11.2014
Quote:
Originally Posted by ******
As it is, "name" will contain the whole of the rest of the string. Do something like this:
pawn Код:
sscanf(params, "is[20]S(no)[20]", vehicleID, name, confirm)
That makes the confirmation optional, with a default of "no", so if you do:
pawn Код:
if (strcmp(confirm, "yes") == 0)
Then you know they must have typed the extra bit.
|
Ah, now I understand. Thanks alot!