Jump to content
CorinaMarie

CoriBoom Lua Coding to Trigger Multiple Game Effects (Such as Disasters)

Cyclone Boom

Please Note:
Cori's discovery detailed in this topic was originally posted in the Oddities thread, but is split to here for clarity of discussion.

Message added by Cyclone Boom

52 posts in this topic Last Reply

Highlighted Posts

Posted:
Last Online:  
 

Something probably not useful, but might be cool  (maybe)

Today Cori has been experimenting further to see whether the remaining effects in the EffectDir could prove useful. Here's one called eroding which stood out not particularly for usefulness, but what we felt was quite cool to see in the game. Adding an Erosion Simulation trigger which can be run the same way.

Like so from the news popup:

Lua Erosion Simulation - News Popup Option.jpg

 

And then over time the eroding proceeds to randomly erode the terrain in sections every 20 seconds:

Lua-Erosion-Simulation

Techy Note:
The animation uses the modern WebP image format which has an advantage of smaller file sizes and higher compression.
If it doesn't play in your browser though, view the GIF here. (4.70 MB)

 

The erosion effect can be set in the first function if wanting to test this for yourselves:

sc4game.effects.create_effect("eroding", 512, 270, 512)


Just be sure to check Cori's post on the prior page for the full walk-through of the editing steps for things to try tweaking and testing. If set as multiple in the 2nd function with multiple loops, it performs essentially like the Erode tool in God Mode does. Now of course, the limitation of this for terraforming is for matching tile borders, and also it'd only be usable immediately after establishing a tile. Otherwise it'd be like a giant's footprints treading through one's city as a new disaster type! :O


This with the erosion is merely something that we figured would be worth posting about as a small extra discovery. *;)

So primarily we believe whatever y'all come up with for expanding the meadow fire generation will likely be the best use of these effects. A possible prospect is to expand the menu items with your discoveries so there can be a range of thresholds for triggering them.

The ability to have the appearance of natural randomness is the main usefulness.

-CB & Cori

  • Like 3
  • Thanks 1

Quick Links

“SimCity 4 is not just a game, but a tool driven by our own imagination and creativity.”

Buy me a coffee

Share this post


Link to post
Share on other sites
Posted:
Last Online:  
 
21 hours ago, Cyclone Boom said:

The animation uses the modern WebP image format which has an advantage of smaller file sizes and higher compression.

So can I use WebP as a replacement for my PNG files here in ST instead of JPG?

Share this post


Link to post
Share on other sites
Posted:
Last Online:  
 
37 minutes ago, chfzdn said:

So can I use WebP as a replacement for my PNG files here in ST instead of JPG?

Good question!
 

Spoiler

At present I recommend not yet as a replacement. *;)

JPGs are ideal for posting gameplay pics, and I did a bit of research on this yesterday to find how WebP is supported by ~80% of browsers at the moment. So the compatibility is growing all the time, and it seems like this and also APNG will be more commonly used looking ahead. Here on the ST board software, it doesn't yet consider these newer formats as images when uploading as attachments, and so it's best keeping to JPGs and PNGs (for simple graphical images).

For animations like we created in the post above, this could be where WebP is useful right now. It made a 12 MB GIF become 1.5 MB with no noticeable quality reduction between frames. And in fact, the quality of the animation is less grainy too with GIFs only supporting 256 colours.

So if wanting to upload a WebP animation, we can arrange them directly uploaded to the server so they can be pasted in and displayed as images.

(It's possible hosting services like Imgur support these too, although I'm not too sure about that.)

 

  • Like 2

Quick Links

“SimCity 4 is not just a game, but a tool driven by our own imagination and creativity.”

Buy me a coffee

Share this post


Link to post
Share on other sites
Posted:
Last Online:  
 

@Cyclone Boom Oh, I don't and never think that it's not useful, CB, I haven't got time on experiencing, whereas I thought we can do sth more precisely with code. for example, I knew that flattening the Shoreline isn't an easy work, and also other terrain formatting works, but it would be easy with code,IMO.*:8) and also with random and cos/sin/tan functions we can create natural stuffs as Barton wishes.

Who says it's useless?*:D

  • Like 3

What is impossible with men is possible with God…!

5d9ffb6b62888_-1.jpg.d47b771d09c95f9e7590c44cf6711098.jpg

I've contributed some to Simtropolis

My Emotion

Share this post


Link to post
Share on other sites
  • Original Poster
  • Posted:
    Last Online:  
     
    6 hours ago, Raymond7cn said:

    I knew that flattening the Shoreline isn't an easy work, and also other terrain formatting works, but it would be easy with code,IMO.*:8) 

    With the method in this thread, we are limited to random coordinates (in whatever calculated groups we want) for where we place the effects or to specific ones we set ourselves.

    We don't have access to the terrain data map table itself to know where the shoreline is. We cannot (via Lua code) even know if a location is over land or water. This means we cannot tell the code to place effects where the terrain meets some criteria such as 0.1 to 3 meters above the sea level.

    • Like 1
    • Thanks 2

    Chance favors the prepared mind. ― Louis Pasteur  
    Remember, a few hours of trial and error can save you several minutes of looking at the README. -- I Am Devloper (on Twitter)

    Clickable ---> The Best of Cori's Posts  (scroll down a wee bit there)    Something fun: MySimtropolis - Invitation to become a SimCity 4 MySim

    Are you new here? Check out the Introduction and Guide to Simtropolis.

    Share this post


    Link to post
    Share on other sites
    Posted:
    Last Online:  
     

    Question... In theory, could this be used in conjunction with a ploppable lot to trigger disasters on a random basis in Mayor Mode?  It's always bothered me how SC4 broke with series conventions by not doing randomly triggered disasters (with an opt-out option), and seeking a way to get that back has always been one of my white whales for this game.

    Share this post


    Link to post
    Share on other sites
  • Original Poster
  • Posted:
    Last Online:  
     
    21 minutes ago, shoptroll said:

    Question... In theory, could this be used in conjunction with a ploppable lot to trigger disasters on a random basis in Mayor Mode?

    Answer... Yes, indeed. *:ohyes:

    The Lua could be coded so every possible disaster we can trigger could be based on the presence of a particular plopped reward lot being present. Then per disaster the code could also assign a random chance per month. An existing Maxis function allows that to be generated between 1 and 100%, but if that seems too much a new function could be written to allow less than 1% per month (but more than zero). Also, the disasters could be coded to count the number of that specific plop and adjust accordingly. Like say you set tornado to be ¼% per month and then have that be additive per plop so if there's 4 of them in the city, the chance increases to 1%. Or six of them would yield 1½% chance.

    You could also have more than one different trigger building so if one is for all disasters then another might only be for meteors and fires. And so forth.

    It'd really only be limited by your imagination and how much time you'd spend writing the Lua code.

    • Like 3

    Chance favors the prepared mind. ― Louis Pasteur  
    Remember, a few hours of trial and error can save you several minutes of looking at the README. -- I Am Devloper (on Twitter)

    Clickable ---> The Best of Cori's Posts  (scroll down a wee bit there)    Something fun: MySimtropolis - Invitation to become a SimCity 4 MySim

    Are you new here? Check out the Introduction and Guide to Simtropolis.

    Share this post


    Link to post
    Share on other sites
    Posted:
    Last Online:  
     

    Just wondering do fires and riots created by this function get "snuffed out" by fire and police stations? Also by ANY disaster does that include toxic spills and a powerplant explosion (standard or nuclear{if powerplant explosions count as disasters in the first place of course^_^})

    • Like 1

    Known as LeonardMT everywhere else

    Share this post


    Link to post
    Share on other sites
  • Original Poster
  • Posted:
    Last Online:  
     
    10 hours ago, Leo -- said:

    Just wondering do fires and riots created by this function get "snuffed out" by fire and police stations?

    As it happens I've modified the Flame Simulator exemplar for my game such that I can have random fires which the fire stations do not auto-suppress and so I don't know if they would be put out in the vanilla version. My guess is yes, but you could test it in your game to see. (Refrain from saving the city tile after the disaster unless you do want to rebuild from the probable resulting chaos.)

    I personally never intended to use this method in any of my play cities (other than for the initial pics). What really did intrigue me is @BartonThinks's fires to create meadows in his Seasonal Trees & Flora: Shortcuts for Beginners & Lazy Landscapers tutorial. As you see back on page 1, that was really the focus where I tweaked for a couple or three days to get the random sized fire splotches.

     

    10 hours ago, Leo -- said:

    Also by ANY disaster does that include toxic spills and a powerplant explosion

    As best I can tell, the Lua function sc4game.effects.create_effect works only with the ones defined in the EffectDir, Section 13. See the file I attached:

    On 6/8/2021 at 8:40 PM, CorinaMarie said:

    I'll attach that as a text file in case you want it the easy way: EffectDir Section 13 Effect Names List.txt

     

    I did try: sc4game.effects.create_effect("toxicwaste", 150, 267, 276) which appears for a while then fades away so it doesn't trigger as a disaster like the fires do. The word toxic is in that list 13 times, so you could test each of them and see if any are the full blown disaster. The toxic_spill one would be my guess as the most likely candidate.

    For power plant explosions, I did test a few of their effects and some do create a range of crater sizes (and iirc, fires). They are not targeted at any specific power plant since this method simply calls the effect at a specified location. Ofc, one could code the Lua with the random chance in which the known coordinates of each power plant are specified, but that would require you to find each location using the terrain query to add them to the code.

    There's no way I know to have the code find the power plants on its own.

    OTOH, a random chance for an explosion could possibly be tied to an advisor message like for a strike or a specific power plant being underfunded and then have that do the explosion. The way this works is the game does know the location of the subject of popup messages and maybe that could tied to where to have the explosion take place. If you look in our code of the Hospital Pockets Picked and Other FUN Dialog Boxes (both the Lua and the LText), you can see how we use the game.event_subject() as part of the parameters passed to the game.camera_jump_and_zoom function. That'd be a good place to start to see if it could be used with the event trigger for these disasters.

    • Like 2

    Chance favors the prepared mind. ― Louis Pasteur  
    Remember, a few hours of trial and error can save you several minutes of looking at the README. -- I Am Devloper (on Twitter)

    Clickable ---> The Best of Cori's Posts  (scroll down a wee bit there)    Something fun: MySimtropolis - Invitation to become a SimCity 4 MySim

    Are you new here? Check out the Introduction and Guide to Simtropolis.

    Share this post


    Link to post
    Share on other sites
    Posted:
    Last Online:  
     
    3 hours ago, CorinaMarie said:

    I did try: sc4game.effects.create_effect("toxicwaste", 150, 267, 276) which appears for a while then fades away so it doesn't trigger as a disaster like the fires do.

    Yeah that can happen with toxic spills triggered by UDI sometimes.

    3 hours ago, CorinaMarie said:

    OTOH, a random chance for an explosion could possibly be tied to an advisor message like for a strike or a specific power plant being underfunded and then have that do the explosion. The way this works is the game does know the location of the subject of popup messages and maybe that could tied to where to have the explosion take place. If you look in our code of the Hospital Pockets Picked and Other FUN Dialog Boxes (both the Lua and the LText), you can see how we use the game.event_subject() as part of the parameters passed to the game.camera_jump_and_zoom function. That'd be a good place to start to see if it could be used with the event trigger for these disasters.

    Now that interesting I always wanted to send my riot police to strikes to beat some sense into them:evil::evil::evil::evil::evil::evil:especially because I have all my funds on 120%

    Is it possible to spawn a riot rather then strike or is it only possible to spawn a riot with a strike?


    Known as LeonardMT everywhere else

    Share this post


    Link to post
    Share on other sites
  • Original Poster
  • Posted:
    Last Online:  
     
    4 minutes ago, Leo -- said:

    Is it possible to spawn a riot rather then strike or is it only possible to spawn a riot with a strike?

    From what I've seen, the start of a riot is controlled internally rather than via any Lua code. Said Lua only reacts to the start of a riot and then allows jumping to it and/or dispatching police.

    You can use the UncivilDisobedience cheat if you install: Simmaster's Extra Cheats DLL to spawn a riot. *;)

    • Like 1
    • Sad 1

    Chance favors the prepared mind. ― Louis Pasteur  
    Remember, a few hours of trial and error can save you several minutes of looking at the README. -- I Am Devloper (on Twitter)

    Clickable ---> The Best of Cori's Posts  (scroll down a wee bit there)    Something fun: MySimtropolis - Invitation to become a SimCity 4 MySim

    Are you new here? Check out the Introduction and Guide to Simtropolis.

    Share this post


    Link to post
    Share on other sites
    Posted:
    Last Online:  
     
    1 minute ago, CorinaMarie said:

    From what I've seen, the start of a riot is controlled internally rather than via any Lua code. Said Lua only reacts to the start of a riot and then allows jumping to it and/or dispatching police.

    You can use the UncivilDisobedience cheat if you install: Simmaster's Extra Cheats DLL to spawn a riot. *;)

    I know I have that mod + the extra riot mod it would just be nice to beat some spoiled strikers. However do you think it may be possible to create a .DLL mod that will allow a Lua script to spawn riots?


    Known as LeonardMT everywhere else

    Share this post


    Link to post
    Share on other sites
  • Original Poster
  • Posted:
    Last Online:  
     
    2 minutes ago, Leo -- said:

    However do you think it may be possible to create a .DLL mod that will allow a Lua script to spawn riots?

    That's completely beyond my ability so I cannot say with any certainty if it could be done.

    I do know that Maxis has functions defined in Lua and those somehow magically get married to code in the .exe, but I don't know how that's done. It might be the code in the .exe knows them by the exact name in the Lua and that's why we can access them from there. It would be ideal if there was a way to access the ExecuteCheat function of the .exe via Lua.

    • Like 2
    • Thanks 1

    Chance favors the prepared mind. ― Louis Pasteur  
    Remember, a few hours of trial and error can save you several minutes of looking at the README. -- I Am Devloper (on Twitter)

    Clickable ---> The Best of Cori's Posts  (scroll down a wee bit there)    Something fun: MySimtropolis - Invitation to become a SimCity 4 MySim

    Are you new here? Check out the Introduction and Guide to Simtropolis.

    Share this post


    Link to post
    Share on other sites
    Posted:
    Last Online:  
     
    On 9/9/2021 at 10:00 PM, CorinaMarie said:

    Answer... Yes, indeed. *:ohyes:

    The Lua could be coded so every possible disaster we can trigger could be based on the presence of a particular plopped reward lot being present. Then per disaster the code could also assign a random chance per month. An existing Maxis function allows that to be generated between 1 and 100%, but if that seems too much a new function could be written to allow less than 1% per month (but more than zero). Also, the disasters could be coded to count the number of that specific plop and adjust accordingly. Like say you set tornado to be ¼% per month and then have that be additive per plop so if there's 4 of them in the city, the chance increases to 1%. Or six of them would yield 1½% chance.

    You could also have more than one different trigger building so if one is for all disasters then another might only be for meteors and fires. And so forth.

    It'd really only be limited by your imagination and how much time you'd spend writing the Lua code.

    Oooo very cool!  I guess I should read up one of these days on Lua and modding SC4, because it would be awesome to try making a mod like this. 

    Thank you for all your hard work and research, it's quite inspiring to see people still digging into this game over 15 years later and finding new things!

    • Like 2

    Share this post


    Link to post
    Share on other sites
    Posted:
    Last Online:  
     

    This is awesome.

     

    Would be really neat to tie it to the Game year so that every 100 years in game time you get a random disaster. kinda like how they say irl that every 100 years there is another disaster (flood, earthquake, massive fire, robot attack)

    i miss the way sc3000 did disasters

    • Like 4

    our world is a simcity

    Share this post


    Link to post
    Share on other sites
  • Original Poster
  • Posted:
    Last Online:  
     
    3 minutes ago, Tysons4 said:

    Would be really neat to tie it to the Game year so that every 100 years in game time you get a random disaster.

    That could certainly be done such that exactly every 100 years either a specific disaster is triggered or at each 100 year mark it then randomly selects from a list of disasters.

    • Like 4

    Chance favors the prepared mind. ― Louis Pasteur  
    Remember, a few hours of trial and error can save you several minutes of looking at the README. -- I Am Devloper (on Twitter)

    Clickable ---> The Best of Cori's Posts  (scroll down a wee bit there)    Something fun: MySimtropolis - Invitation to become a SimCity 4 MySim

    Are you new here? Check out the Introduction and Guide to Simtropolis.

    Share this post


    Link to post
    Share on other sites
    Posted:
    Last Online:  
     

    A random disaster every 100 years would keep me playing a city just to see what happens and if i can recover. it would also add a challenge to see how old i could grow my cities

    • Like 5

    our world is a simcity

    Share this post


    Link to post
    Share on other sites
    Posted:
    Last Online:  
     
    4 hours ago, Tysons4 said:

    A random disaster every 100 years would keep me playing a city just to see what happens and if i can recover. it would also add a challenge to see how old i could grow my cities

    Agreed, could be fun to re-build neighbourhoods based on unpredictable disasters, just as how cities have been transformed by fires and floods over centuries. 

    • Like 5

    Share this post


    Link to post
    Share on other sites
    Posted:
    Last Online:  
     
    Spoiler

    waer.gif

    So I was looking around in the Lua code and found an effect called "stream". It said it was a stream of water, but for some reason I thought it would just be the generic and boring static water spray that you get when a volcano's lava touches water.

    Nevertheless, I added it into the function that randomly spawned effects, and I got... this.

    Needless to say, I was quite fascinated by the fact that this even exists. If you could make it so that a specific buildable building generates this effect when it is placed, I feel like this could be quite a nice decoration feature to make little streams and "waterfalls" in your city.

    by waterfalls I just mean water pouring out of a mountain into a river. if you could build a bridge over one of those, you could probably make some real nice looking cities. that is just a pipedream though, and it may or may not happen with a future mod. :]

    P.S. The spoiler contains the gif of the effect in action. I put it in a spoiler because the file is pretty big, and I hope this will ease the load on one's internet by not loading it immediately. If it still heavily impacts network speeds though (even when the spoiler is not open), let me know.

    • Like 2

    Share this post


    Link to post
    Share on other sites
  • Original Poster
  • Posted:
    Last Online:  
     

    Hiya, @Bruh Man.

    So nice to see you've been testing things. *:)

    I'm going to add you to a PM in which this particular effect has been tested. There's an attached file or two with it already set as an effect on a lot as well as pics and notes.

    • Yes 1

    Chance favors the prepared mind. ― Louis Pasteur  
    Remember, a few hours of trial and error can save you several minutes of looking at the README. -- I Am Devloper (on Twitter)

    Clickable ---> The Best of Cori's Posts  (scroll down a wee bit there)    Something fun: MySimtropolis - Invitation to become a SimCity 4 MySim

    Are you new here? Check out the Introduction and Guide to Simtropolis.

    Share this post


    Link to post
    Share on other sites
    Posted:
    Last Online:  
     
    7 hours ago, Bruh Man said:

    P.S. The spoiler contains the gif of the effect in action. I put it in a spoiler because the file is pretty big, and I hope this will ease the load on one's internet by not loading it immediately. If it still heavily impacts network speeds though (even when the spoiler is not open), let me know.

    That's very thoughtful, since GIF images sure can get very large indeed. *:yes:

    Oddly it doesn't actually appear to be showing in your spoiler and I get an error when viewing it directly, so something must've gone wrong there somehow. As it happens, images still do load up even when in spoilers, but there is a suggestion I have to work around the huge size...

    Try going to the EzGIF site which allows converting from GIF to the newer WebP format. This has an advantage of allowing much smaller file sizes, at even better quality. It's possible to use this page to convert your existing GIF image, or go to here which allows creating it from scratch which might achieve more quality results. I remember using this previously when we wanted to create an animation for the Flying Scotsman steam engine:
     

    Spoiler

    Flying-Scotsman-0.1KPH-on-Street-Animate

     

    Hope this might help too, and we encourage you to post pics here in reply of your stream effect testing. *;)

    • Like 3

    Quick Links

    “SimCity 4 is not just a game, but a tool driven by our own imagination and creativity.”

    Buy me a coffee

    Share this post


    Link to post
    Share on other sites
    Posted:
    Last Online:  
     

    Nice crap. *:thumb: Who knows, maybe it will come in handy one day.

    It could sure be useful to generate two, three simultaneous disasters, but I'm not sure if I need a .lua for that!

    • Like 2

    The "SimCity 4" vanilla Opera House is the most evil thing in existence. Avoid.

     

    My city journals! *:read:
    - SimCity: Tribalism - seven urbanization concepts clashed together
    Saving Magnasanti... - the most depressing city in history being revitalized

    Also worth checking...
    - "TMC's Drawing Board" - my city designs and plans.
     

    Share this post


    Link to post
    Share on other sites

    Sign In or register to comment...

    To comment in reply, you must be a community member

    Sign In  

    Already have an account? Sign in here.

    Sign In Now

    Create an Account  

    Sign up to join our friendly community. It's easy!  

    Register a New Account


    ×

    Thank You for the Continued Support!

    Simtropolis depends on donations to fund site maintenance costs.
    Without your support, we just would not be in our 24th year online!  You really help make this a great community. *:thumb:

    But we still need your support to stay online. If you're able to, please consider a donation to help us stay up and running. This helps sustain a platform where we can share our community creations for years to come.

    Make a Donation, Get a Gift!

    Expand your city with the best from the Simtropolis Exchange.
    Make a Donation and get one or all three discs today!

    STEX Collections

    By way of a "Thank You" gift, we'd like to send you our STEX Collector's DVD. It's some of the best buildings, lots, maps and mods collected for you over the years. Check out the STEX Collections for more info.

    Each donation helps keep Simtropolis online, open and free!

    Thank you for reading and enjoy the site!

    More About STEX Collections