Skip to content

Vehicle Script

Ferdinand Calo edited this page Aug 8, 2019 · 1 revision
# Feature Overview
Kind: Vehicle Script
Extendable: true
JSON based: no
JSON config: no / through attributes

"Vehicle Scripts" are optional instances of custom "classes" ran along
the vehicle entity's general "lifetime". They can be added into a Vehicle via Parts. You can take a look at the class there: VehicleScript.class

Let's see some of the methods:

  • getId - should return an unique id for the script
  • getName - an optional name for the script
  • onUpdate - called every onUpdate call of the Vehicle Entity
  • read - called when the entity's data is read, should return the script instance
  • write - called when the entity's data is written, should return a tag compound
  • onSpawn - called soon after the entity is spawned
  • onRemove - called right before the entity is removed
  • onKeyPress - called when a key was pressed
  • onInteract - called when a player interacts with the vehicle,
    return true to skip/cancel other interaction code
  • onDataPacket - called when the script received a data (nbt) packet
  • sendPacket - method to send packets to the script Client<>Server side

You can do a lot of things with VehicleScripts, for part even override default behaviour. They give you access to the most essential events in an entity's existence, if you
need any more, just request them to be implemented.

Examples of usage of Vehicle Scripts you could find already in FVTM 2!
e.g. the T1(Truck)'s "snow plow" upgrade which was able to clear paths from snow
and "push" the rest on the side of the road,
or the Container Crane which was able to lift up containers, move them around
and even place them - either on land or into another vehicle!

Clone this wiki locally