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: 2056
Joined: Thu Jul 07, 2016 22:50
Location: 'Merica
Plugins: Show
Version: Beta
Contact:

Platform

Plugin Creator

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`
Townsman
Reactions:
Posts: 77
Joined: Sat Apr 04, 2020 17:36
Location: Indonesien
Plugins: Show
Version: Beta

Platform

Plugin Creator

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)
:fire

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: 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
rjroldan1
Inhabitant of a Megalopolis
Reactions:
Posts: 595
Joined: Mon Jul 17, 2017 16:16
Location: Antipolo, Philippines
Plugins: Show
Contact:

Platform

Plugin Creator

Re: Can I detect a building upgrade through Lua?

#4

Post by rjroldan1 »

KINGTUT10101 wrote:
Thu Jun 25, 2020 2: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
T.P.C.

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

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

Platform

Plugin Creator

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.
ImageJust my opinion

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: 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: 5296
Joined: Fri Feb 10, 2017 14:53
Plugins: Show
Version: Beta

Platform

Plugin Creator

Re: Can I detect a building upgrade through Lua?

#7

Post by Bearbear76 »

KINGTUT10101 wrote:
Thu Jun 25, 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
ImageJust my opinion

Post Reply Previous topicNext topic

Return to “Plug-In Discussion”