Hello,
Me again… I need help with running a reflex save for an NPC when the PC activates an item and the Npc is close enough to the created object. Here’s what I originally had; if ( !ReflexSave(onpc, 16) )&& GetDistanceBetween(onpc,oObject) <2.0) { stuff happens}}. Now the npc would roll his saving throw and the scripted stuff would happen, but it wasn’t at the desired distance.
I’ve checked the script generator too but I can’t pick out the proper function to complete my “if” && statement. I guess I need to declare the distance first? Not sure. Thanks in advance for any advice.
That looks perfectly sound. ::headscratch:: Maybe it’s a problem with the way you’re defining the objects. If you’re accidentally feeding an invalid object into GetDistanceBetween, it’ll always return a distance of 0.0(00000…) feet, which would be less than 2.0 and therefore meet the conditions.
You can paste code in here, by the way. Select it and hit Ctrl+Shift+C
and it’ll stay formatted.
I think @TheBarbarian is right. You said this was a script that created the object you’re checking the distance between? The object might not be valid yet.
If this is the case, use GetDistanceBetweenLocations()
like so:
location lNPC = GetLocation(oNPC);
if (GetDistanceBetweenLocations(lNPC, lLoc) < 2.0 && !ReflexSave(oNPC, 16))
{
// ...
}
… where lLoc is the location you are creating the object.
Note: I moved the distance check first, so that if the NPC is not close enough, no reflex save will fire.
Guys if it matters, it’s on item activation(Module properties) here’s what I actually had;
object oPC=GetItemActivator();
object ohench=GetObjectByTag(“some_dude”);
location lTarget=GetItemActivatedTargetLocation();
object oplaceable=CreateObject(OBJECT_TYPE_PLACEABLE,“placeable”,lTarget,TRUE);
lTarget=(GetLocation(oplaceable));
if ( !ReflexSave(ohench, 100) ) && GetDistanceBetween(ohench,oplaceable)<2.0)
{
FloatingTextStringOnCreature( “Reflex save Failed!”,ohench);
// such awful stuff happens
}
}
question for either, where would the lLoc be called from for(lNpc,lLoc)? is that oplaceable?
https://nwnlexicon.com/index.php/Grimlar_-_Introduction_To_Tag_Based_Scripting
^- If you’re putting code for an activatable item directly into the module’s OnActivateItem event script, you’ll want to see Grimlar’s Introduction to Tag-Based Scripting.
You’ve already got the location - oPlaceable is being spawned at lTarget to begin with. You’ll want to check the distance between GetLocation(ohench) and lTarget. I’d erase the "lTarget=(GetLocation(oplaceable));"
line, to be on the safe side.
Okay here is how the script is actually composed in the module properties, OnItemActivation:
object oUsed=GetItemActivated();
if(GetTag(oUsed) == “tagitem”)
{
object oPC=GetItemActivator();
object ohench=GetObjectByTag(“hench”);
location lTarget=GetItemActivatedTargetLocation();
location lhench= GetLocation(ohench);
AssignCommand( oPC,ActionPlayAnimation(ANIMATION_LOOPING_GET_MID,2.0,2.0));
object oplaceable=CreateObject(OBJECT_TYPE_PLACEABLE,“placeable”,lTarget,TRUE);
lTarget=(GetLocation(oplaceable));
DelayCommand(15.0,
DestroyObject(oplaceable));
effect oeffect= SpecialEffect();
if ( !ReflexSave(oPC, 16) )
{
FloatingTextStringOnCreature( “Reflex save Failed!”,oPC);
DelayCommand(2.0,
ApplyEffectToObject(DURATION_TYPE_TEMPORARY,oeffect,oPC,10.0));
DelayCommand(2.0,
PlayVoiceChat(VOICE_CHAT_PAIN1,oPC));
}
else
{
FloatingTextStringOnCreature( “Reflex save Success!”,oPC);
}
if (GetDistanceBetweenLocations(lhench, lTarget) < 2.0 && !ReflexSave(ohench, 13))
{
FloatingTextStringOnCreature( “Reflex save Failed!”,ohench);
DelayCommand(2.0,
ApplyEffectToObject(DURATION_TYPE_TEMPORARY,oeffect,ohench,10.0));
DelayCommand(2.0,
PlayVoiceChat(VOICE_CHAT_PAIN1,ohench));
}
else
{
FloatingTextStringOnCreature( “Reflex save Success!”,ohench);
}
}
Okay, the reflex save still fires even if ohench is more than 2 meters away. I’ve also tried it with the line lTarget=(GetLocation(oplaceable)); removed, and ohench reflex save fires no matter the distance.
Hold up! the “else” statement for ohench is gonna fire no matter what the distance to lTarget the way this is written and the reflex save didn’t fire only the floating text above ohench. What newbness on my part!
Okay, the script is firing correctly, and using distance to determine when the ohench’s reflex save fires. I was confused with the floating text above o hench which will happen no matter the distance from lTarget. Thanks millions for TheBarbarian and Squattingmonk’s input and thanks as well for the Grimlar link too. One more question: Does the dialog and battle text box not show the roll for the save of the associate?
Hooray for things that work.
Looks like it, yeah. If that’s a big problem, you may need to write up a custom reflex save function. But your success/fail messages should do just fine for letting the player know what happened.