Author Topic: REST_EVENTTYPE_REST_FINISHED  (Read 434 times)

Legacy_Rio420

  • Full Member
  • ***
  • Posts: 112
  • Karma: +0/-0
REST_EVENTTYPE_REST_FINISHED
« on: September 04, 2013, 10:51:30 pm »


                Where do you find the code to do damage to a player upon resting?  This module has a ridiculous amount set, so much so that with 1/79hp, I only received 2hp from resting!  I need to find where to change that, I'm sure I've looked at it 5 or 6 times already and just overlooked it.
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
REST_EVENTTYPE_REST_FINISHED
« Reply #1 on: September 05, 2013, 12:25:23 am »


               I did something like this with my rest system. So I only know how that functioned.

First, look at the rest event script for the module under module properties. It is OnRest or some such. Then in the main of that script look for the rest finished sub-event.

In the work I did, I first recorded how many hitpoints the PC had when they started resting, so that may be a part of this too.
               
               

               
            

Legacy_Rio420

  • Full Member
  • ***
  • Posts: 112
  • Karma: +0/-0
REST_EVENTTYPE_REST_FINISHED
« Reply #2 on: September 05, 2013, 12:45:24 am »


               From what I see in the OnRest / rest finished sub event, it calls:

ResetRestingHP()

This is the block of code for ResetRestingHP:


void ResetRestingHP(object oPC)
{
   int nSHP=GetLocalInt(GetModule(),("HPStartRest"+GetName(oPC)+GetPCPublicCDKey(oPC)));
   if(nSHP == 0 || nSHP>=GetCurrentHitPoints(oPC)) return;

   int nRestHP = GetCurrentHitPoints(oPC);

   int nDam = nRestHP-nSHP;
   effect eDamage = EffectDamage(nDam);
   ApplyEffectToObject(DURATION_TYPE_INSTANT, eDamage, oPC);
   RemoveSpells(oPC);
   SendMessageToAllDMs("WARNING: "+GetName(oPC)+" may be trying to cancel rest to re-gain spells.");
   object oFam = GetPCFamiliar(oPC);
   if(GetIsObjectValid(oFam))
      DelayCommand(1.0,pet_rest_dam(oFam, oPC));
}

Maybe I'm confused, but it looks like it's getting the current hitpoints of the PC and getting a local integer for the module assigned to HPStartRest and then subtracting that value from the first. And that is the damage.  The question is, where is that local int being stored?
               
               

               
            

Legacy_Rio420

  • Full Member
  • ***
  • Posts: 112
  • Karma: +0/-0
REST_EVENTTYPE_REST_FINISHED
« Reply #3 on: September 05, 2013, 01:03:24 am »


               Yeah, if I'm reading this right, it's basically set up to get the current hp of the player, subtract from the max, thus if I have 1hp out of 70, I'll take 69 damage on resting... wtf? lol
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
REST_EVENTTYPE_REST_FINISHED
« Reply #4 on: September 05, 2013, 01:11:37 am »


               it doesn't let you recover HP at rest perhaps. You need to look at where it stores that information about HP at start of rest.
               
               

               
            

Legacy_MagicalMaster

  • Hero Member
  • *****
  • Posts: 2712
  • Karma: +0/-0
REST_EVENTTYPE_REST_FINISHED
« Reply #5 on: September 05, 2013, 01:25:31 am »


               

SendMessageToAllDMs("WARNING: "+GetName(oPC)+" may be trying to cancel rest to re-gain spells.");


Based on that line, it seems this might be intended to stop the following:

1, let's say a resting timer exists at 10 minutes

2, Bob the mage has used his spells and can rest

3, he knows that he'll use all of his spells within the next 4-5 minutes so he tries to be clever

4, he rests 95% of the way and then cancels the rest - restoring most of his spells and HP without starting the 10 minute timer

I'd suggest you post the entire rest script if you can't figure it out.
               
               

               
            

Legacy_Rio420

  • Full Member
  • ***
  • Posts: 112
  • Karma: +0/-0
REST_EVENTTYPE_REST_FINISHED
« Reply #6 on: September 05, 2013, 01:39:49 am »


               Here's the entire script, the other script this ties into will follow below this one:


//::///////////////////////////////////////////////
//:: AD On Rest
//:: ad_on_play_rest
//with Purple Rose v 1.1.3
//::///////////////////////////////////////////////
#include "pri_inc"
#include "srace_inc"
#include "ad_inc_food_rest"
#include "hc_inc_fatigue"
#include "ad_inc_cls_restr"
#include "ad_debug_inc"
#include "inc_movement"

int iRESTBREAK;
int iFOODSYSTEM;
int iMinRest;
int nRestHP;
int nSSB;
int nHasFood;
object oBedroll;
int iCount;
int iBedUse;
//object oMod = GetModule();


void InitRestVariables()
{
    // FOODSYSTEM - Controls if the player needs to eat
    iFOODSYSTEM = 1;
    // RESTBREAK - Controls how long between rests in hours
    iRESTBREAK = 4;
    iMinRest = iRESTBREAK*nConv;
    nSSB=SecondsSinceBegin();
}

void SetRestTime(object oPC, int iCount)
{
   int iDec = iRESTBREAK/6;
   //int n0SSB = GetLocalInt(oMod, "SecSB"+GetName(oPC)+GetPCPublicCDKey(oPC));

   if(iDec < 1) iDec =1;
   iCount = iCount-iDec;
   if(iCount > 0)
   {
      int nNSB = nSSB-(iCount*60);
      if(nNSB < 1) nNSB = 1;
      if(GetLastRestEventType() == REST_EVENTTYPE_REST_STARTED)
      {
         SetLocalInt(oMod, ("LastRest" + GetName(oPC) + GetPCPublicCDKey(oPC)), nNSB);
         DelayCommand(6.0, SetRestTime(oPC, iCount));
      }
   }
}

// void ApplyArmorRestPenalty(object oPC)
//{
    // Armor penalty.  Check only if rest fully completed.
//    if (GetLastRestEventType() == REST_EVENTTYPE_REST_FINISHED ) {
        //int bFatigued = GetLocalInt(oPC, "bFatigued");
        //int bExhausted = GetLocalInt(oPC, "bExhausted");
        // Check for armor, and give a penalty for armor +5 and above.
//        object oArmor = GetItemInSlot(INVENTORY_SLOT_CHEST, oPC);
//        if(GetChestArmorBaseType(oArmor) > 1 && GetChestArmorBaseType(oArmor) <= 5)
//        {
//           MakePlayerFatigued(oPC,FATIG);
//        }else if(GetChestArmorBaseType(oArmor) > 5) {
//           MakePlayerExhausted(oPC,EXHAUS);
//        }
//    }
// }

int DoesPCHaveBedroll(object oPC)
{
        oBedroll = GetItemPossessedBy(oPC,"bedroll");
        if (GetIsObjectValid(oBedroll))
            return 1;
        else {
            oBedroll = GetLocalObject(oMod,"inbedroll" + GetName(oPC) + GetPCPublicCDKey(oPC));
            if (GetIsObjectValid(oBedroll))
                return 1;
        }
    return 0;
}

void ApplySleepEffects(object oPC)
{
    effect eSnore = EffectVisualEffect(VFX_IMP_SLEEP);
    ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eSnore, oPC, 7.0);
    //insert special effects here. I tried EffectSleep along with different
    //animations. They either get overrode by the rest anim or cancel the rest.
    ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eSnore, oPC, 7.0);
    effect eBad = GetFirstEffect(oPC);
    //Search for negative effects
    int nBlindMe=1;
    while(GetIsEffectValid(eBad))
    {
        int nEtype=GetEffectType(eBad);
        if(nEtype==EFFECT_TYPE_TRUESEEING)
            nBlindMe=0;
        eBad=GetNextEffect(oPC);
    }
    if(nBlindMe)
    {
        effect eBlind =  EffectBlindness();
        ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eBlind, oPC, 29.0);
    }
    DelayCommand(7.0, ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eSnore, oPC, 7.0));
}

void RemoveSleepBlindness(object oPC)
{
    effect eBad = GetFirstEffect(oPC);
    //Search for negative effects
    while(GetIsEffectValid(eBad)) {
        int nEtype=GetEffectType(eBad);
        if (nEtype == EFFECT_TYPE_BLINDNESS) {
            //Remove effect if it is negative.
            RemoveEffect(oPC, eBad);
        }
        eBad = GetNextEffect(oPC);
    }
}

void ReplaceBedroll(object oPC)
{
    oBedroll=GetLocalObject(oMod, "inbedroll"+GetName(oPC)+GetPCPublicCDKey(oPC));
    CreateItemOnObject("bedroll", oPC);
    DestroyObject(oBedroll);
    DeleteLocalObject(oMod, "inbedroll"+GetName(oPC)+GetPCPublicCDKey(oPC));
}


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

    // DEBUG PRINT OUT
    if (AD_DEBUG == 1) {
    string sDebug = "ad_on_play_rest: "+GetName(oPC)+" attempt to rest";
    PrintString(sDebug); }

    string sID = GetName(oPC) + GetPCPublicCDKey(oPC);
// See if they are in a Barracks
    object oArea = GetArea(oPC);
    int nBARRACK = GetLocalInt(oPC, "BARRACKS");
    object oFam = GetPCFamiliar(oPC);

    if(GetLastRestEventType() == REST_EVENTTYPE_REST_FINISHED){
       EffectArmorEncumbrance(oPC);
       RestrictionCheckDruid(oPC);
       if(GetLocalInt(oPC,"NOSPELLS")==1)
          RemoveAllSpellsAndFeats(oPC);
    }

    if(GetLastRestEventType() == REST_EVENTTYPE_REST_STARTED)
       nRestHP = GetCurrentHitPoints(oPC);

    // Don't allow rest if it is restricted
    object noRest = GetNearestObjectByTag("NORESTWP", oPC);
    if(GetIsObjectValid(noRest))
    {
      AssignCommand( oPC, ClearAllActions());
      FloatingTextStringOnCreature("You must rest in a Inn or Tavern!",oPC,FALSE);
      return;
    }

    string sFullArea = GetStringUpperCase(GetTag(oArea));
    int nBarks = FindSubString(sFullArea, "BARRACK");
    int nSRace = sr_GetSubRace(oPC);
    if(nBarks != -1)
    {
      // Vamp fledgling check
      if(nSRace==SUBRACE_VAMPIRE && GetHitDice(oPC)>4)
      {
         AssignCommand( oPC, ClearAllActions());
         FloatingTextStringOnCreature(VAMPNOREST,oPC,FALSE);
      }else{
         if(GetLastRestEventType() == REST_EVENTTYPE_REST_STARTED)
         {
            ApplySleepEffects(oPC);
            SavePreRestFamiliarHP(oPC, oFam);
         }
         if(GetLastRestEventType() == REST_EVENTTYPE_REST_FINISHED)
         {
            SetLocalInt(oPC,"RESTING",0);
            DeleteLocalInt(oPC, "REST");
            RemoveSleepBlindness(oPC);
            SetSubRaceAbilites(oPC, nSRace);
         }
      }
      SetLocalInt(oPC, "BARRACKS",1);
      return;
    }

    if(GetCurrentHitPoints(oPC)<=FloatToInt((IntToFloat(GetMaxHitPoints(oPC))*0.2)))
       DeleteLocalInt(oMod, ("LastRest" + sID));

    int iBedroll;
    int iBedUse = GetLocalInt(oPC, "RSA_BedUse");

    if (iBedUse == 0) iBedroll = DoesPCHaveBedroll(oPC);

    //Start of Inn Resting Mod

    int iCanBedRoll = 1;
    int iSleep = 0;
    int iKill = 0;
    int iWakeUp = 0;
    int iRatChance = 0;
    int iFail = 0;

    string sWhyNoSleep = "Error in pri_on_play_rest script";
    string sPoorRoom = "Error in pri_on_play_rest script";
    //string sFood = GetLocalString(oPC, "RSA_FoodType");

    object oButler = OBJECT_INVALID;

    object oPRIForceInnRest = GetNearestObjectByTag("PRIForceInnRest", oPC);
    if (GetIsObjectValid(oPRIForceInnRest)) iCanBedRoll = 0;

    if(iBedUse > 0)
    {
        DeleteLocalInt(oMod, ("LastRest" + sID));
        GetInnArea(oPC);

        iRatChance = GetLocalInt(oPC, "RSA_RatChance");

        string sButler = GetLocalString(oPC, "RSA_Butler");
        sPoorRoom = GetLocalString(oPC, "RSA_PoorWake");

        oButler = GetObjectByTag(sButler);

        if(iBedUse == iRSA_POORBED) iWakeUp = 1;
        if(iBedUse == iRSA_RICHBED) iKill = GetLocalInt(oButler, "RSA_KillInSleep");
    }

    if(iBedUse > 0 || (iCanBedRoll > 0 && iBedroll > 0)) iSleep = 1;

    if(iSleep == 0 && GetLastRestEventType() == REST_EVENTTYPE_REST_STARTED)
    {
        AssignCommand(oPC, ClearAllActions());
        sWhyNoSleep = NOBEDROLL;
        if (iCanBedRoll == 0) sWhyNoSleep = SLEEPINN;
        FloatingTextStringOnCreature(sWhyNoSleep, oPC, FALSE);
        return;
    }
    // Vampire for sleeping in a Inn
    if(iBedUse > 0 && nSRace==SUBRACE_VAMPIRE && GetHitDice(oPC)>4 &&
       GetLastRestEventType() == REST_EVENTTYPE_REST_STARTED)
    {
        AssignCommand(oPC, ClearAllActions());
        FloatingTextStringOnCreature(VAMPNOREST, oPC, FALSE);
        return;
    }

    if((iSleep == 0 && GetLastRestEventType() == REST_EVENTTYPE_REST_CANCELLED) ||
        (iSleep == 0 && GetLastRestEventType() == REST_EVENTTYPE_REST_FINISHED))
         {
            return;
         }
    //End of Inn Sleeping Mod


    InitRestVariables();
    // Limit group resting
    //if(nSRace=!SUBRACE_VAMPIRE && RestrictPartyRestOnLimitRestHealAndArmorPen(oPC)) return;

    // Vampires dont need food
    if(nSRace == SUBRACE_VAMPIRE)
    {
       if(!GetLocalInt(oPC, "IN_COFFIN"))
       {
         AssignCommand( oPC, ClearAllActions());
         FloatingTextStringOnCreature(VAMPNOREST, oPC, FALSE);
         return;
       }else{
         // Vamps dont need food
         iFOODSYSTEM = 0;
         nHasFood = 1;
       }
    }

    if(GetLastRestEventType() == REST_EVENTTYPE_REST_STARTED)
    {
        SavePreRestFamiliarHP(oPC, oFam);
        if(iFOODSYSTEM) nHasFood = 0;
        SetLocalInt(oMod,"HPStartRest" + sID,nRestHP);
        object oFood;
        int iFail = 0;

        // Fail checks
        iMinRest = iRESTBREAK*nConv;//(iRESTBREAK+4)*nConv;
        if(iBedUse == 0)
        {
           if(iFail==0) iFail = IsTooSoonToRest(oPC, iMinRest, nSSB, nConv);
           if(iFail==0) iFail = IsPCTooWeakToRest(oPC);
           if(iFOODSYSTEM && !iFail)
           {
              if(HasPCEaten(oPC)==1)
                 nHasFood = 1;
              else
                 iFail = 1;
           }
        }


        if(iFail==0)
        {
           ApplySleepEffects(oPC);
        }else
           return;

        if(iBedroll && iBedUse == 0)
        {
            object oNewBedroll=CreateObject(OBJECT_TYPE_PLACEABLE,"bedroll",GetLocation(oPC));
            DestroyObject(oBedroll);
            SetLocalInt(oMod,"LostBedRoll"+sID,1);
            SetLocalObject(oMod,"inbedroll"+sID,oNewBedroll);
        }
        //PRI Mod
        if(iBedUse > 0)
        {
            if(iWakeUp == 1 && iFail == 0)
            {
                int iRoll = d100(1);
                if(iRoll >= iRatChance)
                {
                    AssignCommand(oPC, ClearAllActions());
                    SendMessageToPC(oPC, sPoorRoom);
                }
            }

            if(iKill == 1 && iFail == 0)
            {
                SendMessageToAllDMs(GetName(oPC)+" has been targeted by the Assassin in "+GetName(GetArea(oPC))+".");
                location lLoc = GetLocation(GetWaypointByTag("AssassinSpawn"));
                object oAssassin = CreateObject(OBJECT_TYPE_CREATURE, "assassian", lLoc, TRUE);
                AssignCommand(oAssassin, ActionAttack(oPC, FALSE));
                SetLocalInt(oButler, "RSA_KillInSleep", 0);
                SendMessageToAllDMs("Assassin in"+GetName(GetArea(oPC))+" is now toggled off!");
            }
        }
        //End of PRI Mod
    }

    if(iFOODSYSTEM && iFail==0 && nHasFood==1)
    {
       if(!DidPCSetUpCamp(oPC) && GetLastRestEventType() == REST_EVENTTYPE_REST_STARTED)
       {
          if(RestrictPartyRestOnLimitRestHealAndArmorPen(oPC)) return;
          iCount = iRESTBREAK;
          DelayCommand(1.5, SetRestTime(oPC, iCount));
       }
    }else if(!iFOODSYSTEM && GetLastRestEventType() == REST_EVENTTYPE_REST_STARTED){
       iCount = iRESTBREAK;
       DelayCommand(1.5, SetRestTime(oPC, iCount));
    }

    int nLastRestType=GetLastRestEventType();
    if(nLastRestType == REST_EVENTTYPE_REST_FINISHED || nLastRestType == REST_EVENTTYPE_REST_CANCELLED)
    {
        RemoveSleepBlindness(oPC);
        if (iBedroll && iBedUse == 0 && nBARRACK==0 && GetLocalInt(oMod,"LostBedRoll"+sID)==1)
        {
           ReplaceBedroll(oPC);
           DeleteLocalInt(oMod,"LostBedRoll"+sID);
        }

        //set the variables for the current time to mark the pc as resting

        SetLocalInt(oPC,"RESTING",0);
        DeleteLocalInt(oPC, "REST");

        if(nLastRestType == REST_EVENTTYPE_REST_FINISHED)
        {
           if(iFOODSYSTEM && !iBedUse) GetFoodEaten(oPC);
           if(iFOODSYSTEM && iBedUse) ApplyInnRest(oPC, iBedUse);
           // Vampire heal
           if(!iFOODSYSTEM) ApplyInnRest(oPC, 4);

           iCount = iRESTBREAK;
           DelayCommand(1.5, SetRestTime(oPC, iCount));
           //SetLocalInt(oMod, "SecSB"+sID, nSSB);

//           if(nBARRACK==0) ApplyArmorRestPenalty(oPC);
           if(nSRace > 0) SetSubRaceAbilites(oPC, nSRace);

           if(!GetIsDM(oPC))
              SetLocalInt(oMod, ("LastRest" + sID), nSSB);

           effect eConDec = ExtraordinaryEffect(EffectAbilityDecrease(ABILITY_CONSTITUTION,GetLocalInt(oMod,"CONPEN"+sID)));
           DelayCommand(1.0, DeleteLocalInt(oMod,"HPStartRest" + sID));
        }

        if(nLastRestType == REST_EVENTTYPE_REST_CANCELLED)
        {
           SetSubRaceAbilites(oPC, nSRace);
           ResetRestingHP(oPC);
        }

        DeleteLocalInt(oPC, "BARRACKS");
        DeleteLocalInt(oPC, "RSA_BedUse");
        DeleteLocalInt(oPC, "RSA_HasRoom");
    }
}

Here's the other file:


// Food and Rest Functions
//void main() {}
//::////////////////////////////////////////////
//:: Creating Food follow this model
//:: Food_<type><bonus>
//:: i.e.   Food_NORM2
//:: TYPES:   POOR, NORM, RICH, MAGI
//:: BONUSES: 0, 1
//::////////////////////////////////////////////
#include "ad_text_rest"
#include "hc_i0_plyrstate"
#include "hc_i0_timecheck"

int HasPCEaten(object oPC);
void EatFood(object oPC, object oFood);
void ClearFood(object oPC);
void GetFoodEaten(object oPC);
void ApplyFoodEffects(object oPC, int nHeal, int nBonus);
// Call on Rest Cancel and player enter.
void ResetRestingHP(object oPC);
object GetPCFamiliar(object oPC);
void pet_rest_dam(object oFam, object oPC, int nAny=0);
int RestrictPartyRestOnLimitRestHealAndArmorPen(object oPC);
void SavePreRestFamiliarHP(object oPC, object oFam);
int IsTooSoonToRest(object oPC, int iMinRest, int nSSB, int nConv);
int IsPCTooWeakToRest(object oPC);
int DidPCSetUpCamp(object oPC);
void ApplyInnRest(object oPC, int nHeal);
// Remove all player spells
void RemoveSpells(object oPC);
// Cook some food
void CookFood(string sTag, object oPC);


//:: FUNCTIONS :://
void CookFood(string sTag, object oPC)
{
   if(FindSubString(sTag, "FISH")!= -1)
      CreateItemOnObject("fish", oPC);
   else if(FindSubString(sTag, "BAT")!= -1)
      CreateItemOnObject("food_bat", oPC);
   else if(FindSubString(sTag, "BADGER")!= -1)
      CreateItemOnObject("food_badger", oPC);
   else if(FindSubString(sTag, "BEAR")!= -1)
      CreateItemOnObject("food_bear", oPC);
   else if(FindSubString(sTag, "VENISON")!= -1)
      CreateItemOnObject("food_deer", oPC);
   else if(FindSubString(sTag, "FELINE")!= -1)
      CreateItemOnObject("food_feline", oPC);
   else if(FindSubString(sTag, "WOLF")!= -1)
      CreateItemOnObject("food_wolf", oPC);
   else
      CreateItemOnObject("cookedfood", oPC);
}

void ApplyInnRest(object oPC, int nHeal)
{
    object oMod = GetModule();
    int nHD=GetHitDice(oPC)*nHeal;
    int nSHP=GetLocalInt(oMod,("HPStartRest"+GetName(oPC)+GetPCPublicCDKey(oPC)));
    int nDam;
    int nLTC;

    //Double healing rate if long term care was applied successfully.
    if(GetLocalInt(oMod, "LONGTERMCARE"+GetName(oPC)+GetPCPublicCDKey(oPC)) == 2)
       nLTC=GetHitDice(oPC)*2;
    else
       nLTC=0;

    if(GetCurrentHitPoints() > (nSHP+nHD+nLTC))
    {
        nDam=(GetCurrentHitPoints() - (nSHP+nHD+nLTC));
        effect eDamage = EffectDamage(nDam);
        ApplyEffectToObject( DURATION_TYPE_INSTANT, eDamage, oPC);
    }
    DeleteLocalInt(oMod, "LONGTERMCARE"+GetName(oPC)+GetPCPublicCDKey(oPC));

    object oFam = GetPCFamiliar(oPC);
    if(GetIsObjectValid(oFam))
       DelayCommand(1.0,pet_rest_dam(oFam, oPC));
}

int DidPCSetUpCamp(object oPC)
{
   int nCamp = 1;
   // Ranger or Druid go no further
   if(GetLevelByClass(CLASS_TYPE_RANGER, oPC)>0 || GetLevelByClass(CLASS_TYPE_DRUID, oPC)>0)
      return nCamp;

   int nCreatureChance = 79;
   object oCamp = GetNearestObjectByTag("hc_campfire", oPC);
   if(!GetIsObjectValid(oCamp))
      nCamp = 0;

   string sID = GetName(oPC) + GetPCPublicCDKey(oPC);

   if(GetIsObjectValid(oCamp) && GetDistanceBetween(oPC, oCamp) > 6.0)
   {
      if(d100() <= nCreatureChance)
      {
         FloatingTextStringOnCreature(NOCAMP, oPC, FALSE);
         AssignCommand(oPC, ClearAllActions());
         SetLocalInt(GetModule(), ("LastRest" + sID), SecondsSinceBegin());
      }
      nCamp = 0;
   }

   return nCamp;
}

int HasPCEaten(object oPC)
{
    int nResult = 0;

    if(GetLocalInt(oPC,"FOODHEAL")>0)
    {
        nResult = 1;
    }else{
        FloatingTextStringOnCreature(TOOHUNGRY, oPC, FALSE);
        AssignCommand( oPC, ClearAllActions());
    }
    return nResult;
}

void EatFood(object oPC, object oFood)
{
   string sTag = GetTag(oFood);
   string sType = GetStringRight(GetStringLeft(sTag,9),4);
   int nNum = GetStringLength(sTag)-9;
   int nBonus = StringToInt(GetStringRight(sTag, nNum));
   int nHeal;

   if(sType == "POOR") nHeal = 1;
   if(sType == "NORM") nHeal = 2;
   if(sType == "RICH") nHeal = 3;
   if(sType == "MAGI") nHeal = 5;

   SetLocalInt(oPC, "FOODHEAL", nHeal);
   SetLocalInt(oPC, "FOODBONUS", nBonus);
   // Effects valid for 8 hours OR until Rest
   DelayCommand(HoursToSeconds(8), DeleteLocalInt(oPC, "FOODHEAL"));
   DelayCommand(HoursToSeconds(8), DeleteLocalInt(oPC, "FOODBONUS"));

   AssignCommand(oPC, ActionPlayAnimation(ANIMATION_FIREFORGET_SALUTE, 1.0));
   DelayCommand(0.8, AssignCommand(oPC, ActionSpeakString(MUNCHFOOD)));

   SendMessageToPC(oPC, EATFOOD + " [" + GetName(oFood) + "]");
   DestroyObject(oFood);
}

void ClearFood(object oPC)
{
   DeleteLocalInt(oPC, "FOODHEAL");
   DeleteLocalInt(oPC, "FOODBONUS");
}

void GetFoodEaten(object oPC)
{
   int nHeal = GetLocalInt(oPC, "FOODHEAL");
   int nBonus = GetLocalInt(oPC, "FOODBONUS");
   ApplyFoodEffects(oPC, nHeal, nBonus);
   ClearFood(oPC);
}

void ApplyFoodEffects(object oPC, int nHeal, int nBonus)
{
    object oMod = GetModule();
    int nHD=GetHitDice(oPC)*nHeal;
    SpeakString(IntToString(nHD));
    int nSHP=GetLocalInt(oMod,("HPStartRest"+GetName(oPC)+GetPCPublicCDKey(oPC)));
    SpeakString(IntToString(nSHP));
    int nDam;
    int nLTC;

    //Double healing rate if long term care was applied successfully.
    if(GetLocalInt(oMod, "LONGTERMCARE"+GetName(oPC)+GetPCPublicCDKey(oPC)) == 2)
       nLTC=GetHitDice(oPC)*2;
    else
       nLTC=0;

    if(GetCurrentHitPoints(oPC) > (nSHP+nHD+nLTC))
    {
        nDam = GetCurrentHitPoints(oPC) - (nSHP+nHD+nLTC);
        effect eDamage = EffectDamage(nDam);
        ApplyEffectToObject( DURATION_TYPE_INSTANT, eDamage, oPC);
    }
    DeleteLocalInt(oMod, "LONGTERMCARE"+GetName(oPC)+GetPCPublicCDKey(oPC));

    object oFam = GetPCFamiliar(oPC);
    if(GetIsObjectValid(oFam))
       DelayCommand(1.0,pet_rest_dam(oFam, oPC));

    // Do bonuses
    if(nBonus == 0) return;

    int nModify = d4() + 1;
    float fDuration = RoundsToSeconds(d10());
    effect eVis = EffectVisualEffect(VFX_IMP_IMPROVE_ABILITY_SCORE);
    effect eBonus, eLink;
    if(nBonus ==1){ // Poison Food
       SendMessageToPC(oPC, "You start to feel sick.");
       SendMessageToAllDMs(GetName(oPC)+" ate some poisoned food!");
       effect ePoison = EffectPoison(POISON_TINY_SPIDER_VENOM);
       ApplyEffectToObject(DURATION_TYPE_PERMANENT, ePoison, oPC);
    }
    if(nBonus == 2){ // Hero's Feast
       effect eRemove = GetFirstEffect(oPC);
       while(GetIsEffectValid(eRemove))
       {
          if(GetEffectType(eRemove)==EFFECT_TYPE_DISEASE||GetEffectType(eRemove)==EFFECT_TYPE_POISON
             ||GetEffectType(eRemove)==EFFECT_TYPE_NEGATIVELEVEL)
          {
             RemoveEffect(oPC, eRemove);
          }
          ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectHeal(d4()+4),oPC);
       }
    }
    if(nBonus==3){ // Badger
       eBonus = EffectAbilityIncrease(ABILITY_STRENGTH,nModify);
       eLink = EffectLinkEffects(eBonus, eVis);
       ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eLink, oPC, fDuration);
    }
    if(nBonus==4){ // Feline
       eBonus = EffectAbilityIncrease(ABILITY_DEXTERITY,nModify);
       eLink = EffectLinkEffects(eBonus, eVis);
       ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eLink, oPC, fDuration);
    }
    if(nBonus==5){ // Wolf
       eBonus = EffectMovementSpeedIncrease(30);
       eLink = EffectLinkEffects(eBonus, eVis);
       ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eLink, oPC, fDuration);
    }
    DeleteLocalInt(oMod,("HPStartRest"+GetName(oPC)+GetPCPublicCDKey(oPC)));
}

void ResetRestingHP(object oPC)
{
   int nSHP=GetLocalInt(GetModule(),("HPStartRest"+GetName(oPC)+GetPCPublicCDKey(oPC)));
   if(nSHP == 0 || nSHP>=GetCurrentHitPoints(oPC)) return;

   int nRestHP = GetCurrentHitPoints(oPC);

   int nDam = nRestHP-nSHP;
   effect eDamage = EffectDamage(nDam);
   ApplyEffectToObject(DURATION_TYPE_INSTANT, eDamage, oPC);
   RemoveSpells(oPC);
   SendMessageToAllDMs("WARNING: "+GetName(oPC)+" may be trying to cancel rest to re-gain spells.");
   object oFam = GetPCFamiliar(oPC);
   if(GetIsObjectValid(oFam))
      DelayCommand(1.0,pet_rest_dam(oFam, oPC));
}

object GetPCFamiliar(object oPC)
{
    object oFam=GetAssociate(ASSOCIATE_TYPE_FAMILIAR, oPC);
    if(!GetIsObjectValid(oFam))
           oFam=GetAssociate(ASSOCIATE_TYPE_ANIMALCOMPANION, oPC);
    return oFam;
}

void pet_rest_dam(object oFam, object oPC, int nAny=0)
{
    int nSHP=GetLocalInt(oPC,"FamiliarHealth");
    int nHD=GetHitDice(oPC);
    int nRestHP=GetCurrentHitPoints(oFam);
    if((nRestHP > nSHP+nHD) || nAny) {
        int nDam=(nRestHP-(nSHP+nHD));
        if(nAny) nDam=nRestHP-nSHP;
        effect eDamage = EffectDamage(nDam,
        DAMAGE_TYPE_MAGICAL, DAMAGE_POWER_NORMAL);
        ApplyEffectToObject( DURATION_TYPE_INSTANT, eDamage, oFam);
    }
}

int RestrictPartyRestOnLimitRestHealAndArmorPen(object oPC)
{
    object oPM=GetFirstFactionMember(oPC);
    while(GetIsObjectValid(oPM))
    {
       if(GetLocalInt(oPM,"RESTING") && oPM != oPC)
       {
          AssignCommand(oPC, ClearAllActions());
          SendMessageToPC(oPC,"You cannot rest while another party member is resting, sleep in shifts.");
          return 1;
        }
        oPM=GetNextFactionMember(oPC);
    }
    return 0;
}

void SavePreRestFamiliarHP(object oPC, object oFam)
{
   if(GetIsObjectValid(oFam) && !GetLocalInt(oPC,"RESTING"))
       SetLocalInt(oPC,"FamiliarHealth",GetCurrentHitPoints(oFam));
}

int IsTooSoonToRest(object oPC, int iMinRest, int nSSB, int nConv)
{
    int nNotOkToRest = 0;

    string sRestedText = GetName(oPC) + NOTTIRED;
    //First get the time last rested and the current time.
    int iLastRest = GetLocalInt(GetModule(), ("LastRest" + GetName(oPC) + GetPCPublicCDKey(oPC)));

    if (iLastRest && ((iLastRest+iMinRest) > nSSB))
    {
        AssignCommand(oPC, ClearAllActions());
        sRestedText+=" Try again in ";
        if(((iMinRest+iLastRest)-nSSB)/nConv > 0)
            sRestedText+=IntToString(((iMinRest+iLastRest)-nSSB)/nConv) + " hours.";
        else
            sRestedText+=IntToString(((iMinRest+iLastRest)-nSSB)/6)+" minutes.";
        FloatingTextStringOnCreature(sRestedText,oPC,FALSE);
        nNotOkToRest = 1;
    }
    return nNotOkToRest;
}

int IsPCTooWeakToRest(object oPC)
{
    int nNotOkToRest = 0;
    if(GPS(oPC)==PS_RECOVERY)
    {
       FloatingTextStringOnCreature(NOTWELL, oPC, FALSE);
       AssignCommand( oPC, ClearAllActions());
       nNotOkToRest = 1;
    }
    return nNotOkToRest;
}

void RemoveSpells(object oPC)
{
   if(!GetIsPC(oPC)) return;
   int nSpell, nID, nLoop, nFeat;

   for(nID=0; nID < 498; nID++)
   {
      nSpell = GetHasSpell(nID, oPC);
      if(nSpell > 0)
      {
         for(nLoop=0; nLoop < nSpell; nLoop++)
         {
            // Only removes 1 use at a time
            DecrementRemainingSpellUses(oPC, nID);
         }
      }
   }

   for(nID=0; nID < 444; nID++)
   {
      nFeat = GetHasFeat(nID, oPC);
      if(nFeat > 0)
      {
         for(nLoop=0; nLoop < nFeat; nLoop++)
         {
            // Only removes 1 use at a time
            DecrementRemainingFeatUses(oPC, nID);
         }
      }
   }
}

Sorry for so much spam in this thread, the scripts are pretty big on this module.
               
               

               
            

Legacy_MagicalMaster

  • Hero Member
  • *****
  • Posts: 2712
  • Karma: +0/-0
REST_EVENTTYPE_REST_FINISHED
« Reply #7 on: September 05, 2013, 01:58:46 am »


               Holy moly that code is awful.  Like six different references to LAST_REST_EVENT_STARTED (or whatever that constant is) within main alone at different points.  Might have been done with the Script Generator or something.

I think I see part/all of the problem and looking into it more, but I have a serious question: how much do you care about the script?  It may be simpler to nuke most of the thing...
               
               

               


                     Modifié par MagicalMaster, 05 septembre 2013 - 12:59 .
                     
                  


            

Legacy_Rio420

  • Full Member
  • ***
  • Posts: 112
  • Karma: +0/-0
REST_EVENTTYPE_REST_FINISHED
« Reply #8 on: September 05, 2013, 02:04:40 am »


               Actually, far as I know it was written originally by a coder, but that was back in 2004, as for the script, unfortunately it's tied into the food system and ATS crafting system in spots, so I have to keep it as intact as I can.   Removing just about anything could and probably will break other things that are currently being used.    

Anyhow, what did you see?
               
               

               
            

Legacy_MagicalMaster

  • Hero Member
  • *****
  • Posts: 2712
  • Karma: +0/-0
REST_EVENTTYPE_REST_FINISHED
« Reply #9 on: September 05, 2013, 02:56:26 am »


               if(GetLastRestEventType() == REST_EVENTTYPE_REST_STARTED)
nRestHP = GetCurrentHitPoints(oPC);

if(GetLastRestEventType() == REST_EVENTTYPE_REST_STARTED)
{
SavePreRestFamiliarHP(oPC, oFam);
if(iFOODSYSTEM) nHasFood = 0;
SetLocalInt(oMod,"HPStartRest" + sID,nRestHP);
}

if(nLastRestType == REST_EVENTTYPE_REST_CANCELLED)
{
SetSubRaceAbilites(oPC, nSRace);
ResetRestingHP(oPC);
}

Looks like the ResetRestingHP thing is only called if you cancel the rest before finishing.  Are you actually completing the rest or did you stop earlier?

Otherwise, if you're actually completing the rest, it looks like the ApplyInnRest is more likely the culprit:

void ApplyInnRest(object oPC, int nHeal)
{
object oMod = GetModule();
int nHD=GetHitDice(oPC)*nHeal;
int nSHP=GetLocalInt(oMod,("HPStartRest"+GetName(oPC)+GetPCPublicCDKey(oPC)));
int nDam;
int nLTC;

//Double healing rate if long term care was applied successfully.
if(GetLocalInt(oMod, "LONGTERMCARE"+GetName(oPC)+GetPCPublicCDKey(oPC)) == 2)
nLTC=GetHitDice(oPC)*2;
else
nLTC=0;

if(GetCurrentHitPoints() > (nSHP+nHD+nLTC))
{
nDam=(GetCurrentHitPoints() - (nSHP+nHD+nLTC));
effect eDamage = EffectDamage(nDam);
ApplyEffectToObject( DURATION_TYPE_INSTANT, eDamage, oPC);
}
DeleteLocalInt(oMod, "LONGTERMCARE"+GetName(oPC)+GetPCPublicCDKey(oPC));

object oFam = GetPCFamiliar(oPC);
if(GetIsObjectValid(oFam))
DelayCommand(1.0,pet_rest_dam(oFam, oPC));
}

Perhaps you could clarify exactly where you were resting and what you did prior to resting?  How does the food work in the module?
               
               

               


                     Modifié par MagicalMaster, 05 septembre 2013 - 01:56 .
                     
                  


            

Legacy_Rio420

  • Full Member
  • ***
  • Posts: 112
  • Karma: +0/-0
REST_EVENTTYPE_REST_FINISHED
« Reply #10 on: September 05, 2013, 03:03:46 am »


               I did a full rest sequence with 1hp out of 79, after the rest, the character stood up, I took "someone damages you for X amount of damage" total hp gain for the rest was 3hp.  As for the food, as far as I can tell it's simply a means to rest, it doesn't seem like it serves any further purpose, there doesn't "appear" to be a quality difference between a trail ration and a piece of bat jerky. Perhaps, there is something hidden within food that could be the culprit? Maybe if I use a better quality food, I'll end up getting a different result?  I'll test it out.
               
               

               
            

Legacy_Rio420

  • Full Member
  • ***
  • Posts: 112
  • Karma: +0/-0
REST_EVENTTYPE_REST_FINISHED
« Reply #11 on: September 05, 2013, 03:12:30 am »


               lol no difference in using bat jerky, I only gained 1hp after resting.  What the hell? lol.
               
               

               
            

Legacy_MagicalMaster

  • Hero Member
  • *****
  • Posts: 2712
  • Karma: +0/-0
REST_EVENTTYPE_REST_FINISHED
« Reply #12 on: September 05, 2013, 03:23:40 am »


               When you get the "someone damages you" message, do you also get a message about how "Damage immunity absorbed X damage" or something similar?

And what level are you with what classes?

And where are you resting?
               
               

               
            

Legacy_Rio420

  • Full Member
  • ***
  • Posts: 112
  • Karma: +0/-0
REST_EVENTTYPE_REST_FINISHED
« Reply #13 on: September 05, 2013, 03:36:28 am »


               Nope, no damage immunity messages, this is a level 2, resting in a standard newbie zone.  I've tried placing the campfire and resting, using several different meats, nothing has changed the amount of hp he gains outside of an inn or barracks.  Basically, what I "want" it to do, is give at least 25% the hp back, I mean after all, they are wasting food to rest, it should have some sort of benefit.
               
               

               
            

Legacy_Rio420

  • Full Member
  • ***
  • Posts: 112
  • Karma: +0/-0
REST_EVENTTYPE_REST_FINISHED
« Reply #14 on: September 05, 2013, 04:57:13 am »


               To be perfectly honest I'd be just as satisfied with disabling the damage completely, these days, noone wants to sit there waiting on a restrictive rest system, especially on a pw that isn't focused on RP.