Help - CreateVehicle ID
#1

Hi,

i have code like this in my GM:

new Car[MAX_PLAYERS_EX];

stock BuyCar(playerid,CarID ....)
{
...
Car[playerid] = CreateVehicle(CarID,-1723.4584,234.6916,-0.3534,271.7465,random(100),random(100),-1);
...

and then command /callvehicle. That command transfers player into vehicle, which he created.
But after some time, vehicles ID mix up. For example player ID 1 writes /callvehicle and he was transferred to another vehicle.

Can somebody help me please?
Reply
#2

Quote:
Originally Posted by Hrb
Посмотреть сообщение
Hi,

i have code like this in my GM:

new Car[MAX_PLAYERS_EX];

stock BuyCar(playerid,CarID ....)
{
...
Car[playerid] = CreateVehicle(CarID,-1723.4584,234.6916,-0.3534,271.7465,random(100),random(100),-1);
...

and then command /callvehicle. That command transfers player into vehicle, which he created.
But after some time, vehicles ID mix up. For example player ID 1 writes /callvehicle and he was transferred to another vehicle.

Can somebody help me please?
you have to destroy their vehicle and reset the variable once they disconnect
you could set it to -1 and then check in your cmd if its -1 (which could indicate that theres no vehicle)
pawn Код:
new Car[MAX_PLAYERS_EX] = {-1,...};
Reply
#3

pawn Код:
// This is a comment
// uncomment the line below if you want to write a filterscript

#define FILTERSCRIPT

#if defined FILTERSCRIPT

#include <a_samp>

new vehicle_spawn[MAX_PLAYERS];

public OnGameModeInit()
{
    for(new i = 0; i < MAX_PLAYERS; i++) // We restarted the variable of all players(0).
    {
        vehicle_spawn[i] = 0;
    }
    return 1;
}

public OnPlayerConnect(playerid) //When the player is ah connected must be in 0, because when you disconnect will destroy the last vehicle.
{
    vehicle_spawn[playerid] = 0;
    return 1;
}

public OnPlayerDisconnect(playerid, reason) //When you disconnect restarted its variable and destroy the last vehicle created.
{
    if(vehicle_spawn[playerid] != 0)
    {
        DestroyVehicle(vehicle_spawn[playerid]);
        vehicle_spawn[playerid] = 0;
    }
    return 1;
}

stock CreateVehicleEx(playerid, modelid) // With this feature we can create vehicles in all our indent usage CreateVehicleEx(playerid, modelid);
{
    new Float:pos[4]; // Create float 4 slots to obtain pos_x, pos_y, pos_z and GetVehicleZangle If you are in a vehicle the user.

    if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER) // obtain getplayerstate (if this driver)..
    {
        GetVehiclePos(GetPlayerVehicleID(playerid), pos[0], pos[1], pos[2]); // Obtain position in the floats.
        GetVehicleZAngle(GetPlayerVehicleID(playerid), pos[3]); // obtan angle vehicle.
        DestroyVehicle(GetPlayerVehicleID(playerid)); // Destroy last vehicle created and continue function.
    }
    else // if not this driver..
    {
        GetPlayerPos(playerid, pos[0], pos[1], pos[2]);  // obtain position in the floats.
        GetPlayerFacingAngle(playerid, pos[3]); // obtain angle playerid and continue function..
    }
    if(vehicle_spawn[playerid] != 0)
    {
        DestroyVehicle(vehicle_spawn[playerid]); // if variable is greater than 0 destroy the last vehicle created.
    }
    vehicle_spawn[playerid] = CreateVehicle(modelid, pos[0], pos[1], pos[2], pos[3], -1, -1, 60); // Create vehicle in pos obtain the floats.
    LinkVehicleToInterior(vehicle_spawn[playerid], GetPlayerInterior(playerid)); // Changes inside the vehicle to which the user is located.
    SetVehicleVirtualWorld(vehicle_spawn[playerid], GetPlayerVirtualWorld(playerid)); // Change the world the vehicle spawn to which you will find a player
    PutPlayerInVehicle(playerid, vehicle_spawn[playerid], 0); // The playerid enters the vehicle and driver.
    SetVehicleZAngle(vehicle_spawn[playerid], pos[3]); // Set angle te obtain float.
    return true;
}

#endif
Create Vehicle using:
pawn Код:
CreateVehicleEx(playerid, modelid);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)