GetRandomObjectByType
From NWN Lexicon
Contents |
[edit] GetRandomObjectByType(int, float)
Get a random nearby object within the specified distance with the specified type.
object GetRandomObjectByType( int nObjType, float fMaxDistance );
[edit] Parameters
nObjType
fMaxDistance
Used to determine the nNth object to look for.
[edit] Description
Get a random nearby object within the specified distance of the specified type.
[edit] Remarks
Returns a valid object on success, OBJECT_INVALID on failure.
This uses DISTANCE_* constants if you want for fMaxDistance.
[edit] Known Bugs
There are some quirks in how fMaxDistance is used to find the requested object. If fMaxDistance is set to DISTANCE_SHORT (3.0), then d6 being sent.
Meaning, if you send in a distance of DISTANCE_TINY (1.0) you could actually end up with an object that is 6.0 distance away.
[edit] Requirements
#include " x0_i0_anims "
[edit] Version
???
[edit] Example
// Find a nearby creature and noogie them. A silly example but fun to watch. #include "x0_i0_anims" void main() { // Find a random creature within 2 meters. object oTarget = GetRandomObjectByType(OBJECT_TYPE_CREATURE, 2.0); // Validate that oTarget was found. if(OBJECT_INVALID != oTarget) { // Check to see if oTarget is not hostile to us and that we have not noogied them already. if(FALSE == GetIsEnemy(OBJECT_SELF, oTarget) && FALSE == GetLocalInt(oTarget, "BEEN_NOOGIED")) { // Move closer to oTarget. AssignCommand(OBJECT_SELF, ActionMoveToObject(oTarget, TRUE, 0.5)); // Sass them! AssignCommand(OBJECT_SELF, SpeakString("*NOOGIES* Ha ha! Gotcha!")); // Now run before they can noogie you back! AssignCommand(OBJECT_SELF, ActionMoveAwayFromObject(oTarget, TRUE, 25.0)); // Set a flag on the player so they only get noogied once. SetLocalInt(oTarget, "BEEN_NOOGIED", TRUE); } } }
[edit] See Also
functions: | |
constants: |
author: Baragg, editor: Mistress