Making RPG events

From Spheriki

Jump to: navigation, search

Events in RPGs aren't that hard to make really.

We can have a linear event system like this:

var current_event = 0; // global variable 

And whenever you refer to any events in the game, you do:

switch (current_event) {
  case 0: 
    /* code */  
  break; 

  case 1: 
    /* code */ 
  break; 

  default: 
    /* code */ 
}

Say you were talking to someone in a town...

function TalkToJim() 
{ 
  switch (current_event) 
  { 
    case 0: 
      ShowText("Jim:\n\"If you're considering going after Freddy...\nYou'll need a sword.\""); 
    break;

    case 1: 
      ShowText("Jim:\n\"Good luck in finding your friend!\"");
    break; 

    default:
      ShowText("Jim:\n\"I'm glad Freddy is safe now.\""); 
      // Jim refuses to give any more helpful information beyond event one :) 
  }
}

And whenever you complete an event with this system you'd do:

++current_event;

e.g.

function OnRescueFreddy() 
{ 
  ShowText("Freddy:\n\"Thanks for saving me from that bush fire there...\"");
  FollowPerson("Freddy", GetInputPerson(), 16); // Freddy (the sprite within the map) now follows you 
  ++current_event; // on to the next event in our linear game! 
}

The problem with this kind of event system is you end up having to have things like:

function OnRescueFreddy() 
{ 
  if (current_event != 1) { 
    ShowText("Freddy:\n\"You cannot rescue me yet, dang.\""); 
    return; 
  } 

  ShowText("Freddy:\n\"Thanks for saving me from that bush fire there...\""); 
  FollowPerson("Freddy", GetInputPerson(), 16); // Freddy (the sprite within the map) now follows you 
  ++current_event; // on to the next event in our linear game! 
}


So maybe we should try a not so linear system?

var event = new Object(); 
event.buy_a_sword = 0; 
event.rescue_freddy = 0; 
// etc

Jim would change to be something like:

function TalkToJim() 
{ 
  if(event.buy_a_sword == 0 && event.rescue_freddy == 0) {
      ShowText("Jim:\n\"If you're considering going after Freddy...\nYou'll need a sword.\""); 
  } else { 
    if (event.buy_a_sword == 1) 
      ShowText("Jim:\n\"Good luck in finding your friend!\""); 
    else 
      ShowText("Jim:\n\"You rescued Freddy without a sword?!\""); 
  } else {
      ShowText("Jim:\n\"I'm glad Freddy is safe now.\""); 
  }
} 

And OnRescueFreddy() would become:

function OnRescueFreddy() 
{ 
  ShowText("Freddy:\n\"Thanks for saving me from that bush fire there...\""); 
  FollowPerson("Freddy", GetInputPerson(), 16); // Freddy (the sprite within the map) now follows you 
  event.rescue_freddy = 1; 
}

Now, I did event.rescue_freddy = 1, but I could have done:

++event.rescue_freddy;

Which would essentially mean I'd have multiple linear storylines... But the rescue Freddy part of the story only has one part.

Anyway, that's enough from me...


By Flikky (from the Sphere CHM, adapted and updated for the wiki.)

Personal tools