Stormworks: Build and Rescue

Stormworks: Build and Rescue

Zizo Natural Disaster Announcements [+ Radio]
Zizo  [developer] 10 Feb, 2022 @ 6:04am
Script
g_savedata = { disasters = {}, notify = property.checkbox("Notify", true), draw_map = property.checkbox("Draw on map", true), radio = property.checkbox("Radio broadcasting", true), radio_frequency = property.slider("Radio broadcasting channel", 5001, 9950, 1, 4566) } local timer = 0 local addon_index = 0 local location_index = 0 local component_id = 0 function onCreate(is_world_create) addon_index = server.getAddonIndex() location_index = server.getLocationIndex(addon_index, "radio_broadcaster") local location_data = server.getLocationData(addon_index, location_index) local component_data = server.getLocationComponentData(addon_index, location_index, location_data.component_count) component_id = component_data.id end function onTick(delta_worldtime) if timer <= 0 then timer = 60 * 10 for id, disaster in pairs(g_savedata.disasters) do if disaster.time <= 0 then if disaster.marker_ui_id then server.removeMapObject(-1, disaster.marker_ui_id) end if disaster.vehicle_id then server.despawnVehicle(disaster.vehicle_id, true) end g_savedata.disasters[id] = nil else if not disaster.marker_ui_id then disaster.marker_ui_id = server.getMapID() if g_savedata.notify then server.notify(-1, "Warning: Extreme weather", disaster.desc,1) end if g_savedata.draw_map then server.addMapObject(-1, disaster.marker_ui_id, 0, 8, disaster.transform[13], disaster.transform[15], 0, 0, 0, 0, "Warning: Extreme weather", disaster.size, disaster.desc, 200, 100, 0, 255) end if g_savedata.radio then local broadcast_transform = disaster.transform broadcast_transform[14] = -350 local component = server.spawnAddonComponent(broadcast_transform, addon_index, location_index, component_id) disaster.vehicle_id = component.id end end disaster.time = disaster.time - timer end end else timer = timer - 1 end end function onVehicleLoad(vehicle_id) for _, disaster in pairs(g_savedata.disasters) do if vehicle_id == disaster.vehicle_id then server.setVehicleKeypad(vehicle_id, "radio_frequency", g_savedata.radio_frequency) server.setVehicleKeypad(vehicle_id, "disaster_type", disaster.type) server.setVehicleKeypad(vehicle_id, "disaster_magnitude", disaster.magnitude) break end end end function onTornado(transform) table.insert(g_savedata.disasters, { transform=transform, time=60*60*4, size=1000, magnitude=10, type=1, desc="Extreme wind has been detected on location." }) end function onTsunami(transform, magnitude) table.insert(g_savedata.disasters, { transform=transform, time=60*60*5, size=3000+3000*magnitude, magnitude=magnitude*12, type=2, desc="Seismic activity has caused large scale ocean displacement, a tsunami warning has been issued. Magnitude ".. math.floor(magnitude*12*100)/100 }) end function onWhirlpool(transform, magnitude) table.insert(g_savedata.disasters, { transform=transform, time=60*60*6, size=250+250*magnitude, magnitude=magnitude*12, type=3, desc="Tectonic disruptions to the seabed are causing unpredictable water currents. Magnitude ".. math.floor(magnitude*12*100)/100 }) end function onMeteor(transform, magnitude) table.insert(g_savedata.disasters, { transform=transform, time=60*60*1, size=1000, magnitude=magnitude*10, type=4, desc="Nearby weather stations have detected an incoming impact event. Magnitude ".. math.floor(magnitude*10*100)/100 }) end function onVolcano(transform) table.insert(g_savedata.disasters, { transform=transform, time=60*60*2, size=2000, magnitude=8, type=5, desc="Seismic activity in the area has triggered a volcanic response." }) end
Last edited by Zizo; 3 Jul, 2023 @ 3:06pm
< >
Showing 1-10 of 10 comments
Seraph 12 Feb, 2022 @ 12:58am 
ok cool
the 12 Feb, 2022 @ 8:11am 
what da f--- does that mean
looks cool not gonna try it even!
SIMPLE MARK 13 Feb, 2022 @ 11:09am 
Nice implementation, could not improve much on it!
Mökki 13 Feb, 2022 @ 1:38pm 
Clear, short and as basic as it needs to be. Couldn't do it better!
RadialVolcano27 8 Jun, 2023 @ 8:44pm 
I'm making an addon that is pretty much this but codded it all myself (I had to use this code to help me a little with the timer part though), and I was wondering if I'm allowed to put it on the workshop when it's done?
Zizo  [developer] 3 Jul, 2023 @ 4:01am 
Originally posted by RadialVolcano27:
I'm making an addon that is pretty much this but codded it all myself (I had to use this code to help me a little with the timer part though), and I was wondering if I'm allowed to put it on the workshop when it's done?
sure, no problem
TomMaverick 4 Jul, 2023 @ 9:24am 
Hi!
Im getting a message in chat when I start a game with this addon.


.../2749036818/playlist
21: attempt to index a nil value (local 'component_data')

Screenshot [i.imgur.com]

Already tried to ?reload_scripts but I get the same message.


Edit:
This seems to happen only in Career and Classic Career mode.

Edit 2: Nope sry my error! The message pops up in Custom as well. But the Addon seems to work regardless.



Thanks for all the addons you make! <3
Last edited by TomMaverick; 4 Jul, 2023 @ 10:02am
Zizo  [developer] 4 Jul, 2023 @ 11:15am 
Originally posted by TomMaverick:
Hi!
Im getting a message in chat when I start a game with this addon.


.../2749036818/playlist
21: attempt to index a nil value (local 'component_data')

Screenshot [i.imgur.com]

Already tried to ?reload_scripts but I get the same message.


Edit:
This seems to happen only in Career and Classic Career mode.

Edit 2: Nope sry my error! The message pops up in Custom as well. But the Addon seems to work regardless.



Thanks for all the addons you make! <3
Hello TomMaverick,

thanks for reporting the issue, I am already uploading a fix, the addon worked the same weirdly enough but now it doesn't print an error.
Daquan Baton 8 Apr, 2024 @ 8:12pm 
Everything works pretty good, up until the mod experiences an error and causes the siren in one location to play constantly.

This is the error I'm getting:
22: attempt to index a nil value (local 'location data')
< >
Showing 1-10 of 10 comments
Per page: 1530 50