[Command Help] sscanff optional user + zcmd -
jordy.kiesebrink - 07.05.2013
Dear users,
I have a question for you, I am working on a server and i'm stuck with making a command with optional paraments. I work with the zcmd proccesor and sscanf currently and I would like to make some commands with a double function.
For example I want to have a /nos command wich I already made but I want it so that a player types /nos it will give the playerid nos on his vehicle but if the player types /nos [playerid] it gives the enetered playerid (the targetid) nos on his vehcile.
so far so good this is my /nos command, now I can copy this and make a /givenos and change the playerid into a targetid but this is not what i want!
Becouse I know sscanf does have the optional parameters called "U" but I am stuck with setting this on a command becouse it needs a switch with the AddVehicleComponent I guess becouse when the player does not give a playerid after the /nos it needs to set the AddVehicleComponent on the playerid, but when they give a targetid it needs to add a AddVehicleComponent on the target
pawn Код:
COMMAND:nos(playerid,params[]) {
if(CheckARank(playerid, 4, 4)) { //nothing special this is my admin check for the admin script im working on.
if(IsPlayerInAnyVehicle(playerid)){ //checks if the player id is in a vehicle
AddVehicleComponent(GetPlayerVehicleID(playerid), 1010); //adds the nos on the vehicle
SendClientMessage(playerid, COLOR_GREEN, "(SUCCES!) Succesfully installed Nitro x10"); //send a message when the nos is added
} else {
SendClientMessage(playerid, COLOR_RED, "(ERROR!) You can not attach nitro on your player, you need to be in a vehicle!"); //send a message when the player is not in a vehicle
}
}
return 1;
}
I hope you guys understand what I mean and I hope you could help me.
Kind regarts Jordy
Re: [Command Help] sscanff optional user + zcmd -
Babul - 07.05.2013
hm.. try
pawn Код:
COMMAND:nos(playerid,params[]) {
new targetid;
if(!sscanf(params,"U("#playerid")",targetid))
{
if(CheckARank(playerid, 4, 4)) { //nothing special this is my admin check for the admin script im working on.
if(IsPlayerInAnyVehicle(targetid)){ //checks if the player id is in a vehicle
AddVehicleComponent(GetPlayerVehicleID(targetid), 1010); //adds the nos on the vehicle
SendClientMessage(playerid, COLOR_GREEN, "(SUCCES!) Succesfully installed Nitro x10"); //send a message when the nos is added
} else {
SendClientMessage(playerid, COLOR_RED, "(ERROR!) You can not attach nitro on your player, you need to be in a vehicle!"); //send a message when the player is not in a vehicle
}
}
}
return 1;
}
...also change the message, its not always "you" anymore
Re: [Command Help] sscanff optional user + zcmd -
jordy.kiesebrink - 07.05.2013
@Babul Thank you verry much this was indead exactly what I was looking for, do you also know how to make a clientmessage switch then? if the player is using /nos on himself it wil give the message and when a player does /nos on a playerid it will give another message when they are not in a vehicle?
Re: [Command Help] sscanff optional user + zcmd -
jordy.kiesebrink - 07.05.2013
I've tested this and in the first vieuw it seems to work but when I tested it with 3 players I came to the consulsion that when you type /nos it only gives nos on playerid always. I guess this is becouse of the targetid in AddVehicleComponent, now when a playerid is doing /nos it will return targetid 0 for some reason.
Код:
AddVehicleComponent(GetPlayerVehicleID(targetid), 1010);
Do anybody knows a solution for this I think I need a switch when a player does not entered a targetid is needs to do:
"AddVehicleComponent(GetPlayerVehicleID(player id), 1010);"
and when a player does give a targetid it gives
"AddVehicleComponent(GetPlayerVehicleID(target id), 1010);"
Anyone?
Kind regarts Jordy
Re: [Command Help] sscanff optional user + zcmd -
Babul - 07.05.2013
the "U("#playerid")",targetid is supposed to use the playerid as deafult value with no input. WITH an input, the targetid gets replaced by it. therefore the targetid is always the right one - the playerid only should be used to send a confirmation message to the command typer, and maybe an information for the reciever, if he is in a vehicle..
did you add some SendClientMessage with a formatted string to check if the player/targetid is properly set?
concerning your question about which player to send the message: use that check
pawn Код:
if(playerid==targetid)
{
//same player
}
else
{
//different player
}
Re: [Command Help] sscanff optional user + zcmd -
jordy.kiesebrink - 07.05.2013
@babul so you say this must work?
pawn Код:
COMMAND:nos(playerid,params[]) {
new targetid;
if(!sscanf(params,"U("#playerid")",targetid)) {
if(CheckARank(playerid, 4, 4)) {
if (playerid==targetid) {
if(IsPlayerInAnyVehicle(targetid)) {
AddVehicleComponent(GetPlayerVehicleID(targetid), 1010);
SendClientMessage(targetid, COLOR_GREEN, "(SUCCES!) Succesfully installed Nitro x10");
} else {
SendClientMessage(playerid, COLOR_RED, "(ERROR!) You can not attach nitro on your player, the player need to be in a vehicle!");
}
} else {
if(IsPlayerInAnyVehicle(playerid)) {
AddVehicleComponent(GetPlayerVehicleID(playerid), 1010);
SendClientMessage(playerid, COLOR_GREEN, "(SUCCES!) Succesfully installed Nitro x10");
} else {
SendClientMessage(playerid, COLOR_RED, "(ERROR!) You can not attach nitro on your player, you need to be in a vehicle!");
}
}
}
}
return 1;
}
Re: [Command Help] sscanff optional user + zcmd -
UnknownGamer - 07.05.2013
pawn Код:
#include <a_samp>
#include <zcmd>
#include <sscanf2>
#define SCM SendClientMessage
#define COLOR_LIGHTRED 0xFF6347AA
CMD:nos(playerid, params[])
{
new giveplayerid;
if(sscanf(params, "u", giveplayerid)) return SCM(playerid, COLOR_LIGHTRED, "USAGE: /nos [playerid]");
if(CheckARank(playerid, 4, 4))
{
if(playerid==giveplayerid)
{
if(IsPlayerInAnyVehicle(giveplayerid))
{
AddVehicleComponent(GetPlayerVehicleID(giveplayerid), 1010);
SCM(playerid, COLOR_LIGHTRED, "[SERVER]: Succesfully installed Nitro x10!");
}
else
{
SCM(playerid, COLOR_LIGHTRED, "[SERVER]: FAILED!");
}
}
}
return 1;
}
You mean like that?