Author Topic: Placeable casting a spell  (Read 895 times)

Legacy_3RavensMore

  • Hero Member
  • *****
  • Posts: 1153
  • Karma: +0/-0
Placeable casting a spell
« on: March 24, 2015, 04:09:32 pm »


               

Trying to set up an automated castle defense system that will fire at anything undead in it's range.  The meat of the problem is that the spell doesn't fire as it is supposed to.


 


Code snippet (in the heartbeat event of the ORB_WARD):


 


    object oCaster = GetObjectByTag("ORB_WARD");    


    object oTarget = GetNearestCreature(CREATURE_TYPE_RACIAL_TYPE, RACIAL_TYPE_UNDEAD);


    float fDist = GetDistanceBetween(oCaster, oTarget);    


    if (fDist < 12.0)


         AssignCommand(oCaster, ActionCastSpellAtObject(SPELL_RAY_OF_FROST, oTarget, METAMAGIC_ANY, TRUE, 0, PROJECTILE_PATH_TYPE_DEFAULT));


 


I've verified that the GetNearestCreature line is acquiring a valid target, and it's in range.  I hear the audible ray of frost sound, but I get no visual beam effect, and the target (a zombie in this instance) is never damaged.  At this point the oCaster is an invisible placeable suspended 3m off the floor.  My brain is more than a little fried today, so any help would be appreciated. 

 


Edit: There is an impact visual from the ray of frost, but no beam, and no damage.  My PC can cast the ray of frost spell with the appropriate visual and damage.



               
               

               
            

Legacy_3RavensMore

  • Hero Member
  • *****
  • Posts: 1153
  • Karma: +0/-0
Placeable casting a spell
« Reply #1 on: March 24, 2015, 05:03:32 pm »


               

Partly solved.  Placeable can't be static.  Now I have the beam visual, but still no damage to creature.



               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Placeable casting a spell
« Reply #2 on: March 24, 2015, 05:10:24 pm »


               

Perhaps a problem with the action queue stumbling on itself.  Try ClearAllActions(TRUE); at the beginning of the script, and use OBJECT_SELF for oCaster instead of GetObjectByTag().



               
               

               
            

Legacy_3RavensMore

  • Hero Member
  • *****
  • Posts: 1153
  • Karma: +0/-0
Placeable casting a spell
« Reply #3 on: March 24, 2015, 05:19:35 pm »


               

Solved!  Placeables usually have a faction of hostile, and a hostile placeable won't damage a hostile creature even though it will display the full spell visual.  Set the plc faction to defender and everything works.  



               
               

               
            

Legacy_LostChangeling

  • Newbie
  • *
  • Posts: 49
  • Karma: +0/-0
Placeable casting a spell
« Reply #4 on: March 24, 2015, 05:34:25 pm »


               

I'm actually trying to set up something like a statue or orb that casts some beneficial spells on the player, say Death Ward, when s/he talks to it. The conversation bit is no problem for me; it's the spellcasting bit where I'm lost. Looks like this thread could provide some useful tips!



               
               

               
            

Legacy_Kato -

  • Hero Member
  • *****
  • Posts: 747
  • Karma: +0/-0
Placeable casting a spell
« Reply #5 on: March 25, 2015, 04:54:47 pm »


               


I'm actually trying to set up something like a statue or orb that casts some beneficial spells on the player, say Death Ward, when s/he talks to it. The conversation bit is no problem for me; it's the spellcasting bit where I'm lost. Looks like this thread could provide some useful tips!




 


Assuming you're using a standard convo and the code takes place in an "Actions Taken" script, it might look like this, modify duration to your taste.


 


object oPC = GetPCSpeaker();

effect eLink = EffectLinkEffects(EffectImmunity(IMMUNITY_TYPE_DEATH), EffectVisualEffect(VFX_DUR_CESSATE_POSITIVE));

ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_DEATH_WARD), oPC);

ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eLink, oPC, HoursToSeconds(1)); // use either hours, turns or rounds

 

 

 

Kato


               
               

               
            

Legacy_3RavensMore

  • Hero Member
  • *****
  • Posts: 1153
  • Karma: +0/-0
Placeable casting a spell
« Reply #6 on: March 25, 2015, 08:52:33 pm »


               

Hmmm.   I'd never come across the EffectLinkEffects function before.  You learn something new everyday. 



               
               

               
            

Legacy_Kato -

  • Hero Member
  • *****
  • Posts: 747
  • Karma: +0/-0
Placeable casting a spell
« Reply #7 on: March 25, 2015, 09:26:49 pm »


               


Hmmm.   I'd never come across the EffectLinkEffects function before.  You learn something new everyday. 




 


Just FYI, the vanilla(or CPP) spell scripts are instructive when dealing with effects. You can quickly find the corresponding script by searching for the spell on the wiki, or simply google "nwn <spell name>"(without the quotes and symbols), which will bring the related wiki page link.


 


 


Kato



               
               

               
            

Legacy_LostChangeling

  • Newbie
  • *
  • Posts: 49
  • Karma: +0/-0
Placeable casting a spell
« Reply #8 on: March 26, 2015, 03:08:35 am »


               

Thanks again, Kato. Can't wait to try out the script you supplied!


 


I actually tried searching for the scripts for some of the spells, but all I could find were the names of the scripts. For the Bull's Strength spell, for example, I could only find the script name: NW_S0_BullStr.


 


Would be great if there were a comprehensive list of the visual and spell effects which can be legitimately employed by the ApplyEffectToObject function. Is there such a list anywhere?  '<img'>



               
               

               
            

Legacy_Kato -

  • Hero Member
  • *****
  • Posts: 747
  • Karma: +0/-0
Placeable casting a spell
« Reply #9 on: March 26, 2015, 03:25:49 am »


               

Sure, the effects are represented by constants, listed in the Lexicon 1.69(and the script editor, under the constants tab), along with pictures(very handy) showing what the effects look like. The effect "constructors" are also listed in the Lexicon, along with the specific constants to use with each one.  


 


 


Kato 



               
               

               
            

Legacy_LostChangeling

  • Newbie
  • *
  • Posts: 49
  • Karma: +0/-0
Placeable casting a spell
« Reply #10 on: March 26, 2015, 04:24:50 pm »


               

Wow, the lexicon was really helpful!


 


Your script worked beautifully, by the way. Tried some other effects; they worked great as well. Thanks ever so much!  '<img'>



               
               

               
            

Legacy_LostChangeling

  • Newbie
  • *
  • Posts: 49
  • Karma: +0/-0
Placeable casting a spell
« Reply #11 on: April 01, 2015, 06:37:43 pm »


               

Just to know: is there some way my placeable could be made to cast beneficial spell effects not on my PC alone, but also on any henchmen following him/her? (Talk about being greedy...)


 


(I also wonder if the regenerating effect can be safely applied on an undead creature, by the way, or if it will actually cause the creature's hit points to decrease to zero and kill him/her. 'cos I understand normal wound-healing spells will actually hurt an undead creature while negative energy attacks will heal him/her, and I've set up an undead henchman for my PC...  '<img'> )



               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Placeable casting a spell
« Reply #12 on: April 01, 2015, 07:14:34 pm »


               


 


(I also wonder if the regenerating effect can be safely applied on an undead creature, by the way, or if it will actually cause the creature's hit points to decrease to zero and kill him/her. 'cos I understand normal wound-healing spells will actually hurt an undead creature while negative energy attacks will heal him/her, and I've set up an undead henchman for my PC...  '<img'> )




 


Regenerating increases the undead hit points, and attacking an undead with a weapon with negative energy damage reduces the undead hit points.  What is done with spells (heal, harm, etc.)  is that a check is made for the race, and one path is followed if the creature is undead and another if the creature is living, but there is no hard-coded behavior to evaluate race.


               
               

               
            

Legacy_Kato -

  • Hero Member
  • *****
  • Posts: 747
  • Karma: +0/-0
Placeable casting a spell
« Reply #13 on: April 02, 2015, 08:31:00 pm »


               


...is there some way my placeable could be made to cast beneficial spell effects not on my PC alone, but also on any henchmen following him/her?




Using the code example I posted previously, it might look like this, yet there are probably other ways to do it:


 



void main()

{

   object oPC = GetPCSpeaker();   

   effect eLink = EffectLinkEffects(EffectImmunity(IMMUNITY_TYPE_DEATH), EffectVisualEffect(VFX_DUR_CESSATE_POSITIVE));

   ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_DEATH_WARD), oPC);

   ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eLink, oPC, HoursToSeconds(1));

 

   object oMember = GetFirstFactionMember(oPC, FALSE);

   while(oMember != OBJECT_INVALID)

   {

      if(GetAssociateType(oMember) == ASSOCIATE_TYPE_HENCHMAN)

      {

         ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_DEATH_WARD), oMember);

         ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eLink, oMember, HoursToSeconds(1));

      }

      oMember = GetNextFactionMember(oPC, FALSE);

   }

}

 

 

Kato


               
               

               
            

Legacy_LostChangeling

  • Newbie
  • *
  • Posts: 49
  • Karma: +0/-0
Placeable casting a spell
« Reply #14 on: April 03, 2015, 05:27:06 pm »


               

Will have to try this out sometime. Thanks!  '<img'>