Need help with /givev command.
#1

I have a filterscript called AVS. It's basically a car-ownership system. I tried to make a command where an admin could give a vehicle to a player. What I did was, I took /addv (which is a command to add a car to a dealership) and modified it.

Here's the command:
pawn Код:
CMD:givev(playerid, params[])
{
    if(!IsAdmin(playerid, 1)) return 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], targetid, modelid, color1, color2, price;
    if(sscanf(params, "dsddd", targetid, model, color1, color2, price))
        return SendClientMessage(playerid, COLOR_GREY, "USAGE: /givev [playerid] [model] [color1] [color2] [value]");
    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!");
    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_PLAYER;
            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;
            GetPlayerName(targetid, VehicleOwner[i], sizeof(VehicleOwner[]));
            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), "You gave vehicle id %d to player id %d", i, targetid);
            SendClientMessage(playerid, COLOR_WHITE, msg);
            return 1;
        }
    }
    SendClientMessage(playerid, COLOR_RED, "Can't add any more vehicles!");
    return 1;
}
Now, my problem is: Let's say ID 0 is Tom and ID 1 is Jason. ID 0 is an admin, he uses /givev command to give Jason a vehicle, but instead he ends up giving himself a vehicle, even though he typed in /givev 1 400 0 0 100. If you don't get what I'm saying, let me explain this way. I don't know how to make "targetid" work.
Reply
#2

You have to use "u" and not "d" for players in sscanf.

So, it will be like this:
Код:
if(sscanf(params, "usddd", targetid, model, color1, color2, price))
Reply
#3

Also, try to detect if the player ID is valid or not by simply using:
pawn Код:
if(targetid != INVALID_PLAYER_ID)
Reply
#4

Quote:
Originally Posted by KreeDz
Посмотреть сообщение
You have to use "u" and not "d" for players in sscanf.

So, it will be like this:
Код:
if(sscanf(params, "usddd", targetid, model, color1, color2, price))
You don't have to use the u specifier, it's better if you do though.
Reply
#5

Thanks alot guys, all of you helped me alot
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)