1. Car definition
As usual, car plugins are defined by using a json file as textual description of your plugin.
A car plugin's json file can look as simple as this:
Code: Select all
[
{
"id":"$lobby_carplugin00",
"type":"car",
"frames":[
{"bmp":"carsample.png","w":18,"h":12,"count":4}
],
"v2":true
}
]
It's worth to mention that "v2":true indicates that we want to use the second generation of car loading. We recommend that as it's much easier to use and takes less expensive texture space. However, a lot of cars are still internally defined using the old system. The provided frames there have to look like that: The border of free space of each frame (size 32x16) as well as the index for each direction differ from the v2 approach. The space is needed here as it's used for positioning.
2. Spawn cars
Now assume we want our sample building "$sample.plugin.unique.id.res00" from our sample plugin to spawn cars from our car plugin "$lobby_carplugin00". We can do that by defining a car spawner with the following attributes:
- cars - An array of car ids
- radius - Radius for the cars to be spawned. Big radius are heavy on computation, so try to avoid them. To cover the whole map you might use a value like 512
- count - Number of cars that should be spawned
- targets - An array of building ids that should be targeted by spawned cars. If empty, any buildings will be targeted (default behavior). Entry null will represent the building in which the car spawner is defined (for convenience).
Code: Select all
[
{
"id":"$sample.plugin.unique.id.res00",
"type":"residential",
"author":"Lobby & theotheoderich",
"width":1,
"height":1,
"frames":[{"bmp":"sample_bmp.png"}],
"smoke":[{"id":"$smoke07","x":13,"y":-14}],
"level":1,
"car spawner":[
{
"cars":["$lobby_carplugin00"],
"radius":10,
"count":5
}
]
}
]
3. Overriding existing cars
⚠Overriding cars was only needed in the past to add your own residential/industrial cars into the game. See this thread on how this should be done since version 437.
As shown in this post you can override existing cars in the game by using the same id. This works as plugins are loaded after internal objects so that the existing object will be overridden (in most cases, it doesn't work well for ground objects for example).
These ids are used for predefined cars:
- $carres00
- $carres01
- $carres02
- $carind00
- $carind01
- $carind02
- $carfirebrigade00
- $carpolice00
- $carbus00
- $carswat00
- $tank00
- $mltry_truck00
- $carmedic00
- $car_null00 (a car without graphics)
4. Reusing car frames from the game
As discussed in this thread we allow you to use our car graphics in your own plugins. However, you have to mention us (me and theo) as authors when distributing it. The easiest way to "steal" our car frames is by using the frame stealing feature which we also used for our people animation. You can do that by using the car ids provided in section 3.
Another way to get car frames is by directly copy them into your own graphics. Here we provide some of our car graphics: You'll find the bus graphics here.
Diagonal cars
See here for details about how to extend the prior definition to support driving on diagonals, too: viewtopic.php?p=177072#p177072