Spawn vehicle. Didn't put me inside of the vehicle. -
newbienoob - 29.04.2012
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;
}
Re: Spawn vehicle. Didn't put me inside of the vehicle. -
Parasight - 29.04.2012
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;
}
Re: Spawn vehicle. Didn't put me inside of the vehicle. -
Kiets - 29.04.2012
I think this line
new veh = GetPlayerVehicleID(playerid);
change to
new veh;
Re: Spawn vehicle. Didn't put me inside of the vehicle. -
newbienoob - 29.04.2012
@ Parasight: I want to put the player INSIDE of the vehicle. Not infront of the player.
@ Kiets: Still not working
Re: Spawn vehicle. Didn't put me inside of the vehicle. -
ReneG - 29.04.2012
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.
Re: Spawn vehicle. Didn't put me inside of the vehicle. -
Parasight - 29.04.2012
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;
}
Re: Spawn vehicle. Didn't put me inside of the vehicle. -
newbienoob - 29.04.2012
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?