Simple Weather + Day/Night Cycle Codes v1.5

Anonynn

Okay! Here are the steps to implement: Weather and TOD scripting. UPDATED: 31JAN17 Changes to Night/Day Cycle.

Weather

  1. Game.Object, Attributes. Add...
    clear Boolean False
    cloud Boolean False
    rain Boolean False
    storm Boolean False

  2. Game.Object, Attributes. Add...
    clearcount Integer Set to 201.
    cloudcount Integer Set to 201.
    stormcount Integer Set to 201.

  3. Create Global Turnscript. ((I have designed the "Weather System" to be completely randomized. As far as Rain goes, it will have a 50% chance to proc at the beginning of "Cloudy Weather" but if it doesn't happen, I have designed it to have a 30% chance to proc at cloudcount 100. If it is already raining at cloudcount 100 then it'll have a 30% chance to stop raining. The Storm Weather can be written in room descriptions to be Rain or Snow, depending on location with; if (game.storm=True:} This code can be used for the other weather procs too, for example: if (game.clear=False: Text here} or if (game.cloud=True: Text here} ))

  4. Add this line of code to a room.object's scripting, probably in a "After Leaving the Room" or "After Entering the Room" script tabs.

EnableTurnScript (weather)
  1. Make sure this script is NOT activated until you want it to be activated. If you want the script activated at the beginning of your game, you do not need the code above.

If you have any questions about it; just let me know.

if (game.clear=True) {
  game.clearcount = game.clearcount - 1
  if (game.clearcount = 200) {
    msg ("<br/><font color=\"dedede\">The weather is clearing up!</font color><br/>")
  }
  if (game.clearcount = 1) {
    game.clear = False
    game.clearcount = 201
    if (RandomChance(50)) {
      game.clear = True
    }
    else if (RandomChance(25)) {
      if (RandomChance(50)) {
        game.cloud = True
      }
      else {
        game.cloud = True
        game.rain = True
      }
    }
    else {
      game.storm = True
    }
  }
}
if (game.cloud=True) {
  game.cloudcount = game.cloudcount - 1
  if (game.cloudcount = 200) {
    msg ("<br/><font color=\"dedede\">It's getting pretty cloudy out!</font color><br/>")
    if (RandomChance(30)) {
      game.rain = True
      msg ("<br/><font color=\"dedede\">And it's beginning to rain!</font color><br/>")
    }
  }
  if (game.cloudcount = 100) {
    if (game.rain = False) {
      if (RandomChance(30)) {
        game.rain = True
        msg ("<br/><font color=\"dedede\">Uh-oh! It's beginning to rain!</font color><br/>")
      }
    }
    else {
      if (RandomChance(30)) {
        game.rain = False
        msg ("<br/><font color=\"dedede\">Seems like the rain has stopped.</font color><br/>")
      }
    }
  }
  if (game.cloudcount = 1) {
    game.cloud = False
    game.cloudcount = 201
    if (game.rain=True) {
      game.rain = False
    }
    if (RandomChance(50)) {
      game.clear = True
    }
    else if (RandomChance(25)) {
      if (RandomChance(50)) {
        game.cloud = True
      }
      else {
        game.cloud = True
        game.rain = True
      }
    }
    else {
      game.storm = True
    }
  }
}
if (game.storm=True) {
  game.stormcount = game.stormcount - 1
  if (game.stormcount = 200) {
    msg ("<br/><font color=\"dedede\">A swarm of dark clouds is moving into the air. It's beginning to storm!</font color><br/>")
  }
  if (game.stormcount = 1) {
    game.storm = False
    game.stormcount = 201
    if (RandomChance(50)) {
      game.clear = True
    }
    else if (RandomChance(25)) {
      if (RandomChance(50)) {
        game.cloud = True
      }
      else {
        game.cloud = True
        game.rain = True
      }
    }
    else {
      game.storm = True
    }
  }
}

Day/Night Cycle

  1. Game.Object, Attributes. Add...
    ndcycle.integer
    Make it 0.

  2. Game.Object, Attributes. Click ndcycle, Click Add ChangeScript.
    changedndcycle Script

 if (game.ndcycle>3) {
 game.ndcycle=0
}  
  1. Add this script to whatever room.object(s) you want the ndcycle to affect. For the first one, I suggest adding it to a previous room's "After Leaving the Room" script which can be found on the room.object, script tab. This code below will randomize the starting ndcycle but if you don't want it randomized, remove the code below and simply put...game.ndcycle = 0 which will set the individual attribute.

0 "morning"
1 "midday"
2 "evening"
3 "night"

game.ndcycle = GetRandomInt(0, 3)
  1. When you want the day/night cycle to advance simply put...
game.ndcycle = game.ndcycle + 1 

Then you can use it in room descriptions with {if game.ndcycle=0:It was early morning}

TO USE THESE TOGETHER TRY:
{if game.ndcycle=0: It was early morning{if game.clear=True: and the sky was clear}.}


Anonynn

If you need any help let me know :D


hegemonkhan

awesome work Anonynn! More guides/code/libraries for people to use! :D


Anonynn

Thanks!


crystalwizard

Create Global Turnscript
how and where?

Add this line of code to a room.object's scripting

Does this mean i have to add that to every single room if I want weather in all the rooms in the game?


Anonynn

Hello!

In your tree of stuff, you right click on your game.object. When you do, you should see a drop down list appear. Among them is "Add Turnscript". Adding it in this fashion instead of to a specific room will make it "global" :)

No. You add it to the first room you want the weather to begin working in, essentially activating the turn-script. Either upon entering that room or leaving it. From there the turn-script will forever run until you disable it.

If you have anymore questions lemme know ^_^

Anonynn.


hegemonkhan

there is the 'enabled' Boolean Attribute for Turnscripts, which is what is checked in whether they're actually "on/runnning/firing" or not. You can have this on/true or off/false at compile time:

<turnscript name="xxx">
  // via:
  // short syntax form: <enabled /> // long-actual-full syntax form: <attr name="enabled" type="boolean">false</attr> // or: <attr name="enabled" type="boolean">true</attr>
  // (or not, see below)
</turnscript>

<turnscript name="xxx">
</turnscript>

----

all forms (as the above is probably confusing, sighs):

// enabled:

<turnscript name="xxx">
  <enabled />
</turnscript>

<turnscript name="xxx">
  <attr name="enabled" type="boolean">true</attr>
</turnscript>

not enabled:

<turnscript name="xxx">
</turnscript>

<turnscript name="xxx">
  <attr name="enabled" type="boolean">false</attr>
</turnscript>

or you can use the built-in helper 'EnableTurnScript/DisableTurnScript' Functions to do it during runtime (dynamically during the game being played): via your scripting/actions/events, which will/can happen during game play.

the quickest example would be to have a Command (which would allow the person playing the game the power to do so whenever he/she wants, lol):

<game name="example_game">
  <attr name="turn" type="int">0</attr>
  <attr name="statusattributes" type="simplestringdictionary">turn = Turns: !</attr> // so you can see/feel/experience the power you have when playing the game to control the game turns in when they increment and when they don't, lol
</game>

<command name="enable_example_turnscript_command">
  <pattern>eet</pattern> // 'eet' for 'enable example turnscript', lol
  <script>
    EnableTurnScript (example_turnscript) // I think this will also work -- ie, this is what the 'EnableTurnscript' Function is doing for you (but I might be wrong): example_turnscript.enabled = true
  </script>
</command>

<command name="disable_example_turnscript_command">
  <pattern>det</pattern> // 'det' for 'disable example turnscript', lol
  <script>
    DisableTurnScript (example_turnscript) // I think this will also work -- ie, this is what the 'EnableTurnscript' Function is doing for you (but I might be wrong): example_turnscript.enabled = false
  </script>
</command>

<turnscript name="example_turnscript">
  <attr name="enabled" type="boolean">false</attr>
  <script>
    game.turn = game.turn + 1
  </script>
</turnscript>

Anonynn

Updated Version Out. See above ^_^ The Night/Day Cycle has changed a little.


Log in to post a reply.

Support

Forums