Cars

Learn here how to create and use plugins.

Moderator: Plugin Moderators

User avatar
Lobby
Developer
Reactions:
Posts: 3332
Joined: Sun Oct 26, 2008 12:34
Plugins: Show
Version: Beta
Phone model: S7 edge

Platform

Cars

#1

Post by Lobby » Fri Apr 28, 2017 12:25

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
So our actual image carsample.png may look like this:
Image
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
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 "" 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
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 » Wed May 03, 2017 14:26

can i get the TV car id please

User avatar
Lobby
Developer
Reactions:
Posts: 3332
Joined: Sun Oct 26, 2008 12:34
Plugins: Show
Version: Beta
Phone model: S7 edge

Platform

#3

Post by Lobby » Wed May 03, 2017 21:28

It's just $cartv00 :)

User avatar
Lobby
Developer
Reactions:
Posts: 3332
Joined: Sun Oct 26, 2008 12:34
Plugins: Show
Version: Beta
Phone model: S7 edge

Platform

#4

Post by Lobby » Wed May 31, 2017 0:19

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: 1886
Joined: Thu Jul 07, 2016 22:50
Location: 'Merica
Plugins: Show
Version: Beta
Phone model: Moto Z Force Droid

Platform

#5

Post by KINGTUT10101 » Thu Jun 08, 2017 2:24

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

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

Platform

Plugin Creator

#6

Post by CommanderABab » Thu Jun 08, 2017 5:05

You may create new ones with new ids.
Last edited by CommanderABab on Thu Jun 08, 2017 8:16, edited 1 time in total.
746!746Currently using beta 746. 746 What's new? :)
lit trfc lights!!
:)

Telegram - t.me/
🆎️🆎️🆎️🆎️Commander🆎️🆎️

User avatar
KINGTUT10101
1,000,000 inhabitants
Reactions:
Posts: 1886
Joined: Thu Jul 07, 2016 22:50
Location: 'Merica
Plugins: Show
Version: Beta
Phone model: Moto Z Force Droid

Platform

#7

Post by KINGTUT10101 » Thu Jun 08, 2017 6:05

Is there a way to make cars not despawn?

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

Platform

Plugin Creator

#8

Post by CommanderABab » Thu Jun 08, 2017 8:19

Maybe give them a high capacity.
746!746Currently using beta 746. 746 What's new? :)
lit trfc lights!!
:)

Telegram - t.me/
🆎️🆎️🆎️🆎️Commander🆎️🆎️

User avatar
Lobby
Developer
Reactions:
Posts: 3332
Joined: Sun Oct 26, 2008 12:34
Plugins: Show
Version: Beta
Phone model: S7 edge

Platform

#9

Post by Lobby » Thu Jun 08, 2017 8:47

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: 3332
Joined: Sun Oct 26, 2008 12:34
Plugins: Show
Version: Beta
Phone model: S7 edge

Platform

Re: Cars

#10

Post by Lobby » Wed Jul 05, 2017 23:09

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
...Have a nice stay

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

Platform

Plugin Creator

Re: Cars

#11

Post by CommanderABab » Wed Jul 05, 2017 23:10

Nice!
746!746Currently using beta 746. 746 What's new? :)
lit trfc lights!!
:)

Telegram - t.me/
🆎️🆎️🆎️🆎️Commander🆎️🆎️

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

Platform

Re: Cars

#12

Post by Barky » Wed Jul 05, 2017 23:19

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

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

Platform

Plugin Creator

Re: Cars

#13

Post by CommanderABab » Wed Jul 05, 2017 23:45

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":[""]
  }
]
746!746Currently using beta 746. 746 What's new? :)
lit trfc lights!!
:)

Telegram - t.me/
🆎️🆎️🆎️🆎️Commander🆎️🆎️

User avatar
Lobby
Developer
Reactions:
Posts: 3332
Joined: Sun Oct 26, 2008 12:34
Plugins: Show
Version: Beta
Phone model: S7 edge

Platform

Re: Cars

#14

Post by Lobby » Thu Jul 06, 2017 9:36

Exactly :)
...Have a nice stay

User avatar
danekbel
Inhabitant of a Galaxy Cluster
Reactions:
Posts: 2773
Joined: Thu May 05, 2016 9:33
Location: in your dreams
Plugins: Show
Version: Beta

Platform

Plugin Creator

Re: Cars

#15

Post by danekbel » Sat Jul 08, 2017 22:04

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 » Tue Jul 25, 2017 17:52

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: 3332
Joined: Sun Oct 26, 2008 12:34
Plugins: Show
Version: Beta
Phone model: S7 edge

Platform

Re: Cars

#17

Post by Lobby » Tue Jul 25, 2017 18:59

Here some graphics:
yacht_green.png
yacht_green.png (993 Bytes) Viewed 5182 times
yacht_blue.png
yacht_blue.png (967 Bytes) Viewed 5182 times
ship.png
ship.png (5.67 KiB) Viewed 5182 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.
...Have a nice stay

User avatar
rjroldan1
Inhabitant of a Conurbation
Reactions:
Posts: 462
Joined: Mon Jul 17, 2017 16:16
Location: philippines
Plugins: Show
Version: Beta
Contact:

Platform

Plugin Creator

Re: Cars

#18

Post by rjroldan1 » Thu Jul 27, 2017 8:09

how to make a decoration that place in water?
Silent

President of Metropole region

____________________________________________________________________________________
I LOVE PHILIPPINES

User avatar
Kulche
Inhabitant of a Country
Reactions:
Posts: 932
Joined: Wed Jun 07, 2017 20:28
Location: 50M3WH3R3
Plugins: Show
Version: Beta

Platform

Plugin Creator

Re: Cars

#19

Post by Kulche » Thu Jul 27, 2017 8:17

Simply write

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

8-)
I'm not lazy, I'm on battery saving mode!

User avatar
rjroldan1
Inhabitant of a Conurbation
Reactions:
Posts: 462
Joined: Mon Jul 17, 2017 16:16
Location: philippines
Plugins: Show
Version: Beta
Contact:

Platform

Plugin Creator

Re: Cars

#20

Post by rjroldan1 » Thu Jul 27, 2017 10:08

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

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

8-)
T you
Silent

President of Metropole region

____________________________________________________________________________________
I LOVE PHILIPPINES

Post Reply Previous topicNext topic

Return to “Tutorials and Documentation”

Who is online

Users browsing this forum: No registered users and 3 guests