Page 1 of 1

Can I detect a building upgrade through Lua?

Posted: 24 Jun 2020, 19:48
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.

Re: Can I detect a building upgrade through Lua?

Posted: 25 Jun 2020, 01:39
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)

Re: Can I detect a building upgrade through Lua?

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

Re: Can I detect a building upgrade through Lua?

Posted: 25 Jun 2020, 04:22
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

Re: Can I detect a building upgrade through Lua?

Posted: 25 Jun 2020, 13:30
by Bearbear76
The x y values in script:event(x, y, level, event) would be the location of the building.

Re: Can I detect a building upgrade through Lua?

Posted: 25 Jun 2020, 16:20
by KINGTUT10101
So I don't need to provide values for them?

Re: Can I detect a building upgrade through Lua?

Posted: 28 Jun 2020, 04:02
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