[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to "verify" your details, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.
[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Conditional events

Conditional events

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Kazdagi   (2 posts)  [Biography] bio
Date Sat 07 Apr 2001 03:38 PM (UTC)
Message
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
[Go to top] top

Posted by Nick Gammon   Australia  (23,043 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Sun 08 Apr 2001 12:45 AM (UTC)
Message
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 



- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


10,589 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]