Aller au contenu

Photo

Cast a Spell From a creatures heartbeat - please help


  • Veuillez vous connecter pour répondre
13 réponses à ce sujet

#1
Morbane

Morbane
  • Members
  • 1 883 messages
 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 .


#2
Shadooow

Shadooow
  • Members
  • 4 471 messages
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);
}

#3
Morbane

Morbane
  • Members
  • 1 883 messages
thanks ShaDoOoW - that got me started.

#4
Morbane

Morbane
  • Members
  • 1 883 messages
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 .


#5
Morbane

Morbane
  • Members
  • 1 883 messages
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?

#6
Shadooow

Shadooow
  • Members
  • 4 471 messages
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 .


#7
Morbane

Morbane
  • Members
  • 1 883 messages
ShaDoOoW - you the one man! This was driving me koo koo... THANKS MUCH :)

#8
_Guile

_Guile
  • Members
  • 685 messages
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 .


#9
Morbane

Morbane
  • Members
  • 1 883 messages
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!

#10
Shadooow

Shadooow
  • Members
  • 4 471 messages
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

#11
WhiZard

WhiZard
  • Members
  • 1 204 messages

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.

#12
Failed.Bard

Failed.Bard
  • Members
  • 774 messages
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.

#13
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages
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.

#14
_Guile

_Guile
  • Members
  • 685 messages
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. :D
(If I could only give + Reps)

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