The Players Corner Archive

Home > Scripting Discussion > Mana Check Tutorial

Mana Check Tutorial

12:51 AMWith every proffesion in the game having the ability to cast, and with the amount of spells that are used in scripting I thought it might be a good idea to post a lil tutorial on the 'good practise' of putting these spell subroutines into the scripts.
The basic tretise is this: Check mana, and dependant on results either prep and cast the spell, or go to some other sub.

Now, the best way to check mana is using the EXP command. Which will give us a number we can match up to check for mana. A typical EXP readout looks like this:

Level: 24 Experience: 715187
Next level at: 750000 exp. Exp. until next lvl: 34813
Family Fame: 20333012 Character Fame: 16214860
Deeds: 10 Deaths this level: 0
Mana: 48/48 Max

The only bit we are really interested in is this line:

Mana: 48/48 Max

This line makes it very easy to check wether we have enough mana to cast, or if we don't. Why is this you ask? because the line will always look the same, except for the obvious number differences, IE it will always look like:

Mana: {Number}/

We can use this in Match statement fairly easily.

Let me reiterate what I said at the beggining of the post. The format of the match/matchwait statement will be to type EXP, check for enough mana, and go to appropriate script section.

Let's put an Example in here to show how it works. Now how this works is like this... First we have matches to catch what we don't want to find (that we don't have enough mana) and the last match statement catches what we do want to find (that none of the previous matches were met, so you must have enough mana). This may sound confusing to read, but just look at this example.

Match Nomana Mana: 0/
Match Nomana Mana: 1/
Match Nomana Mana: 2/
Match Nomana Mana: 3/
Match Nomana Mana: 4/
Match Nomana Mana: 5/
Match Nomana Mana: -
Match prep406 Mana:
put exp
Matchwait

See how it works? It's easy to figure out how mant of the 'Match Nomana Mana: {number}/' sections to put in. It's Mana used by spell - 1. So 406 only needs you to check upto 5 mana, 120 upto 19 etc etc.

I like to make all Script pretty failsafe and universal, so I'll post a sample spellup script below that could be used to cast a shot of 103.


103:
counter set 103
Match Nomana Mana: 0/
Match Nomana Mana: 1/
Match Nomana Mana: 2/
Match Nomana Mana: -
Match Prep103 Mana:
put exp
Matchwait

Prep103:
put prep 103
match Cast103 your spell is
match Cast103 You already have a spell readied
match Reprep103 Nothing happens
match Reprep103 Wait
MatchWait

Reprep103:
GoTo Prep103

Cast103:
put cast %1
exit

Nomana:
echo *** Out of Mana! You may Wrack now if you wish to ***
Match Return You shudder as your life-force is torn and reshaped!
Match Return You feel at full magical power again.
Match Return mana
Match Return Suddenly, a small bolt of energy arcs between the two of you.
Match Return You feel more refreshed.
matchwait

Return:
goto %c

Now this is pretty failsafe and can be changed to add more spells, or just edited slightly to work for any other spells too.

Note the spellsub names are the name of the spell, ie 103: 120: etc etc, this is because when the sub is reached, i set the %c variable to equal that sub (counter set 103, in the above example) so that if you run out of mana you can wrack/be sent to etc etc and it will go back to the part of the script you left. Very useful for multi spell scripts. Also notice that it isn't just 'cast', but instead cast %1, this is so it can be used on a target as well, EG .103 Insomniac, or if no variable is stated it will self cast it.

Hope this is useful, and sorry if I overexplained too much

-=Insomniac=-


reg