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 .