Cars

Learn here how to create and use plugins.

Moderator: Plugin Moderators

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

Platform

Cars

#1

Post by Lobby »

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:
image.png
image.png (3.11 KiB) Viewed 499 times
So our actual image carsample.png may look like this:
image.png
image.png (1007 Bytes) Viewed 499 times
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:
image.png
image.png (638 Bytes) Viewed 499 times
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"],
        "radius":10,
        "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:
image.png
image.png (22.64 KiB) Viewed 499 times
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

#2

Post by Sometheotown mayor »

can i get the TV car id please

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

Platform

#3

Post by Lobby »

It's just $cartv00 :)

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

Platform

#4

Post by Lobby »

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

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

Platform

Plugin Creator

#5

Post by KINGTUT10101 »

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

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

Platform

Plugin Creator

#6

Post by CommanderABab »

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

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

Platform

Plugin Creator

#7

Post by KINGTUT10101 »

Is there a way to make cars not despawn?

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

Platform

Plugin Creator

#8

Post by CommanderABab »

Maybe give them a high capacity.
Image

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

Platform

#9

Post by Lobby »

Cars spawned by a specific building will normally not despawn if they always find a way. Normals cars like $carres00 will despawn by design.

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

Platform

Re: Cars

#10

Post by Lobby »

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. :space
=^._.^= ∫

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

Platform

Plugin Creator

Re: Cars

#11

Post by CommanderABab »

Nice!
Image

Barky
TheoTown Cartographer
Reactions:
Posts: 2074
Joined: Mon Apr 17, 2017 22:13
Location: Ireland
Plugins: Show

Platform

Re: Cars

#12

Post by Barky »

Hmm maybe I'll try have a go with my plug-in again

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

Platform

Plugin Creator

Re: Cars

#13

Post by CommanderABab »

QuestionI have a question in the comment below

Code: Select all

"car spawner":[
  {
    "cars":["ped.dusko.1"],
    "count":4,
    "radius":25,
    // do the targets go here?
    "targets":[""]
  }
]
Image

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

Platform

Re: Cars

#14

Post by Lobby »

Exactly :)
=^._.^= ∫

User avatar
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

#15

Post by danekbel »

Can I still override existing cars?
some text.

User avatar
actemendes
Metropolitan
Reactions:
Posts: 131
Joined: Fri Jan 20, 2017 16:53
Location: Russia
Plugins: Show

Platform

Re: Cars

#16

Post by actemendes »

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.Theo of tomorrow in developing.

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

Platform

Re: Cars

#17

Post by Lobby »

Here some graphics:
yacht_green.png
yacht_green.png (993 Bytes) Viewed 8293 times
yacht_blue.png
yacht_blue.png (967 Bytes) Viewed 8293 times
ship.png
ship.png (5.67 KiB) Viewed 8293 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.
=^._.^= ∫

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

Platform

Plugin Creator

Re: Cars

#18

Post by rjroldan1 »

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

Theotown Philippine Corporation
╔═╗─────────────╔╗────────
║╬║─╔╗╔╦╗╔═╗╔╗─╔╝║╔═╗─╔═╦╗
║╗╣─╠╣║╔╝║╬║║╚╗║╬║║╬╚╗║║║║
╚╩╝╔╝║╚╝─╚═╝╚═╝╚═╝╚══╝╚╩═╝
───╚═╝────────────────────

User avatar
Kulche
Pluche
Reactions:
Posts: 1042
Joined: Wed Jun 07, 2017 20:28
Plugins: Show
Version: Beta

Plugin Creator

Platform

Re: Cars

#19

Post by Kulche »

Simply write

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

8-)
I'm not lazy, I'm motivated to do nothing!
...blame lobby for that

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

Platform

Plugin Creator

Re: Cars

#20

Post by rjroldan1 »

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

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

8-)
T you
T.P.C.

Theotown Philippine Corporation
╔═╗─────────────╔╗────────
║╬║─╔╗╔╦╗╔═╗╔╗─╔╝║╔═╗─╔═╦╗
║╗╣─╠╣║╔╝║╬║║╚╗║╬║║╬╚╗║║║║
╚╩╝╔╝║╚╝─╚═╝╚═╝╚═╝╚══╝╚╩═╝
───╚═╝────────────────────

Post Reply Previous topicNext topic

Return to “Tutorials and Documentation”