Conditional events

Posted by Kazdagi on Sat 07 Apr 2001 03:38 PM — 2 posts, 13,649 views.

#0
Hello Y'all,

Ok, briefly as that I am certain you are all aware of a scenario much like this....

I have a Wizard that likes to keep friends spelled up ...
Say he sees The translucent sphere fades from around (certain number of folks). What I want him to do is to recast on that group member, and I have that part working, but what I need him to do is to first check to make sure he has the mana to safely cast (injury or death if he fails to have enough mana). If I send mana then I get back Mana Points: 87 remaining: 87 the remaining is the important part. Now, suppose my spell, 919, requires 19 mana to safely cast. How do I create this? Like I said, I have the group thing and prep spell and cast on %1 down, I just need to check a condition (mana), if/then or what? Help please...

From Texas,

bye Y'all,
Kazdagi
Australia Forum Administrator #1
This sounds easy enough. There are two ways of doing it. The simple way is if you get regular reports of your mana from your prompt, like this:


<3000hp 3000m 3092mv>
You hear the patter of little feet as the battleground teems with life...


In this case, you make one trigger that fires when it finds the status line. This simply remembers your current mana, by saving it in a variable. Then when you need to use the mana (to cast the spell) you make a script to check the mana level.

To do this method you need two triggers:

1. Remember mana level


Trigger: ^\<(\d+)hp\s+(\d+)m\s+(\d+)mv\>.*$
Regular expression: checked
Label: stats_trigger
Script: OnStats


2. Cast the spell


Trigger: The translucent sphere fades from around (.*)
Regular expression: checked
Label: spell_trigger
Script: OnSpellNeeded


Copy and paste the code below into your script file. This version is written in Jscript. You need to enable scripting, and set the language to Jscript if you haven't already.

If you are using VBscript or Perlscript, just adapt the script to the appropriate language.



// --------------------------------------------
//  Trigger to remember your mana.
//  This will match on something like: <3000hp 3000m 3093mv>
// --------------------------------------------
function OnStats (strTriggerName, strTrigLine, wildcardsVB)
{

wildcards = VBArray(wildcardsVB).toArray();	

iHP = wildcards [0];
iMana = wildcards [1];
iMV = wildcards [2];

world.SetStatus ("HP: " + iHP + ", Mana: " + iMana + ", Move: " + iMV);

world.SetVariable ("Mana", iMana);  // remember mana

}	// end of OnStats 

// --------------------------------------------
//  Trigger to cast the spell
// --------------------------------------------
function OnSpellNeeded (strTriggerName, strTrigLine, wildcardsVB)
{

wildcards = VBArray(wildcardsVB).toArray();	
sTarget = wildcards [0];

iMana = parseInt (world.GetVariable ("Mana"));

if (iMana > 19)
  {
  world.Send ("cast 919 " + sTarget);
  world.SetVariable ("Mana", iMana - 19);  // remember new mana
  }
else
  world.Note ("Not enough mana to cast spell 919 ******");

}	// end of OnSpellNeeded 



The more complicated method is if you don't automatically get your mana every prompt. Then you would need to remember which spell to cast, and on which person, and then ask for your mana.




function OnManaNeeded (strTriggerName, strTrigLine, wildcardsVB)
{

wildcards = VBArray(wildcardsVB).toArray();	
sTarget = wildcards [0];

world.SetVariable ("Target", sTarget);
world.SetVariable ("Spell", 919);
world.Send ("mana");

}	// end of OnManaNeeded 



This version remembers the target (who to cast the spell on), the spell number, and then sends "mana" to the world.

You then need to write another trigger script, similar the OnSpellNeeded above, which matches on the report of how much mana you have, and if you have enough, casts the spell. It would then set "Target" to an empty variable, so you don't keep casting the spell every time you ask for your mana level.

It would look like this, but I haven't tested it:



// --------------------------------------------
//  Trigger to cast the spell if necessary
//  It is triggered when mana is reported, the amount
//  of mana is in the first wildcard.
// --------------------------------------------
function OnSpellNeeded (strTriggerName, strTrigLine, wildcardsVB)
{

wildcards = VBArray(wildcardsVB).toArray();	
iMana = parseInt (wildcards [0]);

sTarget = world.GetVariable ("Target");

if (sTarget == "")
  return;  // no target, no spell


iSpell = world.GetVariable ("Spell");

if (iSpell == 0)
  return;   // no spell, cannot cast it

// work out how much mana we need for different spells
switch (iSpell)
  {
  case 919: iManaNeeded = 19; break;
  case 920: iManaNeeded = 10; break;
  case 921: iManaNeeded = 14; break;
  case 922: iManaNeeded = 3; break;
// and so on
  default: return;  // unknown spell number
  }  // end of switch

if (iMana > iManaNeeded)
  world.Send ("cast " + iSpell + " " + sTarget);
else
  world.Note ("Not enough mana to cast spell " + iSpell);

// empty variables so we don't cast it twice
world.SetVariable ("Target", "");
world.SetVariable ("Spell", 0);

}	// end of OnSpellNeeded