Default Parameters (Colour issue)
#1

pawn Код:
command(veh, playerid, params[])
{
    new sCar;
    new str[128];
    new VehicleID;
    new Float:X, Float:Y, Float:Z, Float:Ang;
    new Int;
    new colour1, colour2;
   
    colour1 = 86;
    colour2 = -1;
   
    if(IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, 0x66666666, "You need to be on foot to spawn a vehicle.");
    if(unformat(params, "k<vehicles>DD", sCar, colour1, colour2)) return SendClientMessage(playerid, 0x66666666, "Usage: /veh(icle) [Vehicle ID / Name] [Colour 1(Optional)] [Colour 2(Optional)]");
    if(sCar == -1) return SendClientMessage(playerid, 0x66666666, "That vehicle model or ID doesn't exist.");
    if(colour2 == -1) return colour2 = colour1;
   
    GetPlayerPos(playerid,X, Y, Z);
    GetPlayerFacingAngle(playerid, Ang);
    Int = GetPlayerInterior(playerid);
   
    VehicleID = CreateVehicle(sCar, X, Y, Z, Ang, colour1, colour2, -1);
    SetVehicleVirtualWorld(VehicleID, GetPlayerVirtualWorld(playerid));

    PutPlayerInVehicle(playerid, VehicleID, 0);
    LinkVehicleToInterior(VehicleID, Int);
    format(str, sizeof(str), "You have spawned a: %s [ID %d]", VehicleNames[sCar - 400], sCar);
    SendClientMessage(playerid, 0x66CCFFFF, str);
    return 1;
}
The script above is a vehicle spawning script..

Basically I want the colour ID of the vehicle to be 86 if no colour ID is input, and if the first colour ID is input then the second is the same colour as the first.

The script in theory should work, but it doesn't.. Any tips?
Reply
#2

I(DEFAULT_VALUE)
Reply
#3

Quote:
Originally Posted by [ABK]Antonio
Посмотреть сообщение
I(DEFAULT_VALUE)
Pardon?
Reply
#4

he means with the unformat function

pawn Код:
if(unformat(params, "k<vehicles>D(default here)D(default here)", sCar, colour1, colour2))

//example for defaults like you asked
if(unformat(params, "k<vehicles>D(86)D(-1)", sCar, colour1, colour2))
if (colour2 == -1) colour2 = colour1;
Reply
#5

Quote:
Originally Posted by Jonny5
Посмотреть сообщение
he means with the unformat function

pawn Код:
if(unformat(params, "k<vehicles>D(default here)D(default here)", sCar, colour1, colour2))

//example for defaults like you asked
if(unformat(params, "k<vehicles>D(86)D(-1)", sCar, colour1, colour2))
if (colour2 == -1) colour2 = colour1;
Thanks, tried it but the issue is, that the command does not spawn the car unless both Variables are input, I have a feeling it is because of the -1, trying it now
Reply
#6

yes because you did not setup a default
you have to do it in the unformat specifier like i showed above
see how i added (86) and (-1)
Reply
#7

Quote:
Originally Posted by Jonny5
Посмотреть сообщение
yes because you did not setup a default
you have to do it in the unformat specifier like i showed above
see how i added (86) and (-1)
Sorry, I meant I added the default and It breaks, I think it is because of the -1 I have set..

Fixed it, added a new variable called "defaultcolour", set it to the default and then had the If statement to change it to the colour1..

Thanks guys..
Reply
#8

hum try it this way with I instead and use a number like 500 as this is not a car color

"k<vehicles>I(86)I(500)"

then check if colour2 == 500;


EDIT: glad you fixed it!
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)