Page 1 of 1

How do I use City.issueDisaster ()?

Posted: 21 Jul 2020, 20:20
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

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

Posted: 21 Jul 2020, 23:14
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

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

Posted: 22 Jul 2020, 00:53
by KINGTUT10101
Thanks for the help. Unfortunately, after trying your code, nothing seemed to change. It still only plays the notification.

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

Posted: 22 Jul 2020, 09:08
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.

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

Posted: 22 Jul 2020, 17:12
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.

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

Posted: 23 Jul 2020, 09:48
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

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

Posted: 23 Jul 2020, 16:40
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.

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

Posted: 23 Jul 2020, 16:52
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:

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

Posted: 23 Jul 2020, 17:22
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?

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

Posted: 23 Jul 2020, 17:27
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

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

Posted: 23 Jul 2020, 17:36
by KINGTUT10101
Thank you for the help! It finally seems to be working now:
Screenshot_20200723-103550.png