Can I detect a building upgrade through Lua?

Plug-in related stuff can be discussed here.

Moderator: Plugin Moderators

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

Can I detect a building upgrade through Lua?

#1

Post by KINGTUT10101 »

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.
User avatar
ian`
Supporter
Reactions:
Posts: 117
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?

#2

Post by ian` »

I never try that, but there are some functions to detect building upgrades. :bt

Code: Select all

function script:event(x,y,level,event)
if event == Script.EVENT_UPGRADE ...
-- and
Tile.hasBuildingUpgrade(upgradeId,x,y)
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: Can I detect a building upgrade through Lua?

#3

Post by KINGTUT10101 »

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.
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: Can I detect a building upgrade through Lua?

#4

Post by Hadestia »

KINGTUT10101 wrote: 25 Jun 2020, 02:15 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.

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
User avatar
Bearbear76
Former Bearbear65
Reactions:
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?

#5

Post by Bearbear76 »

The x y values in script:event(x, y, level, event) would be the location of the building.
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: Can I detect a building upgrade through Lua?

#6

Post by KINGTUT10101 »

So I don't need to provide values for them?
User avatar
Bearbear76
Former Bearbear65
Reactions:
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?

#7

Post by Bearbear76 »

KINGTUT10101 wrote: 25 Jun 2020, 16:20 So I don't need to provide values for them?
Yes, I wrote something about functions if you want to take a look: viewtopic.php?p=161342#p161342
Post Reply Previous topicNext topic

Return to “Plug-In Discussion”