Help needed on cleric script (RESOLVED)

I am trying to make the cleric 1st level spell “Command” and almost have it done except for one command: Run

I have the other three

fall
beg
stop

as commands

but can’t get the “run” command spell script to work. This is what I have so far:

///Command - Run
///sp_run

#include "X0_I0_SPELLS"
#include "x2_inc_spellhook"



void main()
{
    //Declare major variables

    int nDamage;
    effect eVis = EffectVisualEffect(VFX_IMP_FEAR_S);
    effect eFear = EffectFrightened();
    effect eMind = EffectVisualEffect(VFX_DUR_MIND_AFFECTING_FEAR);
    effect eImpact = EffectVisualEffect(VFX_FNF_LOS_NORMAL_20);
    effect eDur = EffectVisualEffect(VFX_DUR_CESSATE_NEGATIVE);
    float fDelay;
    //Link the fear and mind effects
    effect eLink = EffectLinkEffects(eFear, eMind);
    eLink = EffectLinkEffects(eLink, eDur);
    object oTarget = GetSpellTargetObject();
    object oCaster = OBJECT_SELF;
    float fDuration = 12.0; // 2 rounds

    // Check if the target is undead (immune to mind-affecting spells)
    if (GetRacialType(oTarget) == RACIAL_TYPE_UNDEAD)

    // Check if the target is
    if (GetRacialType(oTarget) == RACIAL_TYPE_ANIMAL)

    // Check if the target is
    if (GetRacialType(oTarget) == RACIAL_TYPE_VERMIN)


    // Check if the target is
    if (GetRacialType(oTarget) == RACIAL_TYPE_OOZE)

    // Check if the target is
    if (GetRacialType(oTarget) == RACIAL_TYPE_DRAGON)

    // Check if the target is
    if (GetRacialType(oTarget) == RACIAL_TYPE_BEAST)

    // Check if the target is
    if (GetRacialType(oTarget) == RACIAL_TYPE_ABERRATION)

    {
        return; // No effect on above types
    }

    // Caster says "Run!"
    AssignCommand(oCaster, SpeakString("Run!"));

    // Target says "Ahhhhhh!"
    AssignCommand(oTarget, SpeakString("Ahhhhhh!"));



    if (!X2PreSpellCastCode())
    {
    // If code within the PreSpellCastHook (i.e. UMD) reports FALSE, do not run this spell
        return;
    }


    //Apply Impact
    ApplyEffectAtLocation(DURATION_TYPE_INSTANT, eImpact, GetSpellTargetLocation());
    //Get first target in the spell cone
    oTarget = GetFirstObjectInShape(SHAPE_SPHERE, RADIUS_SIZE_LARGE, GetSpellTargetLocation(), TRUE);
    while(GetIsObjectValid(oTarget))
    {
        if (spellsIsTarget(oTarget, SPELL_TARGET_STANDARDHOSTILE, OBJECT_SELF))
        {
            fDelay = GetRandomDelay();
            //Fire cast spell at event for the specified target
            SignalEvent(oTarget, EventSpellCastAt(OBJECT_SELF, SPELL_FEAR));

                    //Apply the linked effects and the VFX impact
                    DelayCommand(fDelay, ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eLink, oTarget, fDuration));
                }
            }
        }

and the spell description below:

Caster Level(s): Cleric 1, Paladin 3

Innate Level: 3
School: Enchantment
Descriptor(s):
Component(s): Verbal, Somatic
Range: Medium
Area of Effect / Target: Large
Duration: 2 Rounds
Additional Counter Spells:
Save: None
Spell Resistance: No

Description: You speak a single word of command to your target, compelling them to obey. Upon casting, you must choose one of four commands:

  • Beg: The target drops to their knees and is forced to beg for 2 rounds.
    
  • Fall: The target is knocked down for 2 rounds.
    
  • Run: The target is struck with fear and flees for 2 rounds.
    
  • Stop: The target is paralyzed for 2 rounds, unable to move or take actions.
    

Note: This spell only affects living creatures. Undead and creatures immune to mind- affecting spells are unaffected. There is no saving throw.

eVis seems not be used?

This does not work as it probably should. Currently this checks if oTarget is undead and animal and vernim and … which is seldom true ;). Better use a switch statement:

switch (GetRacialType(oTarget))
{
case RACIAL_TYPE_UNDEAD:
case RACIAL_TYPE_ANIMAL:
...
   return;
}

There’s a GetNextObjectInShape(…) missing.

Could you fix this for me please?

Maybe this is what @Kamiryn had in mind? (should probably let Kamiryn handle this, but what the heck, I’ll try out and help too, hopefully I won’t mess things up too much)

(like Kamiryn says, eVis doesn’t seem to be in use so I wonder where that’s supposed to be applied)

//Command - Run
//sp_run

#include "X0_I0_SPELLS"
#include "x2_inc_spellhook"

void main()
{
    //Declare major variables

    int nDamage;
    effect eVis = EffectVisualEffect(VFX_IMP_FEAR_S);
    effect eFear = EffectFrightened();
    effect eMind = EffectVisualEffect(VFX_DUR_MIND_AFFECTING_FEAR);
    effect eImpact = EffectVisualEffect(VFX_FNF_LOS_NORMAL_20);
    effect eDur = EffectVisualEffect(VFX_DUR_CESSATE_NEGATIVE);
    float fDelay;
    //Link the fear and mind effects
    effect eLink = EffectLinkEffects(eFear, eMind);
    eLink = EffectLinkEffects(eLink, eDur);
    object oTarget = GetSpellTargetObject();
    object oCaster = OBJECT_SELF;
    float fDuration = 12.0; // 2 rounds

	switch (GetRacialType(oTarget))
	{
		case RACIAL_TYPE_UNDEAD:
		case RACIAL_TYPE_ANIMAL:
		case RACIAL_TYPE_VERMIN:
		case RACIAL_TYPE_OOZE:
		case RACIAL_TYPE_DRAGON:
		case RACIAL_TYPE_BEAST:
		case RACIAL_TYPE_ABERRATION:
		
		return;	
	}
    // Caster says "Run!"
    AssignCommand(oCaster, SpeakString("Run!"));

    // Target says "Ahhhhhh!"
    AssignCommand(oTarget, SpeakString("Ahhhhhh!"));



    if (!X2PreSpellCastCode())
    {
    // If code within the PreSpellCastHook (i.e. UMD) reports FALSE, do not run this spell
        return;
    }


    //Apply Impact
    ApplyEffectAtLocation(DURATION_TYPE_INSTANT, eImpact, GetSpellTargetLocation());
    //Get first target in the spell cone
    oTarget = GetFirstObjectInShape(SHAPE_SPHERE, RADIUS_SIZE_LARGE, GetSpellTargetLocation(), TRUE);
    while(GetIsObjectValid(oTarget))
    {
        if (spellsIsTarget(oTarget, SPELL_TARGET_STANDARDHOSTILE, OBJECT_SELF))
        {
            fDelay = GetRandomDelay();
            //Fire cast spell at event for the specified target
            SignalEvent(oTarget, EventSpellCastAt(OBJECT_SELF, SPELL_FEAR));

            //Apply the linked effects and the VFX impact
            DelayCommand(fDelay, ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eLink, oTarget, fDuration));
        }
		GetNextObjectInShape(SHAPE_SPHERE, RADIUS_SIZE_LARGE, GetSpellTargetLocation(), TRUE);
	}
	
}

I’m still pretty bad at determining where to put GetNext... functions within scripts when you apply a loop, so that bit may be a bit incorrect, I don’t know.

Hi bud…good to hear from you :slight_smile:

Also, thanks for trying to script this. I tried it and what happens is that the game freezes for a bit then the target still keeps moving toward the PC. So it doesn’t work. :frowning:

But thanks for trying bud

You got the GetNextObjectInShape() in the right place, nice! But you need an “oTarget =” in front so that oTarget changes each loop or you just run until you hit TMI and abort the script, then the game continues. That’s what the OP reported, too.

I tried what you said meaglyn. Script compiled.

in game it stops the target creature (it doesn’t run away as scare would normally do) the animation of the flying skulls spinning around is there but is applied to all the creatures around the target

Yes, that’s what the code as written does. It applies the effects to every hostile object in the sphere around the spell’s target location. I was just fixing andgalf’s loop…

It is only suppose to affect the individual targeted…how do you do that and make the target run away?

This should be on top of your script. No need to create all the effects and let caster/target speak if the spell isn’t really cast (e.g. because of failed UMD checks).

This should came next. Same reason as above.

I don’t know what effect eVis is. Perhaps you want to link it with the other effects? If so add a line

eLink = EffectLinkEffects(eLink, eVis);

after the other EffectLinkEffects lines.

If you want only a single target you shouldn’t apply the effects to all creatures in a shape. Also you could drop the delay. So drop GetFirst/NextObjectInShape and the while statement and just write

SignalEvent(oTarget, EventSpellCastAt(OBJECT_SELF, SPELL_FEAR));
ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eLink, oTarget, fDuration);
1 Like

:man_facepalming: Urrgh! Of course I do. I actually know that, but for some odd reason left it out. Doh! Sorry for the silly mistake.

If I understand @Kamiryn 's notes about this the script should look like this, I think?

//Command - Run
//sp_run

#include "X0_I0_SPELLS"
#include "x2_inc_spellhook"

void main()
{

	if (!X2PreSpellCastCode())
    {
    // If code within the PreSpellCastHook (i.e. UMD) reports FALSE, do not run this spell
        return;
    }

	object oTarget = GetSpellTargetObject();
	
	switch (GetRacialType(oTarget))
	{
		case RACIAL_TYPE_UNDEAD:
		case RACIAL_TYPE_ANIMAL:
		case RACIAL_TYPE_VERMIN:
		case RACIAL_TYPE_OOZE:
		case RACIAL_TYPE_DRAGON:
		case RACIAL_TYPE_BEAST:
		case RACIAL_TYPE_ABERRATION:
		
		return;	
	}
	
   
    effect eVis = EffectVisualEffect(VFX_IMP_FEAR_S);
    effect eFear = EffectFrightened();
    effect eMind = EffectVisualEffect(VFX_DUR_MIND_AFFECTING_FEAR);
    effect eImpact = EffectVisualEffect(VFX_FNF_LOS_NORMAL_20);
    effect eDur = EffectVisualEffect(VFX_DUR_CESSATE_NEGATIVE);
    float fDelay;
    //Link the fear and mind effects
    effect eLink = EffectLinkEffects(eFear, eMind);
    eLink = EffectLinkEffects(eLink, eDur);
	eLink = EffectLinkEffects(eLink, eVis);
    
    object oCaster = OBJECT_SELF;
    float fDuration = 12.0; // 2 rounds

    // Caster says "Run!"
    AssignCommand(oCaster, SpeakString("Run!"));

    // Target says "Ahhhhhh!"
    AssignCommand(oTarget, SpeakString("Ahhhhhh!"));


    //Apply Impact
    ApplyEffectAtLocation(DURATION_TYPE_INSTANT, eImpact, GetSpellTargetLocation());
    //Get first target in the spell cone
   
   	SignalEvent(oTarget, EventSpellCastAt(OBJECT_SELF, SPELL_FEAR));
	ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eLink, oTarget, fDuration);     
     
	
}

EDIT: Edited out the int nDamage; since it wasn’t used.

1 Like

As there is no damage in this spell this could be dropped as well.

1 Like

I’ll edit it out then.

Some remarks:

  1. In the original fear spell script nw_s0_fear the effect eVis is also created but not used as well. No idea why (perhaps it was applied but later removed?).

  2. The spell seems rather powerful (for a level 0 spell). It bypasses any spell resistance (and probably spell protections too?) and it does not allow a saving throw.

  3. Even if the target is immune the line “Ahhhhhh!” is still spoken.

Thanks guy so much for your help :slight_smile:

I will try that script and get back to you.

It is a 1st level cleric spell. “Command”. I just chose 4 commands that the NWN could replicate that slightly differ from the original spell description if you look it up from the Pen-and-paper version. The effect should be only a round in the PnP but I made it two rounds to give it better game mechanics. :slight_smile:

(Spell is almost there )

It complied, it caused the target to have the fear effect of the spinning skulls around it and no other target as before. Only thing to do is to make it do what the fear spell does…make the target run away or in a random direction for 2 rounds.

I think you make in unnecessary complicated. It is enough to make the target fall to the ground without any choice, because that is going to be the most used option anyway.

Hi Shadow, :slight_smile:

The target of the command spell “Run” command doesn’t fall to the ground. It just stands there with skulls floating around its head. I’d like to see the effect of the creature run away (thus “run”).

The other command “Stop” makes the creature just stand there …so it would not be different from that command of run then.