Difference between revisions of "GetRandomObjectByType"

From NWN Lexicon
Jump to: navigation, search
(uvaooamy)
 
Line 36: Line 36:
 
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  | d6 ]] being sent.<br /><br /> 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.
 
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  | d6 ]] being sent.<br /><br /> 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.
  
wh0cd749909 <a href=http://genericlipitor365.us.com/>generic lipitor</a> <a href=http://tadalafil247.us.com/>buy tadalafil cialis</a>
+
====Requirements====
  
wh0cd76252 <a href=http://motrin247.us.com/>purchase motrin</a> <a href=http://propranolol247.us.com/>order propranolol</a>
+
<nowiki>#include "</nowiki>[[ x0_i0_anims | x0_i0_anims ]]"
  
wh0cd443627 <a href=http://genericadvair.us.org/>Generic Advair</a>
+
<br />
  
wh0cd472239 <a href=http://rogaine365.us.com/>rogaine over the counter</a> <a href=http://clomidonline.us.org/>clomid online</a>
+
====Version====
 +
 
 +
???
 +
 
 +
====Example====
 +
 
 +
<nwscript>
 +
 
 +
// 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) &amp;&amp; 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);
 +
        }
 +
    }
 +
}
 +
</nwscript>
 +
 
 +
====See Also====
 +
 
 +
{| class="seealso"
 +
| width="1" align="right" valign="top" | <font color="gray">functions: </font>
 +
|
 +
[[  GetRandomObjectByTag  | GetRandomObjectByTag ]]
 +
|-
 +
| width="1" align="right" valign="top" | <font color="gray">constants: </font>
 +
|
 +
[[ object_type | OBJECT_TYPE_* ]]
 +
|-
 +
|}
 +
 
 +
<br />
 +
----
 +
<font color="gray">author: Baragg, editor: Mistress</font>
 +
[[Category:Functions]]
 +
[[Category:Get_Data_from_Object_Functions]]

Latest revision as of 03:02, 25 December 2017

GetRandomObjectByType(int, float)

Get a random nearby object within the specified distance with the specified type.

object GetRandomObjectByType(
    int nObjType,
    float fMaxDistance
);

Parameters

nObjType

OBJECT_TYPE_*

fMaxDistance

Used to determine the nNth object to look for.


Description

Get a random nearby object within the specified distance of the specified type.



Remarks

Returns a valid object on success, OBJECT_INVALID on failure.

This uses DISTANCE_* constants if you want for fMaxDistance.

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.

Requirements

#include " x0_i0_anims "


Version

???

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) &amp;&amp; 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);
        }
    }
}

See Also

functions: 

GetRandomObjectByTag

constants: 

OBJECT_TYPE_*



author: Baragg, editor: Mistress