Author Topic: Resting System Trouble  (Read 322 times)

Legacy_Evelath

  • Full Member
  • ***
  • Posts: 108
  • Karma: +0/-0
Resting System Trouble
« on: June 25, 2013, 03:51:32 am »


               Hello again everyone,

I am attempting to do the following:

1) Launch a conversation when a player attempts to rest.
2) After selecting the option to rest via the conversation branch, run a resting script.


OnRest Script:
----snip----

void main()

{

object oPC = GetLastPCRested();

if (!GetIsPC(oPC)) return;

AssignCommand(oPC, ClearAllActions());
AssignCommand(oPC, ActionStartConversation(OBJECT_SELF,"rest_conv",TRUE,FALSE));


}
----snip----

Rest System
----snip----
const int REST_DELAY_TIMER = 30; // Minutes between resting?
const string CHEST_TAG = "restitems"; // Tag of the chest that stores the rest items
#include "x2_inc_switches"

void RestTimerCounter(object oPC, string sPlayerID, int nTimer)
{
    SetLocalInt(GetModule(), "RestTimer" + sPlayerID, nTimer);
    if (!nTimer) return;
    nTimer --;
    DelayCommand(60.0, RestTimerCounter(oPC, sPlayerID, nTimer));
}
void main()
{
    object oPC = GetPCSpeaker();

    AssignCommand(oPC, ActionRest(FALSE));
   int nCur = GetCurrentHitPoints(oPC);
   int nMax = GetMaxHitPoints (oPC);
   int nDif = (nMax - nCur);
   int nSub = FloatToInt  (nDif * 0.50);
    int nKey = GetLocalInt (oPC, "nKey");
    string sPlayerID = ObjectToString(oPC) + GetPCPublicCDKey(oPC, TRUE);
    int nRestTimer = GetLocalInt(GetModule(), "RestTimer" + sPlayerID);



    switch (GetLastRestEventType())
    {
        case REST_EVENTTYPE_REST_STARTED:
        {

            object oSpawn;
            object oChest = GetObjectByTag(CHEST_TAG);
            object oRestItem = GetFirstItemInInventory(oChest);
            object oItem;
            int nValidRest = TRUE;
            while (GetIsObjectValid(oRestItem))
            {
                oItem = GetItemPossessedBy(oPC, GetTag(oRestItem));
                if (GetIsObjectValid(oItem))
                    break;
                oRestItem = GetNextItemInInventory(oChest);
            }
            if (nRestTimer)
            {
                FloatingTextStringOnCreature("You are unable to rest for another " + IntToString(nRestTimer) + " minute(s)", oPC);
                nValidRest = FALSE;

            }

             if ( GetItemPossessedBy(oPC, "TDNBEDROLL") == OBJECT_INVALID )
              if ( GetLevelByClass(CLASS_TYPE_DRUID, oPC) == 0  &&  GetLevelByClass(CLASS_TYPE_RANGER, oPC) == 0 &&  GetLevelByClass(CLASS_TYPE_BARBARIAN, oPC) == 0 )
               if ( GetLocalInt(oPC, "nKey") <= 0 )
           {

                FloatingTextStringOnCreature("You do not posess the required bedroll for resting.", oPC);
                nValidRest = FALSE;
            }
            if (!GetIsObjectValid(oItem))

            {
                FloatingTextStringOnCreature("You do not possess the required food items for resting.", oPC);
                nValidRest = FALSE;

            }
            if (nValidRest)
            {
                int nStackSize = GetItemStackSize(oItem);
                if (nStackSize > 1)
                    SetItemStackSize(oItem, nStackSize - 1);




                else
    if ( GetLocalInt(oPC, "nKey") <= 0 )
     if ( GetLevelByClass(CLASS_TYPE_DRUID, oPC) == 0  &&  GetLevelByClass(CLASS_TYPE_RANGER, oPC) == 0 &&  GetLevelByClass(CLASS_TYPE_BARBARIAN, oPC) == 0 )
   oSpawn = CreateObject(OBJECT_TYPE_PLACEABLE, "bedroll", GetLocation(oPC));

          DestroyObject(oItem);
                RestTimerCounter(oPC, sPlayerID, REST_DELAY_TIMER);
 effect eDamage;
 if ( GetLevelByClass(CLASS_TYPE_DRUID, oPC) == 0  &&  GetLevelByClass(CLASS_TYPE_RANGER, oPC) == 0 &&  GetLevelByClass(CLASS_TYPE_BARBARIAN, oPC) == 0)
 if ( GetLocalInt(oPC, "nKey") <= 0 )
 if ( GetHitDice(oPC) <= 13 )

         eDamage = EffectDamage(nSub,DAMAGE_TYPE_MAGICAL);
DelayCommand(16.0,  ApplyEffectToObject(DURATION_TYPE_INSTANT, eDamage, oPC));
DelayCommand(16.5, DestroyObject(oSpawn));
effect nDamage;
if ( GetLevelByClass(CLASS_TYPE_DRUID, oPC) == 0  &&  GetLevelByClass(CLASS_TYPE_RANGER, oPC) == 0 &&  GetLevelByClass(CLASS_TYPE_BARBARIAN, oPC) == 0)
if ( GetLocalInt(oPC, "nKey") <= 0 )
if ( GetHitDice(oPC) >= 14 )

         nDamage = EffectDamage(nSub,DAMAGE_TYPE_MAGICAL);
DelayCommand(20.0,  ApplyEffectToObject(DURATION_TYPE_INSTANT, nDamage, oPC));
DelayCommand(20.5, DestroyObject(oSpawn));

    if(GetLastRestEventType() == REST_EVENTTYPE_REST_STARTED)

    ExecuteScript("x2_mod_def_rest", oPC);

}


            else

                AssignCommand(oPC, ClearAllActions());
            }
            break;
        }
    }
----snip----

I'm not sure if the error is in the OnRest, or the system.

The problem I am experiencing is that once I hit "rest"; the opening to the conversation is repeated over and over until the PC stops the script by moving. No conversation starts.
               
               

               


                     Modifié par Evelath, 25 juin 2013 - 03:07 .
                     
                  


            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Resting System Trouble
« Reply #1 on: June 25, 2013, 04:01:18 am »


               

void main()
{
   object oPC = GetPCSpeaker();

   AssignCommand(oPC, ActionRest(FALSE));
...


You are initiating a rest in the dialogue caused by the rest.
               
               

               
            

Legacy_Evelath

  • Full Member
  • ***
  • Posts: 108
  • Karma: +0/-0
Resting System Trouble
« Reply #2 on: June 25, 2013, 04:11:53 am »


               I removed the Command, however a rest does not take place when selecting that branch in the conversation.
               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
Resting System Trouble
« Reply #3 on: June 25, 2013, 05:59:52 pm »


               If you are running that script from the conversation I don't know that it is valid to use all the rest related commands anymore. Once you start the conversation and end that script you aren't running in the context of the onplayer rest event anymore. i.e. GetLastRestEventType() may not return anything useful.
               
               

               
            

Legacy_Evelath

  • Full Member
  • ***
  • Posts: 108
  • Karma: +0/-0
Resting System Trouble
« Reply #4 on: June 26, 2013, 12:09:41 am »


               

meaglyn wrote...

If you are running that script from the conversation I don't know that it is valid to use all the rest related commands anymore. Once you start the conversation and end that script you aren't running in the context of the onplayer rest event anymore. i.e. GetLastRestEventType() may not return anything useful.


I'm not sure I understand what you're implying for the resolution of the trouble.

Are you suggesting that I replicate the process of resting via scripts since I am using it from the Conversation?
               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
Resting System Trouble
« Reply #5 on: June 26, 2013, 12:48:23 am »


               

Evelath wrote...

I'm not sure I understand what you're implying for the resolution of the trouble.

Are you suggesting that I replicate the process of resting via scripts since I am using it from the Conversation?


What you're trying to do is a bit complicated because you will very easily get into loops. 

I assume that the rest script is only called from an action taken line in the conversation. In that case you might
try simply removing the tests for REST_STARTED. And don't call the default rest script at the end. 

In order for that to work you will need to call ForceRest on the PC when you do the resting. You'll be effectively completely circumventing the use of the games resting mechanism.

You also want to put  the test for REST_STARTED in the first script instead because that event will likely get called several times in a rest cycle.  

I'm just putting this together from memory though... 

Your onrest handler wants to be something like this:

void main()
{
    object oPC = GetLastPCRested();
    if (!GetIsPC(oPC)) return;

    if (GetLastRestEventType() == REST_EVENTTYPE_REST_STARTED) { 
        AssignCommand(oPC, ClearAllActions());
       AssignCommand(oPC, ActionStartConversation(OBJECT_SELF,"rest_conv",TRUE,FALSE));
   }

}

And then yes, you need to do all the resting work in your script
(ForceRest to get the healing and spell effects etc).