Lua chatbox

The Lua scripting language allows you to give your plugin more advanced features.

Moderator: Plugin Moderators

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

Platform

Re: Lua chatbox

#81

Post by Lobby »

distian wrote:
Wed Jul 01, 2020 19:16
Anyway, that is sometime give you an answer not from the array. :bt
Are you sure?

Regarding your issues with road decorations, how does your exact code look like? Also, overlay is not meant to be used to build stuff, although you can do that :mine
=^._.^= ∫

User avatar
ian`
Townsman
Reactions:
Posts: 77
Joined: Sat Apr 04, 2020 17:36
Location: Indonesien
Plugins: Show
Version: Beta

Platform

Plugin Creator

Re: Lua chatbox

#82

Post by ian` »

Lobby wrote:
Thu Jul 02, 2020 22:41
Are you sure?
This isn't about my script, i'm just replied to commanderABab about my signature, :D
Regarding your issues with road decorations, how does your exact code look like? Also, overlay is not meant to be used to build stuff, although you can do that :mine
I posted it on misc showcase topic. But, this one of the script : download/file.php?id=32420
:fire

User avatar
Bearbear76
Former Bearbear65
Reactions:
Posts: 5296
Joined: Fri Feb 10, 2017 14:53
Plugins: Show
Version: Beta

Platform

Plugin Creator

Re: Lua chatbox

#83

Post by Bearbear76 »

Try putting the Draft.getDraft("Id") in script:init()
ImageJust my opinion

User avatar
Lakan Haraya
Metropolitan
Reactions:
Posts: 116
Joined: Thu Mar 28, 2019 9:34
Location: Rizal, Philippines
Plugins: Show
Version: Beta

Plugin Creator

Platform

Re: Lua chatbox

#84

Post by Lakan Haraya »

Heya

(1) How can I find the tile of a certain building using Script.EVENT_PLACED and using Tile.getBuildingDraft(x,y), I used all of it, I put the id back but still can't find it.

Code: Select all

if event == SCRIPT.EVENT_PLACED and Tile.getBuildingDraft(x,y):getDraft() == "$galleon00" then
  if gllg < 100 then 
   Builder.remove(x,y)
end
end
--rjroldan1
(2) How can I create or trigger a new map that will save in Single Cities, something like the DSA's moon map, and back to the origin city. How variable works between those maps? Can I have a sample lua script for it, if available :mine
"ᜀᜃᜓ ᜀᜅ᜔ ᜁᜌᜓᜅ᜔ ᜑᜇᜌ"
CEO of Haráya Motors

“TheoTown Philippines Council”
“Kapulungan Ng Mga Nagkakaisang Lungsod”

Pinoy? Sali na :jb:
https://discord.gg/9n7PFy

User avatar
JustAnyone
enjenir
Reactions:
Posts: 2962
Joined: Sun Jul 23, 2017 12:45
Location: Easter Island
Plugins: Show

Re: Lua chatbox

#85

Post by JustAnyone »

1) In that case, he's comparing Draft with ID which will never return true
2)

Code: Select all

City.load(file location [str], overwrite the map with same name or not [bool], is available in single cities selection or not [bool], target city name [str])
In DSA's case, it loads an empty map and then other scripts take care of generation.

User avatar
Bearbear76
Former Bearbear65
Reactions:
Posts: 5296
Joined: Fri Feb 10, 2017 14:53
Plugins: Show
Version: Beta

Platform

Plugin Creator

Re: Lua chatbox

#86

Post by Bearbear76 »

Think of Drafts as an JSON object.

Code: Select all

{
  "id": "$example",
  "type": "decoration",
  "width": 1,
  "height": 1,
  ...
}
So think of Tile.getBuildingDraft() as getting the code above. Now can you see why it's not the same as the id?
Now if you want to match ids you would have to add :getId() to get the Id of the draft that was returned by Tile.getBuildingDraft()
ImageJust my opinion

User avatar
ian`
Townsman
Reactions:
Posts: 77
Joined: Sat Apr 04, 2020 17:36
Location: Indonesien
Plugins: Show
Version: Beta

Platform

Plugin Creator

Re: Lua chatbox

#87

Post by ian` »

How to use City.countBuildingsOfType(type[,level])? That's always show me an errors 'call nil'. I see the returns is number and level, then i set 2 variables, but it's still doesn't work.
What is that a typo?
What is that a typo?
:fire

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

Platform

Re: Lua chatbox

#88

Post by Lobby »

Thx, try it with

Code: Select all    Reset

City.countBuldingsOfType()
Interactive Lua editor
Run
instead. Will be fixed in 1.8.91.
=^._.^= ∫

User avatar
ian`
Townsman
Reactions:
Posts: 77
Joined: Sat Apr 04, 2020 17:36
Location: Indonesien
Plugins: Show
Version: Beta

Platform

Plugin Creator

Re: Lua chatbox

#89

Post by ian` »

Can i get an explanation about budgetItem and getCurrency(name)? Are there different functions and types of drafts? How can I make them and show in financial information?
Last edited by ian` on Thu Jul 23, 2020 12:22, edited 1 time in total.
:fire

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

Platform

Plugin Creator

Re: Lua chatbox

#90

Post by rjroldan1 »

Temgamer wrote:
Fri Jun 26, 2020 22:14

Code: Select all

function buildZoneC(zeroX, zeroY, zoneId, radius)
    zeroX = zeroX - radius
    zeroY = zeroY - radius
    local offset = 0
    Builder.buildZone(Draft.getDraft(zoneId), zeroX + offset, zeroY)
    for i=1, (radius * 2 + 1)^2 - 1 do
    if i % (radius * 2 + 1) == 0 then
      zeroY = zeroY + 1
      offset = 0
    else
      offset = offset + 1
    end
    Builder.buildZone(Draft.getDraft(zoneId), zeroX + offset, zeroY)
    end
end
Code underneath runs it, when player builds a building with <id>:

Code: Select all

function script:event(zeroX, zeroY, level, event)
  if event == Script.EVENT_PLACED and Tile.getBuildingDraft(zeroX, zeroY):getId() == "<id> then
    buildZoneC(zeroX, zeroY, "$zonecommercial", 2)
  end
end
Result of build:
Ahotee_20-06-26_23.12.47.png
It also places zone under that building, btw

Wait how to used that <id> cause i test it and nothings happened i think it missed the "getId() = <id>" there .

Also you didn't used variable:"zoneId" from your buildZone function
T.P.C.

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

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

Platform

Plugin Creator

Re: Lua chatbox

#91

Post by rjroldan1 »

Gonna ask again.

Can i use :
Show
code

Code: Select all

local lpeg = required 'lpeg'
for my plugin?, Sorry i just ask in advance cause I can't play right now my phone always shutdown when i startup my theo donno why :),
T.P.C.

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

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

Platform

Plugin Creator

Re: Lua chatbox

#92

Post by KINGTUT10101 »

Can you detect winter mode, weather, and zone demand through Lua?

User avatar
JustAnyone
enjenir
Reactions:
Posts: 2962
Joined: Sun Jul 23, 2017 12:45
Location: Easter Island
Plugins: Show

Re: Lua chatbox

#93

Post by JustAnyone »

Using virtual variables, yes.

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

Platform

Plugin Creator

Re: Lua chatbox

#94

Post by KINGTUT10101 »

What about specific happiness levels, like park happiness?

User avatar
ian`
Townsman
Reactions:
Posts: 77
Joined: Sat Apr 04, 2020 17:36
Location: Indonesien
Plugins: Show
Version: Beta

Platform

Plugin Creator

Re: Lua chatbox

#95

Post by ian` »

I think City.getCommercialJobs and getIndustrialJobs return the wrong values at one level higher of available inhabitant levels.

_20200724_133550.JPG

You can see at the image, com and ind TT are (0), but return from lua are 22 and 50.

_20200724_133538.JPG
It's same at TTT levels, it must be 0, but return from lua are 172 and 409.

TT version 1907
Thanks. :space
:fire

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

Platform

Re: Lua chatbox

#96

Post by Lobby »

@KINGTUT10101 version 1.9.09 will introduce an extra parameter happinessType for City.getHappiness that will allow you to get more specific happiness values.

Using it will look like that:

Code: Select all    Reset

local value = City.getHappiness(City.HAPPINESS_PARK) Debug.toast(value)
Interactive Lua editor
Run


@distian The discrepancy that you've discovered is caused by the fact that the budget view shows the amount of all jobs that are created by buildings of a specific level. Your job numbers differ from that slightly in that even poor commercial places create a few higher level jobs (e.g. the boss of a facility is usually richer than his employees).
=^._.^= ∫

User avatar
ian`
Townsman
Reactions:
Posts: 77
Joined: Sat Apr 04, 2020 17:36
Location: Indonesien
Plugins: Show
Version: Beta

Platform

Plugin Creator

Re: Lua chatbox

#97

Post by ian` »

i think there is a bug in City.getDisaster() functions. it always returned 'fire' no matter what disaster happened.
:fire

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

Platform

Re: Lua chatbox

#98

Post by Lobby »

True, I called the wrong function...
image.png
=^._.^= ∫

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

Platform

Plugin Creator

Re: Lua chatbox

#99

Post by KINGTUT10101 »

@distian
How did you make the corners of this window round here? Is there a specific function for that?
Screenshot_20200728-085703.png

User avatar
ian`
Townsman
Reactions:
Posts: 77
Joined: Sat Apr 04, 2020 17:36
Location: Indonesien
Plugins: Show
Version: Beta

Platform

Plugin Creator

Re: Lua chatbox

#100

Post by ian` »

KINGTUT10101 wrote:
Tue Jul 28, 2020 16:02
@distian
How did you make the corners of this window round here? Is there a specific function for that?
Tbh, i used 5 rectangular layers. 2 layers for the shadow, 2 layers for the brighter color and 1 layer for the base.
:fire

Post Reply Previous topicNext topic

Return to “Lua Scripting”