0
Answered

Multiple Spells and Mana

Swainy 4 months ago in Stats updated 4 months ago 2

Here I am again! :)

This might be really simple, but I can't get it to work.

Say I have three spells - Fire, Lightning and Ice

I want to be able to cast a spell, reduce the mana value unique to that spell and not be able to cast if there isn't enough mana. Mana reduction is set up perfectly and so is the health reduction.

What would be the best way to do this so each spell's mana reduction and 'enough mana' isn't conflicting with the other?

I've set up bools for 'can-attack' but every avenue I go down with this will conflict with another and player is able to shoot even when mana is at zero.

Using Stats, Shooter and Inventory.

So far I have:


On Equip Spill (Fireball)

If mana of player is greater or equal to 5

Then Assign bool to can-attack true

Else Assign bool to can-attack fasle

Trigger Shoot (Key Down 'R')

If Compare can-attack with True

Then Character Player Single Shoot

Else Debug.Log: Not enough mana!

Thanks!

Unity version:
2019.2.21f1
Game Creator version:
1.1.8
GOOD, I'M SATISFIED
Satisfaction mark by Swainy 4 months ago
Answered

I would decouple the system a bit more. Each Ammo type can have its own "mana" reduction from the Player's mana pool. You can set this in the "On Shoot" actions from each of the bullet/spell asset.

However, to check for the minimum required mana, you could create a new Local Variable and call it "min-mana". Every time you equip a new ammo asset (not sure how you do it, but if it's from an item, you could you use the "On Equip" actions), you set the minimum required value of mana needed to cast this spell.

Then, all that's left to do is to check whether the attribute "mana" is greater than the local variable "min-mana".

Hope this makes sense :-)

Perfect!! Thank you so much! 

Breakdown of what I did to help others/ check I've done it right:

Player

Add local variable compenent if not already present

Create New Variable Name : 'min-mana'

Type: Number

Value: 0

Ammo/ Spell (Uses Shooter and Stats Module)

'On Shoot' Tab inside the ammo set up inspector window.

Add attribute

Target: Player

Attribute: Mana

Operation: Add

Value Type: Value

Amount: Value, -5

OnEquip Fireball Trigger (Uses Inventory Module)

Add Action: Variable Number

Varibal: Local Variable

Game Object: Player

Variable: Min-mana

Value: 5


Trigger Shoot (Uses Shooter Module)

Add Condition

IF

Attribute Value

Target: Player

Attribute: Mana

Compare: Value is Greater or Equal

Value: Use Local Variable

Game Object: Player

Variable: Min-mana

THEN

Character Player Single Shoot


ELSE

Debug.Message

Not enough Mana


(Or whatever effect you so desire)