Module City

This library contains functions to access and modfiy city information, general buildings and roads.

Functions

alert (actionPlaceType, x, y) Sets an action marker (or removes the one previously set there).
getName () Name of the current city
getFileName () Returns the name of the file of the city.
setName (newName) Sets a new city name
getRotation () Returns the current rotation of the city.
setRotation (r) Sets the rotation of the city
getWidth () Width of the city in tiles
getHeight () Height of the city in tiles
getSeed () Returns the seed that was used to generate the city
getAuthor () Returns the name of the author that the player entered
setAuthor (name) Sets a new author name for the city.
getXp () Returns the amount of xp of the city.
setXp (xp) Sets the amount of xp of the city.
getRank () Returns the current rank draft and the rank index
isSandbox () Determines whether the city is in free or sandbox mode
isReadonly () Indicates whether this city is readonly.
getMoney () Estate of the city
spendMoney (amount[, x[, y[, budgetItem]]]) Spends some money.
earnMoney (amount[, x[, y[, showOverlay=false[, budgetItem]]]]) Earns some money.
getCurrency (name) Returns the available amount of the currency of the given name.
spendCurrency (name, amount) Spends amount of the currency named name.
earnCurrency (name, amount) Earns amount of the currency named name.
getPeople (level) Returns the number of the specified level (0, 1 or 2).
getStorage () Use this storage table to save things city wide
getFunVar (name[, fallbackValue]) Returns the value of the classic fun variable of the given name or fallbackValue if no such variable has been defined, yet.
setFunVar (name, value) Sets the value of a classic fun variable called name.
getTime () Returns the animation time of the game in milliseconds.
getAbsoluteDay () Returns the current absolute day of the city.
getDay () Returns the current day of the month of the city.
getMonth () Returns the current month of the city.
getYear () Returns the current year of the city.
countBuildings ([draft]) Returns the overall amount of buildings.
getBuilding (index[, draft]) Gets the position of a specific building of a specific draft by it's index.
countRoads ([draft]) Returns the overall amount of roads.
getRoad (index[, draft]) Gets the position and level of a specific road (of a specific draft) by it's index.
spawnCar (carDraft, startX, startY, targetX, targetY[, frame]) Spawns a car at a given position / position of a building that drives to the given target / building at the target.
getDisaster () Returns the name of the curretly active disaster or nil if no disaster is is active right now.
issueDisaster (name[, x=-1[, y=-1[, radius=20[, radioactive=true]]]]) Issues the disaster of the given name at the given position x, y.
enableDisaster (name[, state]) Enables or disables the automatic disaster of the given name.
getView () Returns the tile position the camera is currently looking at as well as the current scale.
setView (x, y[, scale]) Sets the view to a specified tile x, y using the provided scale.
save ([enforce=false]) Saves the city if the user has autosave enabled.
load (path[, overwrite[, private[, target]]]) Loads a city file provided by the plugin.
exit ([save=false]) Closes the current city and will go back to region view.
setSpeed (speed) Sets the simulation speed of the city.
getSpeed () Returns the current simulation speed of the city.
setBackground (draft) Sets a background.
getBackground () Returns the current background draft of the city.
getHappiness () Returns the average happiness.
noise (x, y[, z[, w]]) Returns a noise value for the specified coordinates.
getPlayTime () Returns the play time in this city in seconds.
isUber () Returns true if uber is activated for that city.
countCars () Returns number of cars that are active right now.

Fields

DISASTER_FIRE Identifier for fire disaster.
DISASTER_METEOR Identifier for meteorite disaster.
DISASTER_EARTHQUAKE Identifier for earthquake disaster.
DISASTER_NUKE Identifier for nuke disaster.
DISASTER_TORNADO Identifier for tornado disaster.
DISASTER_ILLNESS Identifier for illness disaster.
DISASTER_FLOODING Identifier for flooding disaster.
DISASTER_RIOT Identifier for riot disaster.
DISASTER_CRIME Identifier for crime disaster.
DISASTER_UFO Identifier for ufo disaster.
DISASTER_GREEN_SLIME Identifier for green slime disaster.
DISASTER_PINK_SLIME Identifier for pink slime disaster.
DISASTER_BLIZZARD Identifier for blizzard disaster.
ACTIONPLACE_FIRE Action place for fire alerts.
ACTIONPLACE_POLICE Action place for police alerts.
ACTIONPLACE_MEDIC Action place for medic alerts.
ACTIONPLACE_SWAT Action place for swat alerts.
ACTIONPLACE_GARBAGE Action place for garbage alerts.


Functions

alert (actionPlaceType, x, y)
Sets an action marker (or removes the one previously set there).

Parameters:

  • actionPlaceType integer
  • x integer
  • y integer
getName ()
Name of the current city

Returns:

    string
getFileName ()
Returns the name of the file of the city.

Returns:

    string
setName (newName)
Sets a new city name

Parameters:

  • newName string
getRotation ()
Returns the current rotation of the city. City rotation is expressed with an integer number 0 (unrotated), ..., 3

Returns:

    number {0, 1, 2, 3}
setRotation (r)
Sets the rotation of the city

Parameters:

  • r

Returns:

    number {0, 1, 2, 3}
getWidth ()
Width of the city in tiles

Returns:

    number
getHeight ()
Height of the city in tiles

Returns:

    number
getSeed ()
Returns the seed that was used to generate the city

Returns:

    string
getAuthor ()
Returns the name of the author that the player entered

Returns:

    string
setAuthor (name)
Sets a new author name for the city.

Parameters:

  • name string Name of the author
getXp ()
Returns the amount of xp of the city.

Returns:

    integer
setXp (xp)
Sets the amount of xp of the city.

Parameters:

  • xp integer
getRank ()
Returns the current rank draft and the rank index

Returns:

    draft, integer
isSandbox ()
Determines whether the city is in free or sandbox mode

Returns:

    bool
isReadonly ()
Indicates whether this city is readonly. Cities that are readonly can not be saved. For example foreign cities in online regions are read only.

Returns:

    bool True iff the city is readonly
getMoney ()
Estate of the city

Returns:

    number
spendMoney (amount[, x[, y[, budgetItem]]])
Spends some money. If x, y is specified it will show a red price at that location.

Parameters:

  • amount number
  • x number (optional)
  • y number (optional)
  • budgetItem draft (optional)
earnMoney (amount[, x[, y[, showOverlay=false[, budgetItem]]]])
Earns some money. If x, y is provided (and >= 0) then the money will be drawn as if it was earned at the provided place (green text). If showOverlay is true and overlay for the money will be shown (default is false). Requires privileged rights.

Parameters:

  • amount number
  • x number (optional)
  • y number (optional)
  • showOverlay bool (default false)
  • budgetItem draft (optional)
getCurrency (name)
Returns the available amount of the currency of the given name. E.g. City.getCurreny('bus currency')

Parameters:

  • name string

Returns:

    number, string
spendCurrency (name, amount)
Spends amount of the currency named name.

Parameters:

  • name string
  • amount number
earnCurrency (name, amount)
Earns amount of the currency named name. Requires privileged rights.

Parameters:

  • name string
  • amount number
getPeople (level)
Returns the number of the specified level (0, 1 or 2). Returns the number of all people if no level was specified.

Parameters:

  • level number optional

Returns:

    number
getStorage ()
Use this storage table to save things city wide

Returns:

    table
getFunVar (name[, fallbackValue])
Returns the value of the classic fun variable of the given name or fallbackValue if no such variable has been defined, yet. fallbackValue is 0 by default. Note that fun variables can only contain numbers. Use City.getStorage() or TheoTown.getStorage() to store more fancy stuff. Global fun variables are indicated by a leading ! in it's name.

Parameters:

  • name string
  • fallbackValue number (optional)

Returns:

    number
setFunVar (name, value)
Sets the value of a classic fun variable called name. Note that fun variables can only contain numbers. Use City.getStorage() or TheoTown.getStorage() to store more fancy stuff. Global fun variables are indicated by a leading ! in it's name.

Parameters:

getTime ()
Returns the animation time of the game in milliseconds.

Returns:

    number
getAbsoluteDay ()
Returns the current absolute day of the city.

Returns:

    number
getDay ()
Returns the current day of the month of the city.

Returns:

    number
getMonth ()
Returns the current month of the city.

Returns:

    number
getYear ()
Returns the current year of the city.

Returns:

    number
countBuildings ([draft])
Returns the overall amount of buildings. Optionally of a specific draft. This can for example be used to iterate over all buildings of a draft by using _City.getBuilding(index, draft)_.

Parameters:

  • draft draft A building draft. (optional)

Returns:

    number Amount of buildings.
getBuilding (index[, draft])
Gets the position of a specific building of a specific draft by it's index.

Parameters:

  • index number
  • draft draft (optional)

Returns:

    number, number
countRoads ([draft])
Returns the overall amount of roads. Optionally of a specific draft. This can for example be used to iterate over all roads (of a draft) by using _City.getRoad(index, draft)_.

Parameters:

  • draft draft A road draft. (optional)

Returns:

    number Amount of roads.
getRoad (index[, draft])
Gets the position and level of a specific road (of a specific draft) by it's index.

Parameters:

  • index number
  • draft draft (optional)

Returns:

    number, number, number
spawnCar (carDraft, startX, startY, targetX, targetY[, frame])
Spawns a car at a given position / position of a building that drives to the given target / building at the target. The car will actually not spawned immediately but after a path has been calculated. This happens asynchronously since path calculation is heavy on computation. You can provide a frame to determine the actualy type of the car. It will be random by default.

Parameters:

  • carDraft draft
  • startX number
  • startY number
  • targetX number
  • targetY number
  • frame number (optional)
getDisaster ()
Returns the name of the curretly active disaster or nil if no disaster is is active right now.

Returns:

    string
issueDisaster (name[, x=-1[, y=-1[, radius=20[, radioactive=true]]]])
Issues the disaster of the given name at the given position x, y. Returns true iff disaster was issued successfully.

Parameters:

  • name string
  • x number X position. Random by default. (default -1)
  • y number Y position. Random by default. (default -1)
  • radius number Radius for nuke disaster. (default 20)
  • radioactive bool Radioactivity for nuke disaster. (default true)

Returns:

    bool
enableDisaster (name[, state])
Enables or disables the automatic disaster of the given name.

Parameters:

  • name string
  • state bool true by default. (optional)
getView ()
Returns the tile position the camera is currently looking at as well as the current scale. Format: x, y, scale

Returns:

    number,number,number
setView (x, y[, scale])
Sets the view to a specified tile x, y using the provided scale. If no scale is provided the current scale will be used. Scale 1 means no scaling, 2 times scaling etc.

Parameters:

  • x number
  • y number
  • scale number (optional)
save ([enforce=false])
Saves the city if the user has autosave enabled. If enforce is set the city will even be saved if the user has autosave disabled.

Parameters:

  • enforce bool Whether to enforce saving. (default false)
load (path[, overwrite[, private[, target]]])
Loads a city file provided by the plugin. path is the file of the city file (thus it includes the .city file ending). Prior to loading the city will be copied to maps or private maps folder first (depending on private value). If a city of similar file name already exists at that directory it will be overridden if overwrite flag is set. The target file name can be changed by specifieing a target name.

Parameters:

  • path string
  • overwrite bool (optional)
  • private bool (optional)
  • target string (optional)
exit ([save=false])
Closes the current city and will go back to region view.

Parameters:

  • save bool Whether to save the city before exiting it. (default false)
setSpeed (speed)
Sets the simulation speed of the city. The following values are allowed: `0` for paused `1` for slow `2` for normal `3` for fast `4` for ultra fast

Parameters:

  • speed number One of the values above.

See also:

getSpeed ()
Returns the current simulation speed of the city.

Returns:

    number The speed value.

See also:

setBackground (draft)
Sets a background.

Parameters:

  • draft draft An animation draft or it's id as a string. Use *nil* to set default background.
getBackground ()
Returns the current background draft of the city.

Returns:

    draft
getHappiness ()
Returns the average happiness.

Returns:

    number 0..1 with 1 being happy
noise (x, y[, z[, w]])
Returns a noise value for the specified coordinates.

Parameters:

  • x number
  • y number
  • z number (optional)
  • w number (optional)

Returns:

    number Ranges from -1 to 1
getPlayTime ()
Returns the play time in this city in seconds.

Returns:

    number Time in seconds.
isUber ()
Returns true if uber is activated for that city.

Returns:

    true iff city is uber
countCars ()
Returns number of cars that are active right now. This includes operatonal cars and trains.

Returns:

    number Cars in the city.

Fields

DISASTER_FIRE
Identifier for fire disaster. Used by City.getDisaster and City.issueDisaster.
DISASTER_METEOR
Identifier for meteorite disaster.
DISASTER_EARTHQUAKE
Identifier for earthquake disaster.
DISASTER_NUKE
Identifier for nuke disaster.
DISASTER_TORNADO
Identifier for tornado disaster.
DISASTER_ILLNESS
Identifier for illness disaster.
DISASTER_FLOODING
Identifier for flooding disaster.
DISASTER_RIOT
Identifier for riot disaster.
DISASTER_CRIME
Identifier for crime disaster.
DISASTER_UFO
Identifier for ufo disaster.
DISASTER_GREEN_SLIME
Identifier for green slime disaster.
DISASTER_PINK_SLIME
Identifier for pink slime disaster.
DISASTER_BLIZZARD
Identifier for blizzard disaster.
ACTIONPLACE_FIRE
Action place for fire alerts. Used for action place markers.
ACTIONPLACE_POLICE
Action place for police alerts.
ACTIONPLACE_MEDIC
Action place for medic alerts.
ACTIONPLACE_SWAT
Action place for swat alerts.
ACTIONPLACE_GARBAGE
Action place for garbage alerts.
generated by LDoc 1.4.3 Last updated 2019-10-28 15:18:26