Author Topic: Timing question for a specific routine?  (Read 354 times)

Legacy_lordofworms

  • Sr. Member
  • ****
  • Posts: 422
  • Karma: +0/-0
Timing question for a specific routine?
« on: February 06, 2011, 01:50:13 pm »


               Ok, I am collaborating with someone on a quest and I have been playing with the idea and think I could do it all except for how to do a timing thing? I don't know much about timer's and the like in a PW setting

general idea: your (PC) would need to grab 3 different colored barrels and place in 3 different (same colored marked) places, when all 3 barrels are placed you go talk to npc and *boom* they explode, quest complete.

problem facing PC: goblin sappers keep running out and suicide igniting (1) of your placed barrels random chance. which makes you go back and get another same colored barrel
PC cannot carry more than one barrel at a time.

now I know it will probably be a pain to write up so i wont even ask for help on the concept but I was thinking I would need a timer to count down so that if (5) ticks go by before a player places another barrel then THATS when I would trigger the goblin suicide run.  if player places a second barrel before (5) ticks go by, then count starts back at 5 and counts down until next barrel is placed..so on...so forth.


additional info: this timer would need to work in a multiplayer setting.

is a timer what I am looking for? or is there a simpler approach that I may not be seeing?
thanks for the time guru's!

any help, snippets of code, or re-directs greatly appreciated.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Timing question for a specific routine?
« Reply #1 on: February 06, 2011, 07:26:13 pm »


               Hmm Simpler.  Well I am not sure if what i am going to suggest will be simpler for you or not.  I can only stat the way I would do it. 

Since you have a lot going on that could become hard to keep track of.  It sounds to me like an Ideal case for making an event handler.  The Event Handler woud basicly be what drives the entire system.  It is nothing more then a single placeable that when ever anything happens It get sent a singnal. Then it maks the dicision of what to do.  It just help to keep all the main code in one place. 

Event handler also normally use an include file to keep basic Data easy to reach. Here is a simple example with just your timmer added. 

File:inc_event


const int EVENT_BARREL_PLACED = 2010;
const int EVENT_SEND_SAPER    = 2020;
const int EVENT_3             = 2030;
const int EVENT_4             = 2040;

const float THREE_TICKS =  18.0;
const string EVENT_HANDLER_TAG = "Tag of Event Handlet";

const string EVENT_HANDLER = "EVENT_HANDLER";
const string BARRELS_PLACED = "NUMBER_OF_BARRELS_PLACED";
const string TIMMER_CHECK  = "NUMBER_OF DELAYS_PASSED";

object GetEventHandler();
object GetEventHandler()
{
   object oHandler = GetLocalObject(GetArea(OBJECT_SELF),EVENT_HANDLER);
   if ( !GetIsObjectValid(oHandler))
   {
      oHandler = GetObjectByTag( EVENT_HANDLER_TAG);
      SetLocalObject(GetArea(OBJECT_SELF),EVENT_HANDLER,oHandler);
   }
   return oHandler;
}


File:  EVENT Handler.  The name of the file does not matter. It just need to be placed on the OnUserDefined Event of an object.
 



//::///////////////////////////////////////////////
//:: Custom User Defined Event
//:: FileName
//:: Copyright (c) 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*
*/
//:://////////////////////////////////////////////
//:: Created By:
//:: Created On:
//:://////////////////////////////////////////////

#include "inc_event"
 
void main()
{
    object oEventHandler = GetEventHandler();
    int nEvent = GetUserDefinedEventNumber();
    switch (nEvent)
    {
        case EVENT_BARREL_PLACED:
        {
          int nBarrelsPlaced= GetLocalInt( oEventHandler,BARRELS_PLACED);
          SetLocalInt(oEventHandler,BARRELS_PLACED,nBarrelsPlaced+1);
          event eEvent = EventUserDefined(EVENT_SEND_SAPER);
          DelayCommand (THREE_TICKS,SignalEvent(oEventHandler, eEvent));
        }
        break;
       
        case EVENT_SEND_SAPER:
        {
          int nTM_Check = GetLocalInt(oEventHandler,TIMMER_CHECK) +1;
          SetLocalInt(oEventHandler,TIMMER_CHECK,nTM_Check );
          if (nTM_Check  == GetLocalInt( oEventHandler,BARRELS_PLACED))
          {
            //Enter code to send saper here.
          }
        }
        break;

        case EVENT_3:
        {
        }
        break;

        case EVENT_4:
        {
        }
        break;
    }
}




Then for however you are detecting the barrels being placed the code would be a simple as: 



#include "inc_event"

void main ()
{
  event eEvent = EventUserDefined(EVENT_BARREL_PLACED);
  SignalEvent(GetEventHandler(), eEvent));
 
}


Hope this is helpfull and gives you some ideas.
L8
               
               

               
            

Legacy_lordofworms

  • Sr. Member
  • ****
  • Posts: 422
  • Karma: +0/-0
Timing question for a specific routine?
« Reply #2 on: February 07, 2011, 01:15:58 pm »


               I think this is EXACTLY what I need...i threw together a test module and kind of fudged it together to just see it in action.



I assume the event3 and event 4 are user configured, so I can make an event called FINISHED or what not correct and call it when I have my (3) barrels placed and on time. is this correct?



also this can be ANY item? (the caller of the event I mean) does it have to be usable or can it be a static decoration?



and yes, it has given me alot of ideas, never even knew what an event handler was and never touched user-defined topics before now.

so you opened alot of content for me to digest but it looks like something I should know to give me an edge in designing my own complex quests.



thanks Lightfoot8, seems you always come through for me!



               
               

               
            

Legacy_Baragg

  • Sr. Member
  • ****
  • Posts: 496
  • Karma: +0/-0
Timing question for a specific routine?
« Reply #3 on: February 07, 2011, 04:29:31 pm »


               Yea Lightfoot rocks.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Timing question for a specific routine?
« Reply #4 on: February 08, 2011, 02:33:33 am »


               

lordofworms wrote...

I assume the event3 and event 4 are user configured, so I can make an event called FINISHED or what not correct and call it when I have my (3) barrels placed and on time. is this correct?

 

I just placed them there to show you that you can add however many events you need to.  You just need to add a Constant for the event into the include, then a case for the event into your script.

also this can be ANY item? (the caller of the event I mean) does it have to be usable or can it be a static decoration?

You mean the event handler?  It can be any object that has the OnUserDefined event on it.  So any Creature, Door, Encounter, Placeable or Trigger.  The object does not have to be usable.  Staitc ? Hmm, Not sure I do not think it would cause a problem though.  Just Keep in mind that if the Event Handler gets destroyed the entire system comes to a hault.  Not a bad Idea if that is what you plan on.