Cars

Learn here how to create and use plugins.

Moderator: Plugin Moderators

Lobby
Developer
Reactions:
Posts: 3503
Joined: Sun Oct 26, 2008 12:34
Plugins: Show
Version: Beta

Cars

In this thread I would like to show you how to create your own cars and how to use them. We highly recommend that you've already read our basics about plugin creation.

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 } ] You will notice that I provide 4 frames here. That's needed as we need a frame (image) for each direction in which the car can drive. We indexed the directions as followed: So our actual image carsample.png may look like this: Notice how we load 4 frames from a single image by providing the width and height of each frame and the number of frames we want to extract. The plugin loader will automatically load "count" many frames of the given width and height from left to right out of the provided image. You can provide multiple cars within a single plugin by just providing more frames. The total number of frames has to be a multiple of 4. 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). So our plugin may look like 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"],
"count":5
}
]
}
]
Please notice that you have to define your car before using it in any other plugin.

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.
Last edited by CommanderABab on Wed Nov 29, 2017 10:24, edited 2 times in total.

Sometheotown mayor
Has uncountable inhabitants
Reactions:
Posts: 1548
Joined: Sat Jan 28, 2017 21:37
Location: Somewhere in the middle of russia
Plugins: Show

Platform

can i get the TV car id please

Lobby
Developer
Reactions:
Posts: 3503
Joined: Sun Oct 26, 2008 12:34
Plugins: Show
Version: Beta

It's just $cartv00 Lobby Developer Reactions: Posts: 3503 Joined: Sun Oct 26, 2008 12:34 Plugins: Show Version: Beta Platform Since version 296 we have a new optional attribute for cars: speed It's a multiplier for the car speed (similar to the speed attribute of roads). Usage: Code: Select all  { "id":"$lobby_carplugin00",
"type":"car",
"frames":[
{"bmp":"carsample.png","w":18,"h":12,"count":4}
],
"v2":true,
"speed":0.9
}

Default value is 1.0

KINGTUT10101
1,000,000 inhabitants
Reactions:
Posts: 2023
Joined: Thu Jul 07, 2016 22:50
Location: 'Merica
Plugins: Show
Version: Beta
Contact:

Plugin Creator

Do you need to replace existing cars or can we add custom ones with new ids?

CommanderABab
AB
Reactions:
Posts: 8570
Joined: Tue Jun 07, 2016 21:12
Plugins: Show
Version: Beta

Plugin Creator

You may create new ones with new ids.
Last edited by CommanderABab on Thu Jun 08, 2017 8:16, edited 1 time in total.
888!🆎️

KINGTUT10101
1,000,000 inhabitants
Reactions:
Posts: 2023
Joined: Thu Jul 07, 2016 22:50
Location: 'Merica
Plugins: Show
Version: Beta
Contact:

Plugin Creator

Is there a way to make cars not despawn?

CommanderABab
AB
Reactions:
Posts: 8570
Joined: Tue Jun 07, 2016 21:12
Plugins: Show
Version: Beta

Plugin Creator

Maybe give them a high capacity.
888!🆎️

Lobby
Developer
Reactions:
Posts: 3503
Joined: Sun Oct 26, 2008 12:34
Plugins: Show
Version: Beta

Cars spawned by a specific building will normally not despawn if they always find a way. Normals cars like $carres00 will despawn by design. Lobby Developer Reactions: Posts: 3503 Joined: Sun Oct 26, 2008 12:34 Plugins: Show Version: Beta Platform Re: Cars In case you used the car attribute in a plugin, you have to replace it with another code since version 312 (will be released right now). Replace this code Code: Select all "car":"ped.dusko.1", "car count":4, "car radius":25 with Code: Select all "car spawner":[ { "cars":["ped.dusko.1"], "count":4, "radius":25 } ] (any similarity to existing plugin code is pure coincidence) If you want to mimic the car local only-attribute from before (only the defining building will be targeted by cars) add the following into your car spawner: Code: Select all "targets":[""] The changes we made were necessary in order to provide more flexible car spawning functionality. =^._.^= ∫ CommanderABab AB Reactions: Posts: 8570 Joined: Tue Jun 07, 2016 21:12 Plugins: Show Version: Beta Platform Plugin Creator Re: Cars Nice! 888!🆎️ Barky TheoTown Cartographer Reactions: Posts: 2074 Joined: Mon Apr 17, 2017 22:13 Location: Ireland Plugins: Show Platform Re: Cars Hmm maybe I'll try have a go with my plug-in again CommanderABab AB Reactions: Posts: 8570 Joined: Tue Jun 07, 2016 21:12 Plugins: Show Version: Beta Platform Plugin Creator Re: Cars Question Code: Select all "car spawner":[ { "cars":["ped.dusko.1"], "count":4, "radius":25, // do the targets go here? "targets":[""] } ] 888!🆎️ Lobby Developer Reactions: Posts: 3503 Joined: Sun Oct 26, 2008 12:34 Plugins: Show Version: Beta Platform Re: Cars Exactly =^._.^= ∫ danekbel Inhabitant of a Galaxy Cluster Reactions: Posts: 2788 Joined: Thu May 05, 2016 9:33 Location: in your dreams Plugins: Show Version: Beta Platform Plugin Creator Re: Cars Can I still override existing cars? some text. actemendes Metropolitan Reactions: Posts: 131 Joined: Fri Jan 20, 2017 16:53 Location: Russia Plugins: Show Platform Re: Cars Probably this topic is most suitable for my question. I did not find an article about water transport. What code is needed for spawning ships and yachts? And please can I get their png texture? Do not bend under a volatile world, One day he will bend under us. Lobby Developer Reactions: Posts: 3503 Joined: Sun Oct 26, 2008 12:34 Plugins: Show Version: Beta Platform Re: Cars Here some graphics: yacht_green.png (993 Bytes) Viewed 7246 times yacht_blue.png (967 Bytes) Viewed 7246 times ship.png (5.67 KiB) Viewed 7246 times As always, please give me and theo credit when you reuse it for a plugin. Don't use it outside of TheoTown without permission. The json looks fairly simple. Use ship as type and provide at least 4 frames. For the yacht it may looks like Code: Select all [ { "id":"$shipyacht00",
"type":"ship",
"frames":[
{"bmp":"yacht_green.png","w":17,"h":15,"count":4,"handle x":8,"handle y":12},
{"bmp":"yacht_blue.png","w":17,"h":15,"count":4,"handle x":8,"handle y":12}
]
}
]
Here we provide 8 frames, 4 for each variant of the yacht. The game will pick a variant randomly when spawning a ship. Move frames using handle x and handle y until it looks good. Setting them correctly is difficult, so do it by trial and error.

If your ship is longer than one tile use

Code: Select all

"length":2,
to indicate this. However, the longer the ship the more likely are graphic issues. That's why we never added the long container ships.

Spawning ships from a building is fairly simple. It looks similar to car spawning before car spawners were added:

Code: Select all

"ships":["\$shipyacht00"],
"ship count":4,
"ship radius":16,
"ship radius" is currently ignored. Use it for the future.
=^._.^= ∫

rjroldan1
Inhabitant of a Megalopolis
Reactions:
Posts: 569
Joined: Mon Jul 17, 2017 16:16
Location: Antipolo, Philippines
Plugins: Show
Contact:

Re: Cars

how to make a decoration that place in water?
T.P.C.

Theotown Philippine Corporation

PHILIPPINES

Online
Kulche
Pluche
Reactions:
Posts: 1016
Joined: Wed Jun 07, 2017 20:28
Plugins: Show
Version: Beta

Re: Cars

Simply write

"needs water":true,
"needs land":false,

I'm not lazy, I'm motivated to do nothing!
...

rjroldan1
Inhabitant of a Megalopolis
Reactions:
Posts: 569
Joined: Mon Jul 17, 2017 16:16
Location: Antipolo, Philippines
Plugins: Show
Contact:

Re: Cars

Kulche wrote:
Thu Jul 27, 2017 8:17
Simply write

"needs water":true,
"needs land":false,

T you
T.P.C.

Theotown Philippine Corporation

PHILIPPINES