Wiki

Clone wiki

EFLC-Multiplayer / apiVehicle methods

API Vehicle

Create

#!c++
/*addVehicle(int mId, apiMath::Vector3 pos, apiMath::Vector3 rot, int c1, int c2, int c3, int c4, unsigned int vWorld)
mId: 0-160, open "vehicleModels.dat" for reference. 
pos: spawn position
rot: spawn rotation
c1, c2, c3, c4: vehicle colors
vWorld: virtual world
*/
#include "vehicleList.h"

int main()
{
    int model = 40; //Change the model to test
    if(!vehicleList::isValidModel(model))
    {
        //Model ID is invalid, spawn a TURISMO then
        model = vehicleList::getIdByName("TURISMO");
    }

    //SPAWNS a black vehicle infront of the Majestic Hotel (Central Park) in world ID 1 with default rotation
    int veh = apiVehicle::addVehicle(model, apiMath::Vector3(-205.4f, 630.0f, 13.8f), apiMath::Vector3(), 0, 0, 0, 0, 1);
    if(veh != -1)
    {
        //Vehicle was spawned!!
    }
}

Delete

#!c++
/*bool deleteVehicle(int vehicleId)
Trying to delete an invalid vehicle will throw std::out_of_range exception
*/

void onPlayerDisconnect(int playerid, int reason)
{
   //Deletes the vehicle this player is using
   int veh = apiPlayer::get(playerid).getDriving();
   if(apiVehicle::isVehicle(veh))
   {
      apiVehicle::deleteVehicle(veh);
   }
}

getPosition

Returns: apiMath::Vector3

#!c++
void onPlayerEnteredVehicle(int playerid, int vehicleId, int seatId)
{
    apiMath::Vector3 pos = apiVehicle::get(vehicleId);
    if(pos.z > 100.0f)
    {
        //Omg the vehicle is flying
    }
}

getVelocity

Returns: apiMath::Vector3

#!c++
apiMath::Vector3 velocity = apiVehicle::get(ID);
float speed = std::sqrtf(velocity.x * velocity.x + velocity.y * velocity.y + velocity.z * velocity.z);

getRotation

Returns: apiMath::Vector3

x: pitch

y: roll

z: yaw

getId

Returns: signed int

getDriver

Returns: signed int

setTune

Adds/Removes a vehicle component. Use openIV to preview them.

Params

  • unsigned int part (Index: 0 - 9)

  • bool attach

#!c++
apiVehicle::getVehicle(vehicleId).setTune(1, true);

isTuned

Returns bool

Params

  • unsigned int part (Index: 0 - 9)
#!c++
bool hasTune = apiVehicle::getVehicle(vehicleId).isTunned(1);

setColor

Params

  • int color1

  • int color2

  • int color3

  • int color4

#!c++
//Paints a vehicle RED
apiVehicle::getVehicle(vehicleId).setColor(29, 29, 29, 29);

getColor

Params

  • unsigned int colorSlot (Index: 0-3)
#!c++
int slot0 = apiVehicle::getVehicle(vehicleId).getColor(0);

setIndicator

Turns indicators on or off

Params

  • unsigned int indicator (Index: 0-1)
  • bool status
#!c++
//Turns both indicators ON
apiVehicle::getVehicle(vehicleId).setIndicator(0, true);
apiVehicle::getVehicle(vehicleId).setIndicator(1, true);

getIndicator

Params

  • unsigned int indicator (Index: 0-1)

setPosition

Defines a new position for a vehicle

Params

  • apiMath::Vector3& pos
#!c++
//TPS the vehicle to position 0, 0, 0
apiVehicle::getVehicle(vehicleId).setPosition(apiMath::Vector3());

setRotation

Defines a new rotation for a vehicle

Params

  • apiMath::Vector3& rotation

setVelocity

Defines a new velocity for a vehicle

Params

  • apiMath::Vector3& velocity

setLivery

Sets another livery for the vehicle. Use openIV to browse liveries. Default livery is 0.

Params

  • int liveryId

setDirtLevel

Updates the vehicle dirt level. Ranges from 0.0 to 2.0

Params

  • float dirt level

getEngineHealth

Returns: int Vehicle HP ranges from -2000 to +1000.

setEngineHealth

Params

  • int newHP

  • bool fix visual and tyres

getTire

Returns BOOL: whether the tyre is burst or not

Params

  • unsigned int tyre id (Index: 0-5)

setTire

Used to fix or burst a tyre

Params

  • unsigned int tyre id (Index: 0-5)

  • bool status

getGasPedal

Returns float: 0.0 being not pressed and 1.0 as fully pressed

setEngineFlags

Changes how the engine status

Params

  • int flag (0 off, 1 off but startable, 3 on)

getEngineFlags()

Returns int

Updated