PDA

View Full Version : Vehicle ID


AiRaLoKa
07/06/2014, 08:08 AM
hi all...

i have a little bit bug here... i want to make a vehicle spawner, and when i test it alone, it's work fine.
but when i try it with some of my friends, it's got bugged. What i want is destroy previouse player's spawned vehicle. but it's destroy my friend's vehicle ??? can somebody help me?

//
if(IsPlayerInAnyVehicle(playerid))
{
new vid = GetPlayerVehicleID(playerid);
DestroyVehicle(vid);
if(VehicleSpawn[playerid]==0)
{
new Float:x,Float:y,Float:z,Float:a;
GetPlayerPos(playerid,x,y,z);
GetPlayerFacingAngle(playerid,a);
DestroyVehicle(pInfo[playerid][pSpawnVehicle]);
pInfo[playerid][pSpawnVehicle] = AddStaticVehicle(model, x, y, z+1, a, -1, -1);
PutPlayerInVehicle(playerid, pInfo[playerid][pSpawnVehicle], 0);
SetVehicleHealth(pInfo[playerid][pSpawnVehicle], 1000.0);
LinkVehicleToInterior(pInfo[playerid][pSpawnVehicle], GetPlayerInterior(playerid));
}
}

Rittik
07/06/2014, 08:20 AM
I guess AddStaticvehicle only works under GameModeInit.
AddStaticVehicle (http://wiki.sa-mp.com/wiki/AddStaticVehicle)

BroZeus
07/06/2014, 08:21 AM
is this under a command?

AiRaLoKa
07/06/2014, 08:23 AM
is this under a command?


no
this is the full script

public VehicleSpawner(playerid,model)
{
if(IsPlayerInAnyVehicle(playerid))
{
new vid = GetPlayerVehicleID(playerid);
DestroyVehicle(vid);
if(VehicleSpawn[playerid]==0)
{
new Float:x,Float:y,Float:z,Float:a;
GetPlayerPos(playerid,x,y,z);
GetPlayerFacingAngle(playerid,a);
DestroyVehicle(pInfo[playerid][pSpawnVehicle]);
pInfo[playerid][pSpawnVehicle] = AddStaticVehicleEx(model, x, y, z+1, a, -1, -1, -1);
PutPlayerInVehicle(playerid, pInfo[playerid][pSpawnVehicle], 0);
SetVehicleHealth(pInfo[playerid][pSpawnVehicle], 1000.0);
LinkVehicleToInterior(pInfo[playerid][pSpawnVehicle], GetPlayerInterior(playerid));
}
}
else
{
if(VehicleSpawn[playerid]==0)
{
new Float:x,Float:y,Float:z,Float:a;
GetPlayerPos(playerid,x,y,z);
GetPlayerFacingAngle(playerid,a);
DestroyVehicle(pInfo[playerid][pSpawnVehicle]);
pInfo[playerid][pSpawnVehicle] = AddStaticVehicleEx(model, x, y, z+1, a, -1, -1, -1);
PutPlayerInVehicle(playerid, pInfo[playerid][pSpawnVehicle], 0);
SetVehicleHealth(pInfo[playerid][pSpawnVehicle], 1000.0);
LinkVehicleToInterior(pInfo[playerid][pSpawnVehicle], GetPlayerInterior(playerid));
}
}
return 1;
}

SupaFool
07/06/2014, 08:25 AM
Maybe make it out of stock?

BroZeus
07/06/2014, 08:26 AM
were u in ur friend's vehicle
or
your friend was in your vehicle when u tried that?

AiRaLoKa
07/06/2014, 08:28 AM
were u in ur friend's vehicle
or
your friend was in your vehicle when u tried that?

no, my friend is in another vehicle,, when i use the command to spawn the vehicle, his vehicle gone. :picard:

AiRaLoKa
08/06/2014, 06:07 AM
sorry for bumping, but i still have this bug ??? can somebody help me?

Threshold
08/06/2014, 08:23 AM
I don't know where you're using VehicleSpawner, but this should work:
public VehicleSpawner(playerid, model)
{
if(!VehicleSpawn[playerid]) //Dunno what this means, but oh well.
{
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
new vid = GetPlayerVehicleID(playerid);
if(vid) SetVehicleToRespawn(vid);
}
new Float:x, Float:y, Float:z, Float:a;
GetPlayerPos(playerid, x, y, z);
GetPlayerFacingAngle(playerid, a);
if(pInfo[playerid][pSpawnVehicle] != INVALID_VEHICLE_ID)
{
DestroyVehicle(pInfo[playerid][pSpawnVehicle]);
pInfo[playerid][pSpawnVehicle] = INVALID_VEHICLE_ID;
}
pInfo[playerid][pSpawnVehicle] = CreateVehicle(model, x, y, z + 1, a, -1, -1, -1);
PutPlayerInVehicle(playerid, pInfo[playerid][pSpawnVehicle], 0);
LinkVehicleToInterior(pInfo[playerid][pSpawnVehicle], GetPlayerInterior(playerid));
return pInfo[playerid][pSpawnVehicle];
}
return INVALID_VEHICLE_ID;
}

AiRaLoKa
08/06/2014, 09:12 AM
I don't know where you're using VehicleSpawner, but this should work:
public VehicleSpawner(playerid, model)
{
if(!VehicleSpawn[playerid]) //Dunno what this means, but oh well.
{
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
new vid = GetPlayerVehicleID(playerid);
if(vid) SetVehicleToRespawn(vid);
}
new Float:x, Float:y, Float:z, Float:a;
GetPlayerPos(playerid, x, y, z);
GetPlayerFacingAngle(playerid, a);
if(pInfo[playerid][pSpawnVehicle] != INVALID_VEHICLE_ID)
{
DestroyVehicle(pInfo[playerid][pSpawnVehicle]);
pInfo[playerid][pSpawnVehicle] = INVALID_VEHICLE_ID;
}
pInfo[playerid][pSpawnVehicle] = CreateVehicle(model, x, y, z + 1, a, -1, -1, -1);
PutPlayerInVehicle(playerid, pInfo[playerid][pSpawnVehicle], 0);
LinkVehicleToInterior(pInfo[playerid][pSpawnVehicle], GetPlayerInterior(playerid));
return pInfo[playerid][pSpawnVehicle];
}
return INVALID_VEHICLE_ID;
}

yeah, i think it will work, by reading the code...
going to test it

EDIT:
it's work! thanks BenzoAMG and +REP