![]() |
![]() |
|||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
Defining An Object Intended Audience: [Printer Friendly / Syntax Highlight] Now, this topic is a little more complicated... but I've found myself running into this wall more than once when trying to do something. Most actions require an object as the target. The easiest way to define an object is to have its particular tag handy... which is great if you know what the target object is going to be. But what if you don't? What if you want to find the nearest PC character... whoever it might be? What if you want to target the nearest creature? What if you want to check how far away something is? There are lots of different way of checking for things like this... I'm going to focus on three, here: GetNearestCreature, GetNearestObject and GetDistanceBetween. GetNearestCreature The grammar is as follows: object GetNearestCreature (int nFirstCreatureType, int nFirstParameter, object oTarget=OBJECT_SELF, int nNth=1, int nSecondCreatureType = -1, int nSecondParameter = -1, int nThirdCreatureType = -1, int nThirdParameter = -1 ) This may look a bit confusing, but let's go through it step by step. The 'nFirstCreatureType' and 'nFirstParameter' are the required initial quality that you are looking for. Say you were looking only for the nearest human... the 'nFirstCreatureType' would be the attribute CREATURE_TYPE_ RACIAL_TYPE, and the 'nFirstParameter' would be RACIAL_TYPE_HUMAN. Make sense? You have up to three qualities that you can narrow your search by... each requiring both the attribute and the parameter. The 'oTarget' object is, of course, what the creature you're looking for is near to. It might be OBJECT_SELF (and that's the default) if you're looking for the nearness to the one running the script. You could also do something funky like check for the nearest creature to the nearest PC... but I don't even want to type that out. The integer 'nNth' is what you use to determine whether you want the first-nearest or otherwise. The default is the first nearest... but any number you specify here will determine how many nearer creatures of the parameter you specify are skipped. Note that any function can be used here so long as it returns an integer... you could put d4() here, for instance, if you randomly wanted the first- to fourth-nearest. Here, then, are the list of creature types you can sort by:
I won't go through all the particular classes, races and effects that can be used as parameters since they are pretty obvious. Some of the others are not so obvious, however. CREATURE_TYPE_IS_ALIVE:
CREATURE_TYPE_PERCEPTION:
CREATURE_TYPE_PLAYER_CHAR:
CREATURE_TYPE_REPUTATION:
------------ So, then... how do we find the nearest PC character to myself? GetNearestCreature (CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC); The nearest enemy wizard to myself? GetNearestCreature (CREATURE_TYPE_ REPUTATION, REPUTATION_ENEMY, OBJECT_SELF, 1, CREATURE_TYPE_CLASS, CLASS_TYPE_WIZARD); The nearest living enemy to my nearest PC ally? GetNearestCreature (CREATURE_TYPE_ REPUTATION, REPUTATION_ENEMY, GetNearestCreature (CREATURE_TYPE_ PLAYER_CHAR, PLAYER_CHAR_IS_PC, OBJECT_SELF, 1, CREATURE_TYPE_ REPUTATION, REPUTATION_FRIENDLY), 1, CREATURE_TYPE_ IS_ALIVE, TRUE); The nearest non-PC that I can see? GetNearestCreature (CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_NOT_PC, OBJECT_SELF, 1, CREATURE_TYPE_ PERCEPTION, PERCEPTION_TYPE_ SEEN); GetNearestObject object GetNearestObject (int nObjectType=OBJECT_TYPE_ALL, object oTarget=OBJECT_SELF, int nNth=1) The 'nObjectType' is, obviously, the kind of object you're looking for. If you don't specify anything, than it will be the nearest object of any kind. Again, the 'oTarget' object is what your checking the nearest object in relation to... default is OBJECT_SELF, though it doesn't have to be. 'nNth' is the integer that allows you to go beyond the 'nearest'... an nNth of 3 would look for the 'third nearest', for example. The object types, then, are:
-------------------- float GetDistanceBetween(object oObjectA, object oObjectB) (what's a float, incidentally? A float, like an integer, is just a number... but a float always has decimal places. '50' would be an integer... '50.0' would be a float. If you need to, you can use the command int FloatToInt(float fFloat) to convert a float to an integer.) If you're simply checking how far something is away from the creature or object that is running the script, it is actually easier to use this command: float GetDistanceToObject(object oObject) That way you don't have to constantly specify OBJECT_SELF in the GetDistanceBetween command.
|
|||||||||||||||||||||||