Can I detect a building upgrade through Lua?
Moderators: Scenario Moderators, Plugin Moderators
- KINGTUT10101
- 1,000,000 inhabitants
- Posts: 2227
- Joined: 07 Jul 2016, 22:50
- Location: 'Merica
- Plugins: Showcase Store
- Version: Beta
- Contact:
-
Plugin Creator
Platform
Can I detect a building upgrade through Lua?
Hello,
I am wondering if you can detect building upgrades through Lua. I know you can detect certain buildings through Draft.getDraft (""), but I would like to know if this would work with upgrades, or if there's another equivalent.
I am wondering if you can detect building upgrades through Lua. I know you can detect certain buildings through Draft.getDraft (""), but I would like to know if this would work with upgrades, or if there's another equivalent.
- ian`
- Supporter
- Posts: 118
- Joined: 04 Apr 2020, 17:36
- Location: Indonesien
- Plugins: Showcase Store
- Version: Beta
-
Plugin Creator
Platform
Re: Can I detect a building upgrade through Lua?
I never try that, but there are some functions to detect building upgrades.

Code: Select all
function script:event(x,y,level,event)
if event == Script.EVENT_UPGRADE ...
-- and
Tile.hasBuildingUpgrade(upgradeId,x,y)
- KINGTUT10101
- 1,000,000 inhabitants
- Posts: 2227
- Joined: 07 Jul 2016, 22:50
- Location: 'Merica
- Plugins: Showcase Store
- Version: Beta
- Contact:
-
Plugin Creator
Platform
Re: Can I detect a building upgrade through Lua?
How would I know the location of the building though? It seems like you'd have to know that for this to work. Also, I need to check this for these upgrades on every frame.
- Hadestia
- Inhabitant of a Megalopolis
- Posts: 727
- Joined: 17 Jul 2017, 16:16
- Location: Philippines
- Plugins: Showcase Store
- Contact:
-
Plugin Creator
Platform
Re: Can I detect a building upgrade through Lua?
KINGTUT10101 wrote: ↑25 Jun 2020, 02:15How would I know the location of the building though? It seems like you'd have to know that for this to work. Also, I need to check this for these upgrades on every frame.
Im not sure but try this
Code: Select all
local draft = Draft.getDraft("Draft")
function script:event(x,y,level,event)
if event == Script.EVENT_UPGRADE and Tile.getBuildingDraft(x,y) == draft and Tile.hasBuildingUpgrade(x,y) then
-- other stuff
end
- Bearbear76
- Former Bearbear65
- Posts: 5730
- Joined: 10 Feb 2017, 14:53
- Location: L2 cache
- Plugins: Showcase Store
-
Plugin Creator
Platform
Re: Can I detect a building upgrade through Lua?
The x y values in script:event(x, y, level, event) would be the location of the building.
- KINGTUT10101
- 1,000,000 inhabitants
- Posts: 2227
- Joined: 07 Jul 2016, 22:50
- Location: 'Merica
- Plugins: Showcase Store
- Version: Beta
- Contact:
-
Plugin Creator
Platform
Re: Can I detect a building upgrade through Lua?
So I don't need to provide values for them?
- Bearbear76
- Former Bearbear65
- Posts: 5730
- Joined: 10 Feb 2017, 14:53
- Location: L2 cache
- Plugins: Showcase Store
-
Plugin Creator
Platform
Re: Can I detect a building upgrade through Lua?
Yes, I wrote something about functions if you want to take a look: viewtopic.php?p=161342#p161342