Lua Suggestions

Share your ideas about possible future content here.
User avatar
KINGTUT10101
1,000,000 inhabitants
Reactions:
Posts: 2220
Joined: 07 Jul 2016, 22:50
Location: 'Merica
Plugins: Showcase Store
Version: Beta
Contact:

Plugin Creator

Platform

Lua Suggestions

#1

Post by KINGTUT10101 »

City.getWorkers ([type], [level])
Returns the number of industrial or commercial workers in your city. "type" is optional and is used to select which kind of worker you want to count (commercial, industrial). If "type" is left blank, it returns the total number of workers in the city. "level" is also optional and is used to select which level of worker you want to count (0, 1, 2). If "level" is left blank, workers of all levels will be counted.

City.getBuildingsofType (type, [level])
Returns the number of buildings of a specified type. "type" is used to select which building type you want to count (park, health, residential, etc). "level" is optional and is used to select which building level you want to count if the building type is "residential", "commercial", or "industrial" (0, 1, 2)

City.getIncome ()
Returns the current income of the city.

City.getHappiness ([type])
Returns a number between 0 and 1 that reflect the happiness level of your city. "type" is optional and is used to detect specific happiness levels (supply, transportation, etc). If "type" is left blank, the city's overall happiness will be returned instead.

City.getSize ()
Returns the size of the city as a number.
Last edited by KINGTUT10101 on 14 Oct 2019, 04:36, edited 2 times in total.

User avatar
KINGTUT10101
1,000,000 inhabitants
Reactions:
Posts: 2220
Joined: 07 Jul 2016, 22:50
Location: 'Merica
Plugins: Showcase Store
Version: Beta
Contact:

Plugin Creator

Platform

Re: Lua Suggestions

#2

Post by KINGTUT10101 »

I apologise if any of these are already possible. If some of them are possible, let me know how it works please.

User avatar
Bearbear76
Former Bearbear65
Reactions:
Posts: 5730
Joined: 10 Feb 2017, 14:53
Location: L2 cache
Plugins: Showcase Store

Plugin Creator

Platform

Re: Lua Suggestions

#3

Post by Bearbear76 »

Cool ideas!
About happiness would the returned value to 0.54 if the happiness of the specified category is 54%? As you said it would be between 0 to 1

User avatar
KINGTUT10101
1,000,000 inhabitants
Reactions:
Posts: 2220
Joined: 07 Jul 2016, 22:50
Location: 'Merica
Plugins: Showcase Store
Version: Beta
Contact:

Plugin Creator

Platform

Re: Lua Suggestions

#4

Post by KINGTUT10101 »

Yes. I believe that's how the current version of City.getHappiness () works right now.

User avatar
FranchuFranchu
Inhabitant of a Country
Reactions:
Posts: 799
Joined: 28 May 2017, 00:07
Location: Freezing in Argentina
Plugins: Showcase Store
Version: Beta

Plugin Creator

Platform

Re: Lua Suggestions

#5

Post by FranchuFranchu »

for City.getSize() you can do City.getWidth() * City.getHeight()

User avatar
Hadestia
Inhabitant of a Megalopolis
Reactions:
Posts: 727
Joined: 17 Jul 2017, 16:16
Location: Philippines
Plugins: Showcase Store
Contact:

Plugin Creator

Platform

Re: Lua Suggestions

#6

Post by Hadestia »

I suggest to add like:

City.getRegionName(string)
Returns the name of the region currently playing.

These are also helpful as condition for plugins such as:
Plugins can enable if the current Region name returns true specially roleplaying online regions

User avatar
Lobby
Developer
Reactions:
Posts: 3705
Joined: 26 Oct 2008, 12:34
Plugins: Showcase Store
Version: Beta

Platform

Re: Lua Suggestions

#7

Post by Lobby »

KINGTUT10101 wrote:
12 Oct 2019, 20:51
City.getWorkers ([type], [level])
Returns the number of industrial or commercial workers in your city. "type" is optional and is used to select which kind of worker you want to count (commercial, industrial). If "type" is left blank, it returns the total number of workers in the city. "level" is also optional and is used to select which level of worker you want to count (0, 1, 2). If "level" is left blank, workers of all levels will be counted.
Will add these in 1.8.84:
City.getResidentialSpace([level[, progress]])
City.getCommercialJobs([level[, progress]])
City.getIndustrialJobs([level[, progress]])


KINGTUT10101 wrote:
12 Oct 2019, 20:51
City.getBuildingsofType (type, [level])
Returns the number of buildings of a specified type. "type" is used to select which building type you want to count (park, health, residential, etc). "level" is optional and is used to select which building level you want to count if the building type is "residential", "commercial", or "industrial" (0, 1, 2)
Because of the way the game stores buildings I'd recommend the following approach:

Code: Select all

local draftCache = {}
local function countBuldingsOfType(type, level)
  level = level == nil and -1 or level
  local drafts = draftCache[type..':'..level]
  if not drafts then
    drafts = Draft.getDrafts()
        :filter(function(d)
          return d:getType() == type and (level == -1 or d.orig.level - 1 == level)
        end)
    draftCache[type..':'..level] = drafts
  end

  local ctr = 0
  for i=1,#drafts do
    ctr = ctr + City.countBuildings(drafts[i])
  end
  return ctr
end

-- Now you can call e.g.
-- countBuildingsOfType('residential')
-- countBuildingsOfType('commercial', 0)
-- countBuildingsOfType('industrial', 2)
But will also add that in 1.8.84: City.countBuildingsOfType(type[, level])


KINGTUT10101 wrote:
12 Oct 2019, 20:51
City.getIncome ()
Returns the current income of the city.
Will add that as well in 1.8.84:
City.getIncome()


rjroldan1 wrote:
19 Jun 2020, 02:45
I suggest to add like:

City.getRegionName(string)
Returns the name of the region currently playing.

These are also helpful as condition for plugins such as:
Plugins can enable if the current Region name returns true specially roleplaying online regions
Will add these in 1.8.84:
City.getRegionId()
City.getRegionName()



Functions that might be useful in regard to online mode:
City.isOnline()
City.isReadonly()
TheoTown.getUserName()

User avatar
ian`
Supporter
Reactions:
Posts: 117
Joined: 04 Apr 2020, 17:36
Location: Indonesien
Plugins: Showcase Store
Version: Beta

Plugin Creator

Platform

Re: Lua Suggestions

#8

Post by ian` »

Lobby wrote:
19 Jun 2020, 21:27
1884 will be a nice update for Lua. And don't forget to update the doc site too. lol :jb:

User avatar
Hadestia
Inhabitant of a Megalopolis
Reactions:
Posts: 727
Joined: 17 Jul 2017, 16:16
Location: Philippines
Plugins: Showcase Store
Contact:

Plugin Creator

Platform

Re: Lua Suggestions

#9

Post by Hadestia »

How do i collects users name in list using TheoTown.getUserName()?

User avatar
Lobby
Developer
Reactions:
Posts: 3705
Joined: 26 Oct 2008, 12:34
Plugins: Showcase Store
Version: Beta

Platform

Re: Lua Suggestions

#10

Post by Lobby »

It was a typo in the documentation, the function returns exactly one string, or nil if the player is not logged in.

Code: Select all    Reset

local name = TheoTown.getUserName() Debug.toast(name)
Interactive Lua editor
Run

Post Reply Previous topicNext topic

Return to “Suggestions”