Jump to content

Photo

DisplayFloatyMessage() failure


  • Please log in to reply
1 reply to this topic

#1
DarthGizka

DarthGizka
  • Members
  • 867 posts

It seems that DisplayFloatyMessage() is the only means of displaying text, short of printing to the log and doing tail -f on that from elsewhere.

 

The fact that the floaties don't stick around when the game is paused is irritating enough when playing, but here even more so. With FLOATY_MESSAGE the floaties do stay around for a bit but then the function seems to go into some kind of failure mode and new floaties do not get displayed at all on the creature in question.

 

The duration of the failure state seems to be correlated to the floaty duration. E.g., if you give 20 seconds as duration then the floaty will be visible for a good while but then you won't be able to float anything new for a long time.

 

Also, there seem to be varying limits on how many floaties you can display above a creature. Sometimes you can see only one or two, sometimes up to six. So far I haven't been able to discern any logic behind it at all.

 

By and large I find the floaty method of printing preferrable to the log method, since it allows you to take screen shots for posterity and thus see exactly what the text refers to (since the text is floating above the offending creature's head). With the log method that's not so easy.

 

Does anyone know how to tame the beast?

 

Examples of what I'm doing can be seen in another thread.



#2
DarthGizka

DarthGizka
  • Members
  • 867 posts
Just in case someone wants to play around a bit:
 
// tpv.nss - target property value
// 2014-03-28

#include "2da_constants_h"

// IsMagicUser()
#include "core_h"

// sys_resistances_h
const int PROPERTY_ATTRIBUTE_SPELLRESISTANCE_ = 52;


const int LINE_DELTA_ = 17;


string pad0_ (int value, int width = 2)
{
   string s = IntToString(value);
   int l = GetStringLength(s);

   while (l++ < width)
   {
      s = "0" + s;
   }

   return s;
}


string trim_ (string s)
{
   int l = GetStringLength(s);

   while (StringLeft(s, 1) == " ")
   {
      s = StringRight(s, --l);
   }

   while (StringRight(s, 1) == " ")
   {
      s = StringLeft(s, --l);
   }

   return s;
}


string f2s_ (float v)
{
   if (fabs(v) > 25.0f)
   {
      return IntToString(FloatToInt(v));
   }

   string s = trim_(FloatToString(v, 18, 1));

   if (StringLeft(s, 1) == ".")
   {
      s = "0" + s;
   }

   if (StringRight(s, 2) == ".0")
   {
      s = StringLeft(s, GetStringLength(s) - 2);
   }

   return s == "" ? "0" : s;
}

string prop_text_ (object oTarget, int nPropID)
{
   float fTotVal = GetCreatureProperty(oTarget, nPropID, PROPERTY_VALUE_TOTAL);
   float fCurVal = GetCreatureProperty(oTarget, nPropID, PROPERTY_VALUE_CURRENT);
   string s = f2s_(fTotVal);

   if (fCurVal >= 0.0f)
   {
      s = f2s_(fCurVal) + "/" + s;
   }

   return s;
}


string prop_text_nz_ (object oTarget, int nPropID, string suffix, string prefix = "")
{
   string s = prop_text_(oTarget, nPropID);

   return s == "0" ? "" : prefix + s + suffix + " ";
}


int fudge_colour_ (int n)
{
   int c = 0xFFFFFF;

   if (n & 4)  c = c & 0xFFFF40;
   if (n & 2)  c = c & 0xFF40FF;
   if (n & 1)  c = c & 0x40FFFF;

   return c;
}


int print_line_ (int y, object oAboveWhom, string s)
{
   // "This function doesn't work in the retail version of the game."
   // DEBUG_PrintToScreen(s, y, 10.0f);

   DisplayFloatyMessage(oAboveWhom, s, FLOATY_MESSAGE, fudge_colour_(y), 20.0f);

   return y + LINE_DELTA_;
}


int print_prop_ (int y, object oTarget, string sPrefix, int nPropID, int bWithPropID = 0)
{
   string s = prop_text_(oTarget, nPropID);

   if (nPropID == PROPERTY_DEPLETABLE_HEALTH)
   {
      s = s + " (" + prop_text_(oTarget, PROPERTY_ATTRIBUTE_REGENERATION_HEALTH_COMBAT) + ")"
        + " MP " + prop_text_(oTarget, PROPERTY_DEPLETABLE_MANA_STAMINA)
        + " (" + prop_text_(oTarget, PROPERTY_ATTRIBUTE_REGENERATION_STAMINA_COMBAT) + ")";
   }
/*
   else if (nPropID == PROPERTY_DEPLETABLE_MANA_STAMINA)
   {
      s = s + " (" + prop_text_(oTarget, PROPERTY_ATTRIBUTE_REGENERATION_STAMINA_COMBAT) + ")";
   }
/**/
   else if (nPropID == PROPERTY_ATTRIBUTE_DEFENSE)
   {
      s = s + " (AR " + prop_text_(oTarget, PROPERTY_ATTRIBUTE_ARMOR) + ") "
        + prop_text_nz_(oTarget, PROPERTY_ATTRIBUTE_DISPLACEMENT, "% dodge");
   }
   else if (nPropID == PROPERTY_ATTRIBUTE_ATTACK)
   {
      s = s + " (AP " + prop_text_(oTarget, PROPERTY_ATTRIBUTE_AP) + ") "
        + prop_text_nz_(oTarget, PROPERTY_ATTRIBUTE_DAMAGE_BONUS, " dmg", "+");
   }
   else if (nPropID == PROPERTY_ATTRIBUTE_RESISTANCE_MENTAL)
   {
      s = s + " mental "
        + prop_text_(oTarget, PROPERTY_ATTRIBUTE_RESISTANCE_PHYSICAL) + " phys "
        + prop_text_nz_(oTarget, PROPERTY_ATTRIBUTE_SPELLRESISTANCE_, "% spell");
   }
   else if (nPropID == PROPERTY_ATTRIBUTE_DAMAGE_RESISTANCE_FIRE)
   {
      s = prop_text_nz_(oTarget, PROPERTY_ATTRIBUTE_DAMAGE_RESISTANCE_FIRE, "% fire")
        + prop_text_nz_(oTarget, PROPERTY_ATTRIBUTE_DAMAGE_RESISTANCE_COLD, "% cold")
        + prop_text_nz_(oTarget, PROPERTY_ATTRIBUTE_DAMAGE_RESISTANCE_ELEC, "% shock")
        + prop_text_nz_(oTarget, PROPERTY_ATTRIBUTE_DAMAGE_RESISTANCE_SPIRIT, "% spirit")
        + prop_text_nz_(oTarget, PROPERTY_ATTRIBUTE_DAMAGE_RESISTANCE_NATURE, "% nature");
   }
   else if (nPropID == PROPERTY_ATTRIBUTE_FIRE_DAMAGE_BONUS)
   {
      s = prop_text_nz_(oTarget, PROPERTY_ATTRIBUTE_FIRE_DAMAGE_BONUS, "% fire")
        + prop_text_nz_(oTarget, PROPERTY_ATTRIBUTE_COLD_DAMAGE_BONUS, "% cold")
        + prop_text_nz_(oTarget, PROPERTY_ATTRIBUTE_ELECTRICITY_DAMAGE_BONUS, "% shock")
        + prop_text_nz_(oTarget, PROPERTY_ATTRIBUTE_SPIRIT_DAMAGE_BONUS, "% spirit")
        + prop_text_nz_(oTarget, PROPERTY_ATTRIBUTE_NATURE_DAMAGE_BONUS, "% nature");
   }

   s = (bWithPropID ?  pad0_(nPropID, 2) + " " : "") + sPrefix + " " + s;

   return print_line_(y, oTarget, trim_(s));
}

          
string lxx_ (object o)
{              
   int l = FloatToInt(GetCreatureProperty(o, PROPERTY_SIMPLE_LEVEL));
   int d = l - FloatToInt(GetCreatureProperty(GetHero(), PROPERTY_SIMPLE_LEVEL));
   string s = SubString("ELHN", GetGameDifficulty(), 1) + pad0_(l);
   
   if (d != 0)
   {
      s = s + "(" + (d < 0 ? "" : "+") + IntToString(d) + ")";
   }                                              
   
   return s;
}
            

string id_ (object o)
{
   return GetTag(o);
}

void print_info_ (object o)
{
   int y = 16;

   y = print_prop_(y, o, lxx_(o) + " HP", PROPERTY_DEPLETABLE_HEALTH);
   y = print_prop_(y, o, "def", PROPERTY_ATTRIBUTE_DEFENSE);
   y = print_prop_(y, o, "", PROPERTY_ATTRIBUTE_DAMAGE_RESISTANCE_FIRE);
   y = print_prop_(y, o, "", PROPERTY_ATTRIBUTE_RESISTANCE_MENTAL);

   // Only up to six floaties visible, so we have to choose...

   if (IsMagicUser(o))
   {
      y = print_prop_(y, o, "SP", PROPERTY_ATTRIBUTE_SPELLPOWER);
      y = print_prop_(y, o, "dmg", PROPERTY_ATTRIBUTE_FIRE_DAMAGE_BONUS);
   }

   y = print_prop_(y, o, "att", PROPERTY_ATTRIBUTE_ATTACK);

   print_line_(y, o, id_(o));
}


void print_modifiers_ (object oTarget)
{
   float fSR = Diff_GetSRMod(oTarget);
   float fDR = Diff_GetDRMod(oTarget);
   float fDM = Diff_GetDurationModifier(oTarget);

   string s = "SRMod " + f2s_(fSR) + "% "
            + "DRMod " + f2s_(fDR) + "% "
            + "duration " + f2s_(100.0f * fDM) + "%";

   print_line_(4, oTarget, s);
   print_line_(5, oTarget, lxx_(oTarget) + " " + id_(oTarget));
}


// based on testperc.nss
void show_perceivers_ (object oPerceiver)
{
   object[] oPerceived = GetPerceivedCreatureList(oPerceiver, FALSE);
   int i = GetArraySize(oPerceived);

   while (i--)
   {
      object o = oPerceived[i];

      ApplyEffectVisualEffect(o, o, 20, EFFECT_DURATION_TYPE_TEMPORARY, 10.0f, 0);
      DisplayFloatyMessage(o, id_(o), FLOATY_MESSAGE, -1, 15.0f);
   }
}

void main ()
{
   string s = GetLocalString(GetModule(),"RUNSCRIPT_VAR");
   object o = GetMainControlled();
   object oTarget = GetAttackTarget(o);

   if (!IsObjectValid(oTarget))
   {
      oTarget = o;
   }

   int nPropID = StringToInt(s);

   if (s == "mod")
   {
      print_modifiers_(oTarget);
   }
   else if (s == "who")
   {
      show_perceivers_(o);
   }
   else if (nPropID == 0)
   {
      print_info_(oTarget);
   }
   else
   {
      string s = "prop(" + pad0_(nPropID) + ") == " + prop_text_(oTarget, nPropID);

      print_line_(10, oTarget, s);
   }
}