Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Dark Dreams of Furiae - a new module for NWN:EE! Buy now
Attention, new and old users! Please read the new rules of conduct for the forums, and we hope you enjoy your stay!

how do you make it so an NPC will cast defensively?

sarevok57sarevok57 Member Posts: 5,267
*sigh* oh man is this toolset really starting to annoy me with its shenanigans

even with the script generator and with NWN lexicon for the life of me i can't wrap my head around why this defensive casting mode script won't compile

i go to lexicon and all it says is

int GetDefensiveCastingMode(
object oCreature

and then some oCreature jargon and what not

and then you can have it active or disabled, and thats it, no example on WHAT TO ACTUALLY TYPE in the script, so trying to do some detective work i tried;

int GetDefensiveCastingMode(object DEFENSIVE_CASTING_MODE_ACTIVATED );

that failed

int GetDefensiveCastingMode(object, DEFENSIVE_CASTING_MODE_ACTIVATED );

that failed

(which i swear was going to be a winner.... )
and that failed

int GetDefensiveCastingMode(object, oCreature DEFENSIVE_CASTING_MODE_ACTIVATED );

that failed


that failed

so it would be nice for someone who actually knows what the command is to type it out for me, because apparently i am not one of the chosen ones who actually understand this whacky alien language regardless on how much i try


  • WilliamDracoWilliamDraco Member Posts: 97
    It seems you have a misunderstanding of what the lexicon is trying to tell you. I'll step through it piece by piece for your understanding, but also you used the wrong function, so at the end I'll point you to the correct one.

    int GetDefensiveCastingMode(object oCreature);

    This is the function declaration. It tells you the three components of the function so that you could use it yourself. I'll go through then out-of-order below.

    1. GetDefensiveCastingMode
    This is the name of the function. Very straightforward, if you want to ask, this is what you type - Note capitals matter. Good function names also hint at what it will do, in this case it's going to Get whether something is in Defensive Casting mode.

    2. (object oCreature)
    The Parameters, this tells you that the function expects to receive some 'thing' to work with. In particular, it's looking for a 'thing' which is an object. When it receives that object, it's going to name it oCreature. For using the function, this name doesn't really matter (only if you were writing the function yourself) but it again hints that the type of object it expects to receive is a Creature object, and it might not work correctly for any other type of object (like an item, which obviously can't be defensive casting).

    3. int
    This is the 'return type' for the function. When a function is run it either does something, returns something, or both. In this case, it returns an int (integer). Reading more of the lexicon article on the function, it explains that there are two possible return values. The article lists these as DEFENSIVE_CASTING_MODE_ACTIVATED and DEFENSIVE_CASTING_MODE_DISABLED. In the 'See Also' section you can see that these are defined as Constants with the integer values of 1 and 0 respectively

    Therefore in order to actually use the above fucntion you'd need to do something like:
    int IsDefenceCasting = GetDefensiveCastingMode(OBJECT_SELF);
      Do something here
    Note that OBJECT_SELF refers to "this thing running the script", so this only works if the script-runner is the creature itself, maybe as part of an "OnDamaged" event

    Like I said at the start though - It looks like the wrong function for what you want. That function only retrieves whether a creature is currently in defensive casting, where-as you asked for how to make it do defensive casting. Defensive casting is an Action Mode, so what you're really looking for is SetActionMode.
    void SetActionMode(object oCreature, int nMode, int nStatus);

    This function is a 'void', which means it doesn't return anything and therefore must be a function which 'does something'. The parameters expect an object (the creature) and two integers to represent the Mode and the Status for that mode. A little bit more reading of the lexicon suggests the appropriate function to be:

    Now, the appropriate place to insert that function is another matter. Perhaps during the "OnSpawn" script of the creature? This depends on more specifics than you've provided.

    I hope that helps. Always hard to judge someones skill-level from one post, so apologies if I've aimed too high or too low. Feel free to shoot me a PM for more help if you need it.

  • TarotRedhandTarotRedhand Member Posts: 960
    I hesitated to make this post in case it just seemed like self-promotion but then said to myself to hell with that. From this (especially) and other posts you have made asking how to do certain things with scripting my guess is that you have not done any scripting or computer programming before. If that is the case I urge you to read this (well received) primer that I wrote for people with zero experience of programming at all. I maintain that anyone can learn this skill but they just have to be willing to learn and not be put off by "jargon".


Sign In or Register to comment.