SA-MP Forums Archive
Params Not Detected When Using 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: Params Not Detected When Using Command (/showthread.php?tid=320696)



Params Not Detected When Using Command - lewismichaelbbc - 24.02.2012

Everything compiles correctly, but when in-game this command is not detecting the params and just displays USAGE: /addv [dealerid] [model] [color1] [color2] [price] to the people who type the command.

How can i fix this?
Thanks

Here is the code:

pawn Код:
if(strcmp(cmdtext, "/addv", true) == 0)
    {
        new params[128];
        if(!IsAdmin(playerid, 1)) SendClientMessage(playerid, COLOR_RED, "You are not admin!");
        if(!IsPlayerSpawned(playerid)) return SendClientMessage(playerid, COLOR_RED, "You can't use this command now!");
        new model[32], modelid, dealerid, color1, color2, price;
        if(sscanf(params, "dsddd", dealerid, model, color1, color2, price))
            return SendClientMessage(playerid, COLOR_GREY, "USAGE: /addv [dealerid] [model] [color1] [color2] [price]");
        if(!IsValidDealership(dealerid)) return SendClientMessage(playerid, COLOR_RED, "Invalid dealerid!");
        if(IsNumeric(model)) modelid = strval(model);
        else modelid = GetVehicleModelIDFromName(model);
        if(modelid < 400 || modelid > 611) return SendClientMessage(playerid, COLOR_RED, "Invalid model ID!");
        if(color1 < 0 || color2 < 0) return SendClientMessage(playerid, COLOR_RED, "Invalid color!");
        if(price < 0) return SendClientMessage(playerid, COLOR_RED, "Invalid price!");
        new Float:X, Float:Y, Float:Z, Float:angle;
        GetPlayerPos(playerid, X, Y, Z);
        GetPlayerFacingAngle(playerid, angle);
        X += floatmul(floatsin(-angle, degrees), 4.0);
        Y += floatmul(floatcos(-angle, degrees), 4.0);
        for(new i=1; i < MAX_DVEHICLES; i++)
        {
            if(!VehicleCreated[i])
            {
                new msg[128];
                VehicleCreated[i] = VEHICLE_DEALERSHIP;
                VehicleModel[i] = modelid;
                VehiclePos[i][0] = X;
                VehiclePos[i][1] = Y;
                VehiclePos[i][2] = Z;
                VehiclePos[i][3] = angle+90.0;
                VehicleColor[i][0] = color1;
                VehicleColor[i][1] = color2;
                VehicleInterior[i] = GetPlayerInterior(playerid);
                VehicleWorld[i] = GetPlayerVirtualWorld(playerid);
                VehicleValue[i] = price;
                valstr(VehicleOwner[i], dealerid);
                VehicleNumberPlate[i] = DEFAULT_NUMBER_PLATE;
                for(new d=0; d < sizeof(VehicleTrunk[]); d++)
                {
                    VehicleTrunk[i][d][0] = 0;
                    VehicleTrunk[i][d][1] = 0;
                }
                for(new d=0; d < sizeof(VehicleMods[]); d++)
                {
                    VehicleMods[i][d] = 0;
                }
                VehiclePaintjob[i] = 255;
                UpdateVehicle(i, 0);
                SaveVehicle(i);
                format(msg, sizeof(msg), "Added vehicle id %d to dealerid %d", i, dealerid);
                SendClientMessage(playerid, COLOR_WHITE, msg);
                return 1;
            }
        }
        SendClientMessage(playerid, COLOR_RED, "Can't add any more vehicles!");
        return 1;
    }



Re: Params Not Detected When Using Command - Stylock - 24.02.2012

You should convert that to ZCMD or YCMD, and then it will work better.


Re: Params Not Detected When Using Command - lewismichaelbbc - 24.02.2012

Quote:
Originally Posted by YJIET
Посмотреть сообщение
You should convert that to ZCMD or YCMD, and then it will work better.
Hi, that hasnt answered my question, i didnt ask whats the best format to use. I asked how can i get the params to work. I cannot use ZCMD or YCMD because i use strcmp and dcmd together - using ZCMD just bugs the script.


Re: Params Not Detected When Using Command - iTorran - 24.02.2012

You cant just use

pawn Код:
new params[128];
and expect it to work..
Just convert all your cmds to ZCMD, it will be alot easier.


Re: Params Not Detected When Using Command - Stylock - 24.02.2012

I'm just saying that it's way more efficient than strcmp, especially that you have over 400 cmds in your script.. but oh well, here's the solution for your problem.
pawn Код:
if(strcmp(cmdtext, "/addv", true, 5) == 0)
{
    //code
    new model[32], modelid, dealerid, color1, color2, price;
    if(sscanf(cmdtext[6], "ds[32]ddd", dealerid, model, color1, color2, price))



Re: Params Not Detected When Using Command - Kaperstone - 24.02.2012

Quote:
Originally Posted by lewismichaelbbc
Посмотреть сообщение
Hi, that hasnt answered my question, i didnt ask whats the best format to use. I asked how can i get the params to work. I cannot use ZCMD or YCMD because i use strcmp and dcmd together - using ZCMD just bugs the script.
zcmd and dcmd is almost the same,just zcmd save's alot of work.

and i suggest you not to use few cmd proccecors in the same script.
and this:
pawn Код:
if(color1 < 0 || color2 < 0) return SendClientMessage(playerid, COLOR_RED, "Invalid color!");
there's a max. limit too,120.
so add:
pawn Код:
if(color1 > 121 || color2 > 121) return SendClientMessage(playerid, COLOR_RED, "Invalid color!");
and if you still want to use dcmd,than,here's the fixed code/script:
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    dcmd(addv, 4, cmdtext);
    return 0;
}
 
dcmd_addv(playerid, params[])
    {
        if(!IsAdmin(playerid, 1)) SendClientMessage(playerid, COLOR_RED, "You are not admin!");
        if(!IsPlayerSpawned(playerid)) return SendClientMessage(playerid, COLOR_RED, "You can't use this command now!");
        new model[32], modelid, dealerid, color1, color2, price;
        if(sscanf(params, "dsddd", dealerid, model, color1, color2, price))
            return SendClientMessage(playerid, COLOR_GREY, "USAGE: /addv [dealerid] [model] [color1] [color2] [price]");
        if(!IsValidDealership(dealerid)) return SendClientMessage(playerid, COLOR_RED, "Invalid dealerid!");
        if(IsNumeric(model)) modelid = strval(model);
        else modelid = GetVehicleModelIDFromName(model);
        if(modelid < 400 || modelid > 611) return SendClientMessage(playerid, COLOR_RED, "Invalid model ID!");
        if(color1 < 0 || color2 < 0) return SendClientMessage(playerid, COLOR_RED, "Invalid color!");
        if(price < 0) return SendClientMessage(playerid, COLOR_RED, "Invalid price!");
        new Float:X, Float:Y, Float:Z, Float:angle;
        GetPlayerPos(playerid, X, Y, Z);
        GetPlayerFacingAngle(playerid, angle);
        X += floatmul(floatsin(-angle, degrees), 4.0);
        Y += floatmul(floatcos(-angle, degrees), 4.0);
        for(new i=1; i < MAX_DVEHICLES; i++)
        {
            if(!VehicleCreated[i])
            {
                new msg[128];
                VehicleCreated[i] = VEHICLE_DEALERSHIP;
                VehicleModel[i] = modelid;
                VehiclePos[i][0] = X;
                VehiclePos[i][1] = Y;
                VehiclePos[i][2] = Z;
                VehiclePos[i][3] = angle+90.0;
                VehicleColor[i][0] = color1;
                VehicleColor[i][1] = color2;
                VehicleInterior[i] = GetPlayerInterior(playerid);
                VehicleWorld[i] = GetPlayerVirtualWorld(playerid);
                VehicleValue[i] = price;
                valstr(VehicleOwner[i], dealerid);
                VehicleNumberPlate[i] = DEFAULT_NUMBER_PLATE;
                for(new d=0; d < sizeof(VehicleTrunk[]); d++)
                {
                    VehicleTrunk[i][d][0] = 0;
                    VehicleTrunk[i][d][1] = 0;
                }
                for(new d=0; d < sizeof(VehicleMods[]); d++)
                {
                    VehicleMods[i][d] = 0;
                }
                VehiclePaintjob[i] = 255;
                UpdateVehicle(i, 0);
                SaveVehicle(i);
                format(msg, sizeof(msg), "Added vehicle id %d to dealerid %d", i, dealerid);
                SendClientMessage(playerid, COLOR_WHITE, msg);
                return 1;
            }
        }
        SendClientMessage(playerid, COLOR_RED, "Can't add any more vehicles!");
        return 1;
    }



Re: Params Not Detected When Using Command - [ABK]Antonio - 24.02.2012

Quote:
Originally Posted by xkirill
Посмотреть сообщение
zcmd and dcmd is almost the same,just zcmd save's alot of work.

and i suggest you not to use few cmd proccecors in the same script.
and this:
pawn Код:
if(color1 < 0 || color2 < 0) return SendClientMessage(playerid, COLOR_RED, "Invalid color!");
there's a max. limit too,120.
so add:
pawn Код:
if(color1 > 121 || color2 > 121) return SendClientMessage(playerid, COLOR_RED, "Invalid color!");
Actually, that's not the limit but, the colors after 126 (some of them) appear black

https://sampwiki.blast.hk/wiki/Color_ID


Re: Params Not Detected When Using Command - Kaperstone - 24.02.2012

Quote:
Originally Posted by [ABK]Antonio
Посмотреть сообщение
Actually, that's not the limit but, the colors after 126 (some of them) appear black

https://sampwiki.blast.hk/wiki/Color_ID
yea,but if you'll look at the bottom of the second image you'll see,"Standard".
and many people are using a limit of 120.


Re: Params Not Detected When Using Command - lewismichaelbbc - 24.02.2012

Quote:
Originally Posted by xkirill
Посмотреть сообщение
zcmd and dcmd is almost the same,just zcmd save's alot of work.

and i suggest you not to use few cmd proccecors in the same script.
and this:
pawn Код:
if(color1 < 0 || color2 < 0) return SendClientMessage(playerid, COLOR_RED, "Invalid color!");
there's a max. limit too,120.
so add:
pawn Код:
if(color1 > 121 || color2 > 121) return SendClientMessage(playerid, COLOR_RED, "Invalid color!");
and if you still want to use dcmd,than,here's the fixed code/script:
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    dcmd(addv, 4, cmdtext);
    return 0;
}
 
dcmd_addv(playerid, params[])
    {
        if(!IsAdmin(playerid, 1)) SendClientMessage(playerid, COLOR_RED, "You are not admin!");
        if(!IsPlayerSpawned(playerid)) return SendClientMessage(playerid, COLOR_RED, "You can't use this command now!");
        new model[32], modelid, dealerid, color1, color2, price;
        if(sscanf(params, "dsddd", dealerid, model, color1, color2, price))
            return SendClientMessage(playerid, COLOR_GREY, "USAGE: /addv [dealerid] [model] [color1] [color2] [price]");
        if(!IsValidDealership(dealerid)) return SendClientMessage(playerid, COLOR_RED, "Invalid dealerid!");
        if(IsNumeric(model)) modelid = strval(model);
        else modelid = GetVehicleModelIDFromName(model);
        if(modelid < 400 || modelid > 611) return SendClientMessage(playerid, COLOR_RED, "Invalid model ID!");
        if(color1 < 0 || color2 < 0) return SendClientMessage(playerid, COLOR_RED, "Invalid color!");
        if(price < 0) return SendClientMessage(playerid, COLOR_RED, "Invalid price!");
        new Float:X, Float:Y, Float:Z, Float:angle;
        GetPlayerPos(playerid, X, Y, Z);
        GetPlayerFacingAngle(playerid, angle);
        X += floatmul(floatsin(-angle, degrees), 4.0);
        Y += floatmul(floatcos(-angle, degrees), 4.0);
        for(new i=1; i < MAX_DVEHICLES; i++)
        {
            if(!VehicleCreated[i])
            {
                new msg[128];
                VehicleCreated[i] = VEHICLE_DEALERSHIP;
                VehicleModel[i] = modelid;
                VehiclePos[i][0] = X;
                VehiclePos[i][1] = Y;
                VehiclePos[i][2] = Z;
                VehiclePos[i][3] = angle+90.0;
                VehicleColor[i][0] = color1;
                VehicleColor[i][1] = color2;
                VehicleInterior[i] = GetPlayerInterior(playerid);
                VehicleWorld[i] = GetPlayerVirtualWorld(playerid);
                VehicleValue[i] = price;
                valstr(VehicleOwner[i], dealerid);
                VehicleNumberPlate[i] = DEFAULT_NUMBER_PLATE;
                for(new d=0; d < sizeof(VehicleTrunk[]); d++)
                {
                    VehicleTrunk[i][d][0] = 0;
                    VehicleTrunk[i][d][1] = 0;
                }
                for(new d=0; d < sizeof(VehicleMods[]); d++)
                {
                    VehicleMods[i][d] = 0;
                }
                VehiclePaintjob[i] = 255;
                UpdateVehicle(i, 0);
                SaveVehicle(i);
                format(msg, sizeof(msg), "Added vehicle id %d to dealerid %d", i, dealerid);
                SendClientMessage(playerid, COLOR_WHITE, msg);
                return 1;
            }
        }
        SendClientMessage(playerid, COLOR_RED, "Can't add any more vehicles!");
        return 1;
    }
wow great!!! It actually works!!! Could you tell me what you did, because I have a few other commands which i need to do the same to, eg. /deletedealership ID /deletefuelstation ID

Thanks!


Re: Params Not Detected When Using Command - lewismichaelbbc - 24.02.2012

I tried converting them to DCMD, but the params are still not working. Could you help me?


pawn Код:
dcmd_deletedealership(playerid, params[])
{
    if(!IsAdmin(playerid, 1)) return SendClientMessage(playerid, COLOR_RED, "You are not admin!");
    new dealerid, msg[128];
    if(sscanf(params, "d", dealerid)) return SendClientMessage(playerid, COLOR_GREY, "USAGE: /deletedealership [dealerid]");
    if(!IsValidDealership(dealerid)) return SendClientMessage(playerid, COLOR_RED, "Invalid dealerid!");
    for(new i=1; i < MAX_DVEHICLES; i++)
    {
        if(VehicleCreated[i] == VEHICLE_DEALERSHIP && strval(VehicleOwner[i]) == dealerid)
        {
            DestroyVehicle(VehicleID[i]);
            Delete3DTextLabel(VehicleLabel[i]);
            VehicleCreated[i] = 0;
        }
    }
    DealershipCreated[dealerid] = 0;
    Delete3DTextLabel(DealershipLabel[dealerid]);
    SaveDealership(dealerid);
    format(msg, sizeof(msg), "Deleted dealership id %d", dealerid);
    SendClientMessage(playerid, COLOR_WHITE, msg);
    return 1;
}
and

pawn Код:
dcmd_deletefuelstation(playerid, params[])
{
    if(!IsAdmin(playerid, 1)) return SendClientMessage(playerid, COLOR_RED, "You are not admin!");
    new stationid, msg[128];
    if(sscanf(params, "d", stationid)) return SendClientMessage(playerid, COLOR_GREY, "USAGE: /deletefuelstation [stationid]");
    if(!IsValidFuelStation(stationid)) return SendClientMessage(playerid, COLOR_RED, "Invalid stationid!");
    FuelStationCreated[stationid] = 0;
    Delete3DTextLabel(FuelStationLabel[stationid]);
    SaveFuelStation(stationid);
    format(msg, sizeof(msg), "Deleted fuel station id %d", stationid);
    SendClientMessage(playerid, COLOR_WHITE, msg);
    return 1;
}