Author Topic: Problem with onheartbeat script and waypoints  (Read 562 times)

Legacy_Krevett

  • Full Member
  • ***
  • Posts: 203
  • Karma: +0/-0
Problem with onheartbeat script and waypoints
« on: September 04, 2010, 08:22:33 am »


               Hello, still playing nwn and currently building a module for playing with friends I find myself stuck with this issue: guards in the town are assigned an onheartbeat script to check if it's day or night, and light a torch accordingly...Up to this point it works fine guards switch their shield for a torch at dusk and vice-versa at dawn, but if i set a waypoint for him to walk to (or a post) it won't work!!
Has anyone encountered this problem?Thanks in advance!
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Problem with onheartbeat script and waypoints
« Reply #1 on: September 04, 2010, 08:47:50 am »


               Did you overwrite the default OnHeartbeat? Or did you make a custom OnHeartbeat script for the torches? If you made a custom one then make sure you put an ExecuteScript line in there to run the default HB script(nw_c2_default1).
               
               

               


                     Modifié par GhostOfGod, 04 septembre 2010 - 07:49 .
                     
                  


            

Legacy_Krevett

  • Full Member
  • ***
  • Posts: 203
  • Karma: +0/-0
Problem with onheartbeat script and waypoints
« Reply #2 on: September 04, 2010, 09:00:11 am »


               I made a custom one...and didn't put this line! OK i'll try this at once thanks!

Edit: still don't work for guard with waypoints...
               
               

               


                     Modifié par Krevett, 04 septembre 2010 - 08:12 .
                     
                  


            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Problem with onheartbeat script and waypoints
« Reply #3 on: September 04, 2010, 09:04:50 am »


               No problem. And if you need the actual line you'd use:

ExecuteScript("nw_c2_default1", OBJECT_SELF);

Just put that at the bottom of your script just before/above the last closing curly bracket "}".
               
               

               


                     Modifié par GhostOfGod, 04 septembre 2010 - 08:06 .
                     
                  


            

Legacy_Krevett

  • Full Member
  • ***
  • Posts: 203
  • Karma: +0/-0
Problem with onheartbeat script and waypoints
« Reply #4 on: September 04, 2010, 12:24:02 pm »


               It don't solve the problem, for now guards without waypoints still light their torches at night and those with waypoints go on walking them without switching their shield...
               
               

               
            

Legacy_Fester Pot

  • Hero Member
  • *****
  • Posts: 1698
  • Karma: +0/-0
Problem with onheartbeat script and waypoints
« Reply #5 on: September 04, 2010, 01:57:55 pm »


               Without posting the script, we're left with only guesses, which isn't going to produce a speedy solution.



FP!
               
               

               
            

Legacy_Krevett

  • Full Member
  • ***
  • Posts: 203
  • Karma: +0/-0
Problem with onheartbeat script and waypoints
« Reply #6 on: September 04, 2010, 02:48:27 pm »


               You're right sorry! Here's the script

void main()

{

int post;

if (GetIsDay()&GetLocalInt(OBJECT_SELF, "post")==2)

{

ActionEquipItem(GetItemPossessedBy(OBJECT_SELF, GetTag(GetLocalObject(OBJECT_SELF, "oldobject"))), INVENTORY_SLOT_LEFTHAND);

SetLocalInt(OBJECT_SELF, "post", 1);

}

if (GetIsNight()&GetLocalInt(OBJECT_SELF, "post")==1)

{

SetLocalObject(OBJECT_SELF, "oldobject", GetItemInSlot(INVENTORY_SLOT_LEFTHAND));

ActionEquipItem(GetItemPossessedBy(OBJECT_SELF, "NW_IT_TORCH001"), INVENTORY_SLOT_LEFTHAND);

SetLocalInt(OBJECT_SELF, "post", 2);

}

ExecuteScript("nw_c2_default1", OBJECT_SELF);

}



I set a local variable "post" to 1 on the guards i want to switch their shield for a torch at night, and of course these guards have a torch in their inventory!
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Problem with onheartbeat script and waypoints
« Reply #7 on: September 04, 2010, 05:23:55 pm »


               Could just be a simple matter of using "&&" instead of "&". Two of them for short circuit logical "And".
               
               

               
            

Legacy_Krevett

  • Full Member
  • ***
  • Posts: 203
  • Karma: +0/-0
Problem with onheartbeat script and waypoints
« Reply #8 on: September 04, 2010, 05:38:29 pm »


               Strange i use only one & for now in other scripts and it works???

Even with this correction guards with waypoints still won't switch their shields for torches at night as if while walking they ignore the heartbeat script!!
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Problem with onheartbeat script and waypoints
« Reply #9 on: September 04, 2010, 06:14:04 pm »


               Sorry I'm just throwing this out untested but on my way out the door to work. '<img'>

Try this and see what happens:

void main()
{
if (GetIsDay()&& GetLocalInt(OBJECT_SELF, "post")==2)
    {
    ClearAllActions();
    ActionEquipItem(GetItemPossessedBy(OBJECT_SELF, GetTag(GetLocalObject(OBJECT_SELF, "oldobject"))), INVENTORY_SLOT_LEFTHAND);
    SetLocalInt(OBJECT_SELF, "post", 1);
    }

if (GetIsNight()&& GetLocalInt(OBJECT_SELF, "post")==1)
    {
    ClearAllActions();
    SetLocalObject(OBJECT_SELF, "oldobject", GetItemInSlot(INVENTORY_SLOT_LEFTHAND));
    ActionEquipItem(GetItemPossessedBy(OBJECT_SELF, "NW_IT_TORCH001"), INVENTORY_SLOT_LEFTHAND);
    SetLocalInt(OBJECT_SELF, "post", 2);
    }

ExecuteScript("nw_c2_default1", OBJECT_SELF);
}


I slapped in a couple "ClearAllActions" to interupt his current action. Not tested but hope that is the problem. Good luck.
               
               

               


                     Modifié par GhostOfGod, 04 septembre 2010 - 05:14 .
                     
                  


            

Legacy_Krevett

  • Full Member
  • ***
  • Posts: 203
  • Karma: +0/-0
Problem with onheartbeat script and waypoints
« Reply #10 on: September 04, 2010, 07:05:44 pm »


               I tried it but this didn't solve the problem...Thanks for your help anyway '<img'> no work for me except on aurora toolset lol it's already dusk in france!
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Problem with onheartbeat script and waypoints
« Reply #11 on: September 04, 2010, 07:53:46 pm »


               And it does work if you set the guard normal heartbeat script, nw_c2_default1, like he is walking on waypoints normally, right?
               
               

               


                     Modifié par ShaDoOoW, 04 septembre 2010 - 06:53 .
                     
                  


            

Legacy_Krevett

  • Full Member
  • ***
  • Posts: 203
  • Karma: +0/-0
Problem with onheartbeat script and waypoints
« Reply #12 on: September 04, 2010, 08:02:08 pm »


               The problem is that the script works as long as your guard has no assigned waypoints...if you assign him with waypoints he walks them normally but never switch for his torch at night!
               
               

               
            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
Problem with onheartbeat script and waypoints
« Reply #13 on: September 04, 2010, 08:32:14 pm »


               You may have to alter walk waypoints which is the standard script:



#include "NW_I0_GENERIC"



void main()



{

   WalkWayPoints();

}



You could alter that to something like:

#include "NW_I0_GENERIC"



void main()

{

if (GetLocalInt (OBJECT_SELF, "Guard") == 1)

 ExecuteScript("GuardTorch", OBJECT_SELF);

 WalkWayPoints();

}



And then set a local int (variable) on your guards with torches to Guard 1.

Then you execute the torch script as above, and follow that up with the normal

walkwaypoints call.  You might want to put a delaycommand in befor walkwaypoints,

but the other script should execute first.
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Problem with onheartbeat script and waypoints
« Reply #14 on: September 04, 2010, 08:41:48 pm »


               

void main()
{
object oGuard = OBJECT_SELF;
 if(GetIsInCombat(oGuard))//if fighting do not mess with equiping AI
 {
 ExecuteScript("nw_c2_default1",oGuard);
 return;
 }
ClearAllActions();
object oLeftHand = GetItemInSlot(INVENTORY_SLOT_LEFTHAND, oGuard);
 if(GetIsDay() || GetIsDawn())
 {
 object old = GetLocalObject(oGuard,"oldobject");
  if(GetTag(oLeftHand) == "NW_IT_TORCH001")//if got torch in the left hand
  {
   if(old != OBJECT_INVALID)//guard have shield, or light weapon equipping it, unequip torch
   {
   ActionEquipItem(old, INVENTORY_SLOT_LEFTHAND);
   }
   else//guard do not have any shield, or light weapon, must unequip torch manually
   {
   ActionUnequipItem(oLeftHand);
   }
  }
 }
 else//night or dusk
 {
  if(GetTag(oLeftHand) != "NW_IT_TORCH001")//if not torch in the left hand
  {
  SetLocalObject(oGuard, "oldobject", oLeftHand);
  ActionEquipItem(GetItemPossessedBy(oGuard, "NW_IT_TORCH001"), INVENTORY_SLOT_LEFTHAND);
  }
 }
ActionDoCommand(ExecuteScript("nw_c2_default1",oGuard));
}

Try this, I think the problem is that "waypoint walking" cancels the equipping, this should workaround this + has number of new features - see comments.

Also, I would add the check if the guard can even equip the torch, but suppose you giving this only to guards with one-handed weapon it is not needed.