Spawn vehicle. Didn't put me inside of the vehicle.
#1

What's wrong with this codes? I'm making a vehicle spawner but it didn't put me in the vehicle. Here's the codes...

pawn Код:
CMD:v(playerid,params[])
{
    new Float:P[4];
    new veh = GetPlayerVehicleID(playerid);
    if(sscanf(params,"i",veh)) return SCM(playerid,COLOR_RED,"[USAGE] /V [Vehicle ID]");
    else if(veh < 400 || veh > 611) return SCM(playerid,COLOR_RED,"[ERROR] Invalid Vehicle ID");
    else
    {
    GetPlayerPos(playerid,P[0],P[1],P[2]);
    GetPlayerFacingAngle(playerid,P[3]);
    CreateVehicle(veh,P[0],P[1],P[2],P[3],-1,-1,-1);
    PutPlayerInVehicle(playerid,veh,0);
    }
    return 1;
}
Reply
#2

Try this:

pawn Код:
stock GetXYInFrontOfPlayer(playerid, &Float:x, &Float:y, Float:distance)
{
    new Float:a;

    GetPlayerPos(playerid, x, y, a);
    GetPlayerFacingAngle(playerid, a);

    if (GetPlayerVehicleID(playerid)) {
        GetVehicleZAngle(GetPlayerVehicleID(playerid), a);
    }

    x += (distance * floatsin(-a, degrees));
    y += (distance * floatcos(-a, degrees));
}

COMMAND:v(playerid, params[])
{
    new vehicle, pString[128], vCreated;
    if(sscanf(params, "i", vehicle)) return SendClientMessage(playerid, 0xFFFFFFFF, "* Usage: /v [vehicle id]");
    else
    {
        new Float: pPos[4];
        GetPlayerPos(playerid, pPos[0], pPos[1], pPos[2]);
        GetPlayerFacingAngle(playerid, pPos[3]);
        GetXYInFrontOfPlayer(playerid, pPos[0], pPos[1], 5);
        format(pString, sizeof(pString), "* You have spawned a vehicle. ID: %i", vehicle);
        SendClientMessage(playerid, 0xFFFFFFFF, gMessage);
        vCreated = CreateVehicle(vehicle, pPos[0], pPos[1], pPos[2], pPos[3], random(128), random(128), -1);
                PutPlayerInVehicle(playerid, vCreated, 0);
    }
    return 1;
}
Reply
#3

I think this line
new veh = GetPlayerVehicleID(playerid);
change to
new veh;
Reply
#4

@ Parasight: I want to put the player INSIDE of the vehicle. Not infront of the player.
@ Kiets: Still not working
Reply
#5

I'm not sure if this is the most efficient way of doing it, but I think when you use CreateVehicle, it assigns the highest vehicle id.
pawn Код:
for(new i=0; i<MAX_VEHICLES; i++) // Loop through all the cars.
{
    // The first invalid vehicle ID is obviously one that hasn't been made yet.
    if(i == INVALID_VEHICLE_ID)
    {
        i = CreateVehicle(blahblah); break; // so it breaks out of the loop at the highest vehicle.
    }
}
PutPlayerInVehicle(playerid, i, 0);
It also might not work if you have the 2k cars in your script.
Reply
#6

pawn Код:
COMMAND:v(playerid, params[])
{
    new vehicle, pString[128], vCreated;
    if(sscanf(params, "i", vehicle)) return SendClientMessage(playerid, 0xFFFFFFFF, "* Usage: /v [vehicle id]");
    else
    {
        new Float: pPos[4];
        GetPlayerPos(playerid, pPos[0], pPos[1], pPos[2]);
        GetPlayerFacingAngle(playerid, pPos[3]);
        format(pString, sizeof(pString), "* You have spawned a vehicle. ID: %i", vehicle);
        SendClientMessage(playerid, 0xFFFFFFFF, gMessage);
        vCreated = CreateVehicle(vehicle, pPos[0], pPos[1], pPos[2], pPos[3], random(128), random(128), -1);
                PutPlayerInVehicle(playerid, vCreated, 0);
    }
    return 1;
}
Reply
#7

Finally fixed by me The codes are almost same as Parasight's post ^
But, here's another problem/question.
How to destroy another vehicle after spawning a new one?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)