## How do I use City.issueDisaster ()?

Plug-in related stuff can be discussed here.

Moderator: Plugin Moderators

KINGTUT10101
1,000,000 inhabitants
Reactions:
Posts: 2109
Joined: Thu Jul 07, 2016 22:50
Location: 'Merica
Plugins: Show
Version: Beta
Contact:

### How do I use City.issueDisaster ()?

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 JustAnyone Rip-off engineer Reactions: Posts: 3097 Joined: Sun Jul 23, 2017 12:45 Location: Easter Island Plugins: Show #### Platform ### Re: How do I use City.issueDisaster ()? 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
Try this

KINGTUT10101
1,000,000 inhabitants
Reactions:
Posts: 2109
Joined: Thu Jul 07, 2016 22:50
Location: 'Merica
Plugins: Show
Version: Beta
Contact:

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

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

ian
Supporter
Reactions:
Posts: 99
Joined: Sat Apr 04, 2020 17:36
Location: Indonesien
Plugins: Show
Version: Beta

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

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.

KINGTUT10101
1,000,000 inhabitants
Reactions:
Posts: 2109
Joined: Thu Jul 07, 2016 22:50
Location: 'Merica
Plugins: Show
Version: Beta
Contact:

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

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.

Lobby
Developer
Reactions:
Posts: 3637
Joined: Sun Oct 26, 2008 12:34
Plugins: Show
Version: Beta

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

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
=^._.^= ∫

KINGTUT10101
1,000,000 inhabitants
Reactions:
Posts: 2109
Joined: Thu Jul 07, 2016 22:50
Location: 'Merica
Plugins: Show
Version: Beta
Contact:

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

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

Lobby
Developer
Reactions:
Posts: 3637
Joined: Sun Oct 26, 2008 12:34
Plugins: Show
Version: Beta

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

Yeah, the documentation is admittedly that that specific in that regard. Thank you for pointing that out, this way we can improve the documentation
=^._.^= ∫

KINGTUT10101
1,000,000 inhabitants
Reactions:
Posts: 2109
Joined: Thu Jul 07, 2016 22:50
Location: 'Merica
Plugins: Show
Version: Beta
Contact:

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

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?

Lobby
Developer
Reactions:
Posts: 3637
Joined: Sun Oct 26, 2008 12:34
Plugins: Show
Version: Beta

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

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
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
=^._.^= ∫`

KINGTUT10101
1,000,000 inhabitants
Reactions:
Posts: 2109
Joined: Thu Jul 07, 2016 22:50
Location: 'Merica
Plugins: Show
Version: Beta
Contact:

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

Thank you for the help! It finally seems to be working now: