How do I use City.issueDisaster ()?

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

How do I use City.issueDisaster ()?

#1

Post by KINGTUT10101 »

I've been trying to use City.issueDisaster () in a Lua-based project of mine, but I can't get it to work. I've been trying to get a building to execute disasters relative to it's position, but nothing happens. The script is attached to a building json using the "script": "myscripthere.lua" variable. Oddly enough, the notification will still activate, even though the disasters do not.

Code: Select all

math.randomseed(os.time())
-- Creates a seed for RNG

local PNI=Draft.getDraft("$anim_people_source01"):getFrame (21)
-- Sets the frame variables


function script.nextDay ()

City.issueDisaster ("DISASTER_RIOT", 1, 0)
City.issueDisaster ("DISASTER_RIOT", -1, 0)
City.issueDisaster ("DISASTER_RIOT", 0, 1)
City.issueDisaster ("DISASTER_RIOT", 0, -1)
City.issueDisaster ("FIRE", 0, 0)
City.showNotification{icon=PNI, id="Riot.notif", showOnce=false, important=true, text="Prison riot!", locationX, locationY}

end

User avatar
JustAnyone
Developer
Reactions:
Posts: 3474
Joined: 23 Jul 2017, 12:45
Location: Easter Island
Plugins: Showcase Store

Platform

Re: How do I use City.issueDisaster ()?

#2

Post by JustAnyone »

Code: Select all    Reset

math.randomseed(os.time()) -- Creates a seed for RNG local PNI=Draft.getDraft("$anim_people_source01"):getFrame (21) -- Sets the frame variables function script.nextDay () City.issueDisaster ("riot", 1, 0) City.issueDisaster ("riot", -1, 0) City.issueDisaster ("riot", 0, 1) City.issueDisaster ("riot", 0, -1) City.issueDisaster ("fire", 0, 0) City.showNotification{icon=PNI, id="Riot.notif", showOnce=false, important=true, text="Prison riot!", locationX, locationY} end
Interactive Lua editor
Run
Try this

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: How do I use City.issueDisaster ()?

#3

Post by KINGTUT10101 »

Thanks for the help. Unfortunately, after trying your code, nothing seemed to change. It still only plays the notification.

User avatar
ian`
Supporter
Reactions:
Posts: 117
Joined: 04 Apr 2020, 17:36
Location: Indonesien
Plugins: Showcase Store
Version: Beta

Plugin Creator

Platform

Re: How do I use City.issueDisaster ()?

#4

Post by ian` »

Riot need road to spawn and fire need building or tree to burn. Even you make it random, if there are no stuff, disaster will not happen.

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: How do I use City.issueDisaster ()?

#5

Post by KINGTUT10101 »

I'm well aware of these conditions and I can assure you, the riots and fires should have all the buildings and roads they need.

User avatar
Lobby
Developer
Reactions:
Posts: 3705
Joined: 26 Oct 2008, 12:34
Plugins: Showcase Store
Version: Beta

Platform

Re: How do I use City.issueDisaster ()?

#6

Post by Lobby »

Documentation of City.issueDisaster

As name of the disasters I suggest to just use the predefined constants like City.DISASTER_FIRE etc. The position provided is absolute so you have to pass the x and y of the context yourself.

Code: Select all    Reset

function script:earlyTap(x, y) City.issueDisaster(City.DISASTER_RIOT, x + 1, y) City.issueDisaster(City.DISASTER_RIOT, x - 1, y) City.issueDisaster(City.DISASTER_RIOT, x, y + 1) City.issueDisaster(City.DISASTER_RIOT, x, y - 1) City.issueDisaster(City.DISASTER_FIRE, x, y) return false -- Prevent it from open dialog for the tile end
Interactive Lua editor
Run

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: How do I use City.issueDisaster ()?

#7

Post by KINGTUT10101 »

Ah, thank you. I'll try this later. I wasn't aware you need to add the prefix to the disaster names as well.

User avatar
Lobby
Developer
Reactions:
Posts: 3705
Joined: 26 Oct 2008, 12:34
Plugins: Showcase Store
Version: Beta

Platform

Re: How do I use City.issueDisaster ()?

#8

Post by Lobby »

Yeah, the documentation is admittedly that that specific in that regard. Thank you for pointing that out, this way we can improve the documentation :lol:

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: How do I use City.issueDisaster ()?

#9

Post by KINGTUT10101 »

You mentioned how the positions are absolute. To make them relative to a building, would I use City.getBuilding () as a part of the location?

User avatar
Lobby
Developer
Reactions:
Posts: 3705
Joined: 26 Oct 2008, 12:34
Plugins: Showcase Store
Version: Beta

Platform

Re: How do I use City.issueDisaster ()?

#10

Post by Lobby »

Well, it depends on where you want to spawn it. You could do something like

Code: Select all    Reset

local x, y = City.getBuilding(1, draft)
Interactive Lua editor
Run
to get the location of the first building of type draft.

But actually, if you want to do it daily for every building of the type your script is attached to the use of script:daily(x, y, level) would be a great choice. That would look like that:

Code: Select all    Reset

function script:daily(x, y) -- Do something with x, y end
Interactive Lua editor
Run

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: How do I use City.issueDisaster ()?

#11

Post by KINGTUT10101 »

Thank you for the help! It finally seems to be working now:
Screenshot_20200723-103550.png

Post Reply Previous topicNext topic

Return to “Plug-In Discussion”