small help need with command +REP
#1

the cmd have so much bugs, can anyone fix it for me ?
I would like to remove the [price]
and yeah there is a mistake somewhere
so I type /giveowncar id model color1 color2
the command give to me the car and set me as owner
I would like someone of you make it to give the owner to the decided player I used in command
and spawn car close him
+REP
Srry for bad English
pawn Код:
CMD:giveowncar(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
        position,
        modelid,
        color1,
        color2,
        price;
    if(!IsPlayerConnected( position )) return SendClientMessage( playerid, -1, "Player not connected" );
    if(sscanf(params, "dk<vehicle>ddd", position,modelid, color1, color2, price)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /givevipcar [playerid] [model] [color1] [color2] [price]");
    if(!(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;
    new freeid = GetFreeVehicleID();
    GetPlayerPos(position, X, Y, Z);
    GetPlayerFacingAngle(position, angle);

    X += floatmul(floatsin(-angle, degrees), 4.0);
    Y += floatmul(floatcos(-angle, degrees), 4.0);

    new
        i = 1;

    for(; i < MAX_DVEHICLES; i++)
        if(!VehicleCreated[i]) break;

    if(i == MAX_DVEHICLES) return SendClientMessage(playerid, COLOR_RED, "Can't add any more vehicles!");

    VehicleCreated[i] = VEHICLE_PLAYER; //Vehicle for player
    VehicleModel[i] = modelid; //car model
    VehiclePos[i][0] = X; //player x
    VehiclePos[i][1] = Y; //y
    VehiclePos[i][2] = Z; //z
    VehiclePos[i][3] = angle+90.0;
    VehicleColor[i][0] = color1; //cc 1
    VehicleColor[i][1] = color2; //cc 2
    VehicleInterior[i] = GetPlayerInterior(playerid); //get player int
    VehicleWorld[i] = GetPlayerVirtualWorld(playerid); // get player vw
    VehicleValue[i] = price;
    GetPlayerName(playerid, VehicleOwner[freeid], sizeof(VehicleOwner[])); //setowner dont work

    //valstr(VehicleOwner[i],position);
    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;
    VehicleLock[i] = 0;
    VehicleAlarm[i] = 0;
    UpdateVehicle(i, 0);
    SaveVehicle(i);
    return 1;
}
Reply
#2

It's been a very, very long time since I've coded or posted on this forum. Forgive me if this doesn't fix your issues, but it should. You were using "playerid" in parts where you should've used the variable you created for the player you are giving the car to. That is called "position" for whatever reason, so it should be all fixed now.

I have also removed the price requirement for the car.

pawn Код:
CMD:giveowncar(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
        position,
        modelid,
        color1,
        color2,
    if(!IsPlayerConnected( position )) return SendClientMessage( playerid, -1, "Player not connected" );
    if(sscanf(params, "dk<vehicle>dd", position,modelid, color1, color2)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /givevipcar [playerid] [model] [color1] [color2]");
    if(!(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;
    new freeid = GetFreeVehicleID();
    GetPlayerPos(position, X, Y, Z);
    GetPlayerFacingAngle(position, angle);

    X += floatmul(floatsin(-angle, degrees), 4.0);
    Y += floatmul(floatcos(-angle, degrees), 4.0);

    new
        i = 1;

    for(; i < MAX_DVEHICLES; i++)
        if(!VehicleCreated[i]) break;

    if(i == MAX_DVEHICLES) return SendClientMessage(playerid, COLOR_RED, "Can't add any more vehicles!");

    VehicleCreated[i] = VEHICLE_PLAYER; //Vehicle for player
    VehicleModel[i] = modelid; //car model
    VehiclePos[i][0] = X; //player x
    VehiclePos[i][1] = Y; //y
    VehiclePos[i][2] = Z; //z
    VehiclePos[i][3] = angle+90.0;
    VehicleColor[i][0] = color1; //cc 1
    VehicleColor[i][1] = color2; //cc 2
    VehicleInterior[i] = GetPlayerInterior(position); //get player int
    VehicleWorld[i] = GetPlayerVirtualWorld(position); // get player vw
    GetPlayerName(position, VehicleOwner[freeid], sizeof(VehicleOwner[])); //setowner dont work

    //valstr(VehicleOwner[i],position);
    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;
    VehicleLock[i] = 0;
    VehicleAlarm[i] = 0;
    UpdateVehicle(i, 0);
    SaveVehicle(i);
    return 1;
}
Reply
#3

+ rep thanks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)