You are here

Is there a script for checking the $PC hitpoints

8 posts / 0 new
Last post
Friar
Friar's picture
Is there a script for checking the $PC hitpoints

I was looking for a script that checks if the player's hitpoints are below a percentage; ie <50%.

perhaps it can check if the player is afflicted by a disease.

I'd want to use it as a conditional in conversation trees. So npcs might be like "oh gross your skin is falling off your bones", "Oh man, thats a nasty wound get that checked out dude!" Of course they won't talk like that in the campaign but as an exmaple.

 

void main()
{

object oPC = GetPCSpeaker();

int nInt;
nInt = GetHitDice(oPC);

SetLocalInt(oPC, "HitPoints", nInt);

if (GetLocalInt(oPC, "Hitpoints")<= .5f)
   {
   }
}
 

  • up
    50%
  • down
    50%
kevL's

here's your basic "check hitpoint percentage" script ... untested but i think its alright

// 'gc_check_hp'
//
// Dialog conditional script that checks if PCSpeaker has greater than the
// specified percentage of his/her hitpoints.
// - ret TRUE if hp are equal or above iPct (see Notes)
// - ret FALSE if not.
//
// Note1: if PCSpeaker has less than 1 hp (not sure how it would be in a
// conversation) then FALSE is always returned.
// Note2: if a value less than 1 is passed in for iPct then TRUE is always
// returned.
//
// - to check for less than percentage, use the NOT qualifier in the conversation editor

int StartingConditional(int iPct)
{
    if (iPct < 1) return TRUE;

    object oPC = GetPCSpeaker();

    int iHp = GetCurrentHitPoints(oPC);
    if (iHp > 0)
    {
        int iMax = GetMaxHitPoints(oPC);
        if (iMax > 0 && IntToFloat(iHp) / IntToFloat(iMax) >= IntToFloat(iPct) * 0.01f)
        {
            return TRUE;
        }
    }
    return FALSE;
}

 

diseases and such are more involved 'cause there are so many "bad effects" to test for -- poison, disease, slow, etc etc etc

  • up
    50%
  • down
    50%
kevL's

oops, think i got the "<=" backwards ...

 

edit: corrected, needs test

  • up
    50%
  • down
    50%
Friar
Friar's picture

How do you come up with these so quickly?

I feel like a caveman banging the keyboard.

  • up
    50%
  • down
    50%
kevL's
  • How do you come up with these so quickly?

years and years of banging my head against the keyboard like a caveman ...

  • up
    50%
  • down
    50%
kamal

kevL took skill focus: nwscript as a feat

  • up
    50%
  • down
    50%
Friar
Friar's picture

lol too funny

Well I tested it and it works great.

Thank you

  • up
    50%
  • down
    50%
kevL's

welcome

@kamal, when i read that i actually thought about trying to implement it ... for about 2 sec.

  • up
    50%
  • down
    50%