Author Topic: Cast a Spell From a creatures heartbeat - please help  (Read 370 times)

Legacy_Morbane

  • Jr. Member
  • **
  • Posts: 79
  • Karma: +0/-0
Cast a Spell From a creatures heartbeat - please help
« on: September 20, 2011, 09:50:44 am »


                void main()
{   
object oCaster = OBJECT_SELF;

   object oTarget = GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC, oCaster);

      AssignCommand(oCaster, ActionCastSpellAtObject(SPELL_BLESS, oTarget, METAMAGIC_ANY, TRUE, 20, PROJECTILE_PATH_TYPE_DEFAULT, TRUE));
}

The above code does not work - what am I missing here?
               
               

               


                     Modifié par Morbane, 20 septembre 2011 - 08:51 .
                     
                  


            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Cast a Spell From a creatures heartbeat - please help
« Reply #1 on: September 20, 2011, 09:55:09 am »


               Try this:

void main()
{
object oCaster = OBJECT_SELF;

object oTarget = GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC, oCaster);
if(!GetIsPC(oTarget))
{
SendMessageToPC(GetFirstPC(),"DEBUG: invalid target!");
}
ClearAllActions();
ActionCastSpellAtObject(SPELL_BLESS, oTarget, METAMAGIC_ANY, TRUE, 20, PROJECTILE_PATH_TYPE_DEFAULT, TRUE);
}
               
               

               
            

Legacy_Morbane

  • Jr. Member
  • **
  • Posts: 79
  • Karma: +0/-0
Cast a Spell From a creatures heartbeat - please help
« Reply #2 on: September 20, 2011, 10:11:48 am »


               thanks ShaDoOoW - that got me started.
               
               

               
            

Legacy_Morbane

  • Jr. Member
  • **
  • Posts: 79
  • Karma: +0/-0
Cast a Spell From a creatures heartbeat - please help
« Reply #3 on: September 20, 2011, 11:36:32 am »


               Now with more than one char it always says invalid target - how do I get around that?

I tried this line:
object oTarget = GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC, oCaster, CREATURE_TYPE_IS_ALIVE, CREATURE_ALIVE_TRUE);

But it didn't help.

Edit: also tried this line : if(!GetIsOwnedByPlayer(oTarget))

no go - any more help please?
               
               

               


                     Modifié par Morbane, 20 septembre 2011 - 10:42 .
                     
                  


            

Legacy_Morbane

  • Jr. Member
  • **
  • Posts: 79
  • Karma: +0/-0
Cast a Spell From a creatures heartbeat - please help
« Reply #4 on: September 20, 2011, 11:49:26 am »


               the "invalid target" message comes up after the main pc dies - so it is not recognising companions -is there a way to force the creature to notice companions?
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Cast a Spell From a creatures heartbeat - please help
« Reply #5 on: September 20, 2011, 11:54:01 am »


               Try this:

void main()
{
object oCaster = OBJECT_SELF;

object oTarget = GetNearestCreature(CREATURE_TYPE_REPUTATION, REPUTATION_TYPE_ENEMY, oCaster, 1, CREATURE_TYPE_IS_ALIVE, TRUE);
 if(GetIsObjectValid(oTarget))
 {
ClearAllActions();
ActionCastSpellAtObject(SPELL_BLESS, oTarget, METAMAGIC_ANY, TRUE, 20,  PROJECTILE_PATH_TYPE_DEFAULT, TRUE);
 }
 else
 {
 SendMessageToPC(GetFirstPC(),"DEBUG: invalid target!");//delete this message after you get it working properly
 }
}
[/quote]
               
               

               


                     Modifié par ShaDoOoW, 20 septembre 2011 - 10:54 .
                     
                  


            

Legacy_Morbane

  • Jr. Member
  • **
  • Posts: 79
  • Karma: +0/-0
Cast a Spell From a creatures heartbeat - please help
« Reply #6 on: September 20, 2011, 12:25:30 pm »


               ShaDoOoW - you the one man! This was driving me koo koo... THANKS MUCH '<img'>
               
               

               
            

Legacy__Guile

  • Hero Member
  • *****
  • Posts: 1308
  • Karma: +0/-0
Cast a Spell From a creatures heartbeat - please help
« Reply #7 on: September 20, 2011, 01:05:06 pm »


               The real problem is, this creature will continue to cast this spell every freaking 6 seconds infinitely!

You should use a variable to have them only cast once every 30 seconds or 1 minute.. & Check distance too!
Of course you just don't want the NPC to stand there where they chased the PC down to, they need to return back to where they came from (their first way point).

//REVISED EDITION

//Required Include
#include "x0_i0_walkway"
void main()
{
 object oCaster = OBJECT_SELF;
 int nCast = GetLocalInt(oCaster, "I_BLESSED");
 object oTarget = GetNearestCreature(CREATURE_TYPE_REPUTATION, REPUTATION_TYPE_ENEMY, oCaster, 1, CREATURE_TYPE_IS_ALIVE, TRUE);

if(GetIsObjectValid(oTarget) && nCast != TRUE)
{

    //If the PC isn't close by... stop here.. (more than 15 meters away)
    if(GetDistanceBetween(oTarget, oCaster)>15.0) { return; }
 
  //Prevent Spam
  SetLocalInt(oCaster, "I_BLESSED", TRUE);
  DelayCommand(30.0, SetLocalInt(oCaster, "I_BLESSED", FALSE));

   ClearAllActions();
   ActionCastSpellAtObject(SPELL_BLESS, oTarget, METAMAGIC_ANY, TRUE, 20,
PROJECTILE_PATH_TYPE_DEFAULT, TRUE);

}
else
{
 if(!GetIsInCombat(oCaster) && !IsInConversation(oCaster))
 {
 //Um, since we have cast the spell, now let's return back to our station..
 WalkWayPoints(FALSE, 1.0);
 }
}

//End Main Script
}

//---------------------------

Just so you know for future reference, it would be A LOT better to use a trigger to assing the NPC the command to cast the spell, and of course you would want to set an integer on the Trigger to show that they have case "Bless", so that the NPC doesn't keep blessing every time the PC or anyone in the area enters the trigger.  You can use DelayCommand to set the integer back to FALSE that way the NPC is ready to cast again... (maybe after 10 seconds)

////////////////////////////////////////////////////////
// This Script Goes in the OnEnter Event of a Tracks Trigger

//IMPORTANT: Enter the tagname of the NPC to cast the spell here
string NPC_TAGNAME = "tagname";

////////////////////////////////////////////////////////
//Main Script
void main()
{
 object oCaster = GetNearestObjectByTag(NPC_TAGNAME, OBJECT_SELF);
 object oPC = GetEnteringObject();
 if(GetLocalInt(OBJECT_SELF, "BLESSED")==TRUE || !GetIsPC(oPC))
 { return; }
 else
 {
  SetLocalInt(OBJECT_SELF, "BLESSED", TRUE);
  DelayCommand(10.0, SetLocalInt(OBJECT_SELF, "BLESSED", FALSE));

  AssignCommand(oCaster, ActionCastSpellAtObject(SPELL_BLESS, oPC,
  METAMAGIC_ANY, TRUE, 40, PROJECTILE_PATH_TYPE_DEFAULT));

 }

//Main script end..
}
               
               

               


                     Modifié par _Guile, 20 septembre 2011 - 12:29 .
                     
                  


            

Legacy_Morbane

  • Jr. Member
  • **
  • Posts: 79
  • Karma: +0/-0
Cast a Spell From a creatures heartbeat - please help
« Reply #8 on: September 20, 2011, 02:53:16 pm »


               Guile - I was just using SPELL_BLESS for example - I am actually designing a custom ability that the creature uses every round until it does it 8 times - then it starts casting blasphemy.

Nice scripting though - I'll copy/paste that stuff!
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Cast a Spell From a creatures heartbeat - please help
« Reply #9 on: September 20, 2011, 03:50:12 pm »


               Also, there is a bug in the ActionCastSpell function where whatever you set metamagic and caster level it always remain at no metamagic and caster level of 10.

If you want to workaround this you should download my unofficial patch. That will allow you to override caster level/metamagic of a creature directly by setting a variable on her or via scripting like this:

SetLocalInt(oCaster, "SPECIAL_ABILITY_CASTER_LEVEL_OVERRIDE", 16);//sets caster level at 16
SetLocalInt(oCaster, "METAMAGIC_OVERRIDE", 2);//sets metamagic at extended
               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Cast a Spell From a creatures heartbeat - please help
« Reply #10 on: September 21, 2011, 01:36:45 am »


               

ShaDoOoW wrote...

Also, there is a bug in the ActionCastSpell function where whatever you set metamagic and caster level it always remain at no metamagic and caster level of 10.


Actually "cheat casting" uses 2 * innate level -1 (minimum of 10).  However if the innate level is set outside the 0 to 9 range, the SR check part of the spell resistance won't fire.
               
               

               
            

Legacy_Failed.Bard

  • Hero Member
  • *****
  • Posts: 1409
  • Karma: +0/-0
Cast a Spell From a creatures heartbeat - please help
« Reply #11 on: September 21, 2011, 02:06:12 am »


               It might be a case that the spell casting would work more efficiently in the OnCombatRoundEnd script instead of in OnHeartbeat.  That will still make it fire once a round, but only while in combat.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Cast a Spell From a creatures heartbeat - please help
« Reply #12 on: September 21, 2011, 02:12:56 am »


               You beat me to the punch Failed Bard.   I have just a slightly differant angle.   If is is a combat custom ability.  It would be even better to just make a Speicial AI script for it.  That way you do not even have to modify any of the original event scripts for the creature or search for the target, the AI will pass the combat target to the script for you.
               
               

               
            

Legacy__Guile

  • Hero Member
  • *****
  • Posts: 1308
  • Karma: +0/-0
Cast a Spell From a creatures heartbeat - please help
« Reply #13 on: September 21, 2011, 06:58:27 am »


               TY for the notes on the OnCombatRoundEnd event, that totally escaped my memory when considering AI, I wrote my AI in the OnHeartbeat event, wow, what a huge mistake!  + Rep to both of you. '<img'>
(If I could only give + Reps)
               
               

               


                     Modifié par _Guile, 21 septembre 2011 - 05:58 .