Simple Weather + Day/Night Cycle Codes

Anonynn

Okay! Here are the steps to implement: Weather and TOD scripting.

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 String List.
    Add morning
    Add midday
    Add evening
    Add night

  2. Game.Object, Attributes. Click ndcycle, Click Add ChangeScript.
    changedndcycle Integer, 0

  3. 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"

if (RandomChance(25)) {
  game.ndcycle = 0
}
else if (RandomChance(25)) {
  game.ndcycle = 1
}
else if (RandomChance(25)) {
  game.ndcycle = 2
}
else {
  game.ndcycle = 3
}
  1. When you want the day/night cycle to advance simply put...
game.ndcycle = game.ndcycle + 1 
if (game.ndcycle>3) {
 game.ndcycle = 0
}

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!


Log in to post a reply.

Support

Forums