Author Topic: Heartbeat Event Scripting Problem  (Read 313 times)

Legacy_Ed Venture

  • Full Member
  • ***
  • Posts: 200
  • Karma: +0/-0
Heartbeat Event Scripting Problem
« on: December 12, 2013, 03:06:04 am »


               Hello Everybody,
I am having a problem with 3 Heartbeat scripts. The first is on an orc, that on HB yells "FIRE !" The second is on a catapult, that on HB cast fireball spells. The third is on barrels that, on HB spawn flames. From what I have read on the forum, I expected to have problems with these scripts firing when the PC was not in the area. I was hoping that placing a conditional on them, would make them invalid untill the variable was set on the PC. I was wrong !
This is the On Enter script of the trigger.

void main()
{
 object oPC = GetFirstPC();
 object oEnt = GetEnteringObject();
 object oTrig = GetObjectByTag("TrOnDeck");
 object oCapt = GetObjectByTag("Captain");
 string sConvo = "capt_marvel";
 if(GetIsPC(oEnt))
 {
  DelayCommand(3.0,AssignCommand(oCapt,
  ActionStartConversation(oPC,sConvo,FALSE)));
  DelayCommand(7.0,SetLocalInt(oPC,"Fire",1));
  DestroyObject(oTrig,8.0);
 }
}

This is the first HB script.

void main()
{
 object oPC = GetFirstPC();
 object oCap = OBJECT_SELF;
 object oCat = GetObjectByTag("PirateCat");
 int nVols = TALKVOLUME_SHOUT;
 if(GetIsObjectValid(oCat))
 {
  if(GetLocalInt(oPC,"Fire") > 0)
  {
   AssignCommand(oCap,ActionSpeakString("FIRE !",nVols));
  }
 }
}

Can some one tell me what I"m doing wrong, and how I can fix this ?
Should I spawn the objects into the area with the trigger ?
Ed
               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
Heartbeat Event Scripting Problem
« Reply #1 on: December 12, 2013, 02:54:23 pm »


               Hi Ed.
Assuming the PC does not enter the trigger and does not have an int variable Fire set on her somewhere else the Captain should not be shouting fire (assuming that's the HB for the captain).

Are you saying that even before the PC enters the trigger the captain is shouting FIRE? Seems odd.

This setup does not directly deal with the PC in the area. Once the PC has entered the trigger these things will go off. If the PC is then meant to kill them then it would work. But if the PC leaves
the variable will still be set unless you clear it somewhere.

Looks like you have a conversation with the captain. Is there something there that triggers the need to start firing? You could use a script off of the appropriate conversation node to set
the variable that controls if the HBs do anything.

(The references to PC in the first script are extraneous. You've got oEnt and have established that
oEnt is a PC so you could just use that. But that's mostly just a style issue.)

All that said,  the code looks like it should do what you said. If "Fire" is not set on the PC the captain should not be shouting "FIRE". Therefore "Fire" must be set on the PC. Is it possible you have something else that sets that variable?
You could put something like this in the onEnter script (inside the GetISPC block) and see:

if (GetLocalInt(oEnt, "Fire"))
           SendMessageToPC(oEnt, "DEBUG: PC has Fire already set!");


Cheers,
meaglyn
               
               

               
            

Legacy_Ed Venture

  • Full Member
  • ***
  • Posts: 200
  • Karma: +0/-0
Heartbeat Event Scripting Problem
« Reply #2 on: December 13, 2013, 04:24:36 am »


               meaglyn,
Thank you for your reply. You got me thinking. I changed the variable name on the first two scripts.
No problems.
void main()
{
object oPC = GetFirstPC();
object oCap = OBJECT_SELF;
object oCat = GetObjectByTag("PirateCat");
int nVols = TALKVOLUME_SHOUT;

if(GetIsObjectValid(oCat))
{
 if(GetLocalInt(oPC,"UnderSiege") > 0)
 {
  AssignCommand(oCap,ActionSpeakString("FIRE !",nVols));
 }
}
}

I then did the same with the third script. Problem.
void main()
{
object oPC = GetFirstPC();
string sTemp = "flame_aft";
string sMes = "The Argosent Is Lost !";
int nType = OBJECT_TYPE_PLACEABLE;
int bUse = FALSE;
location lLocA = GetLocation(GetWaypointByTag("WpCatTarget04"));
location lLocB = GetLocation(GetWaypointByTag("WpFireAft01"));
location lLocC = GetLocation(GetWaypointByTag("WpFireAft02"));
location lLocD = GetLocation(GetWaypointByTag("WpFireAft03"));
location lLocE = GetLocation(GetWaypointByTag("WpFireAft04"));
location lLocF = GetLocation(GetWaypointByTag("WpFireAft05"));
int nCount = GetLocalInt(oPC,"Fire");
nCount = nCount + 1;
int nDice = d6();

if(GetLocalInt(oPC,"Fire") < 100)
{
 switch(nDice)
 {
  case 1:
  CreateObject(nType,sTemp,lLocA,bUse);
  SetLocalInt(oPC,"Fire",nCount);
  break;
  case 2:
  CreateObject(nType,sTemp,lLocB,bUse);
  SetLocalInt(oPC,"Fire",nCount);
  break;
  case 3:
  CreateObject(nType,sTemp,lLocC,bUse);
  SetLocalInt(oPC,"Fire",nCount);
  break;
  case 4:
  CreateObject(nType,sTemp,lLocD,bUse);
  SetLocalInt(oPC,"Fire",nCount);
  break;
  case 5:
  CreateObject(nType,sTemp,lLocE,bUse);
  SetLocalInt(oPC,"Fire",nCount);
  break;
  case 6:
  CreateObject(nType,sTemp,lLocF,bUse);
  SetLocalInt(oPC,"Fire",nCount);
  break;
 }
}
else
{
 SendMessageToPC(oPC,sMes);
 DeleteLocalInt(oPC,"Fire");
 //Fade to Black, Delay Jump Player
}
}
This script was adding the "Fire" variable. I inserted the "UnderSiege" conditional at the beginning of the script, and set it on the trigger. Problem solved. Still have alot to learn. Thanks again for your help.
Ed
               
               

               
            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Heartbeat Event Scripting Problem
« Reply #3 on: December 13, 2013, 04:07:04 pm »


               Since you're still learning, try comparing this script to your second. They're functionally identical, but this one is designed to be both more compact and easier to read.

void main()
{
    object oPC = GetFirstPC();
    int nCount = GetLocalInt(oPC,"Fire");

    if(nCount++ < 100) {
        location lLoc;
        switch(Random(6)) {
        case 0: lLoc = GetLocation(GetWaypointByTag("WpCatTarget04")); break;
        case 1: lLoc = GetLocation(GetWaypointByTag("WpFireAft01"));   break;
        case 2: lLoc = GetLocation(GetWaypointByTag("WpFireAft02"));   break;
        case 3: lLoc = GetLocation(GetWaypointByTag("WpFireAft03"));   break;
        case 4: lLoc = GetLocation(GetWaypointByTag("WpFireAft04"));   break;
        case 5: lLoc = GetLocation(GetWaypointByTag("WpFireAft05"));   break;
        }
        CreateObject(OBJECT_TYPE_PLACEABLE,"flame_aft",lLoc,FALSE);
        SetLocalInt(oPC,"Fire",nCount);
    }
    else {
        SendMessageToPC(oPC,"The Argosent Is Lost!");
        DeleteLocalInt(oPC,"Fire");
        //Fade to Black, Delay Jump Player
    }
}


Didn't do this in the toolset, but it should compile.

Funky
               
               

               
            

Legacy_Ed Venture

  • Full Member
  • ***
  • Posts: 200
  • Karma: +0/-0
Heartbeat Event Scripting Problem
« Reply #4 on: December 15, 2013, 04:25:30 am »


               FunkySwerve,
Thank you. As a noob, I often try to read other peoples scripts. Alot of the time it just gets to a point were it all stops making sense. Seeing a more advanced version of my own script, makes it much easier to read yours. I have copied and pasted it to a word doc for future study.

A Fan,
Ed