HeroEngine Forums
Welcome, Guest. Please login or Register for HeroCloud Account.
Pages: [1] 2 3 ... 5

Author Topic: Simple mana system  (Read 15239 times)

LastJudge

  • General Accounts
  • *
  • Posts: 215
    • View Profile
Simple mana system
« on: Jan 21, 12, 05:17:31 PM »

Time for another tutorial :)

I'm only going to make it very simple, you can expand it to fit your needs. I am going to cover adding new attribute to character which will be used to cast spells and also make spells use it, I'm not going to cover adding this new attribute to your status bar (I might do a status bar tutorial later, but I don't think it's needed).

Note: I did not actually test this tutorial. I am using a bit more complex system that is specific to my game. So if something doesn't work as intended, just tell me and I'll try and fix it.

1. Let's add mana to our character
Open DOM Editor: Windows -> DOM Editor
Add new field to the client side. Call it E_manaPoints and make it an integer.



2. Copy it to server.


3. Go to Server DOM, click on your E_manaPoints field and set Destination Field (client) to "E_manaPoints" and set Delta Priority to 1. Also set Change Callback to true (even though it's not changed to that value in the picture).

Note: You should have E_manaPoints instead if TS_powerPoints.


4. Now let's add our field to character. Find E_CommonCharacter in client DOM. Add new field and choose E_manaPoints, click the Save button.



5. Do the same for E_CommonCharacter in server DOM and also check the 'R' checkbox (it indicates that this field is going to be replicated), click the Save button. That's it for clicking, it's time to write some code now.

Note: Yours should be named E_manaPoints


6. Open E_CommonCharacterClassMethods server script. In the InitCommonChatacter() method, we will need to add an initial value for mana. Modify this
Code: [Select]
  me.E_hitPoints = 100
  me.E_isDead = false
to
Code: [Select]
  me.E_hitPoints = 100
  me.E_manaPoints = 100
  me.E_isDead = false

We also need to add a method that will allow us to modify mana upon casting a spell.
Code: [Select]
method AdjustMana(manaDelta as Integer, ability as NodeRef of Class E_Ability)
  me.E_manaPoints = MiscUtils:Min(me.E_manaPoints + manaDelta, me.E_manaPoints) 
.

Find the ApplyDeath method and modify it so character won't have mana when dead. Modify this
Code: [Select]
me.E_isDead = true
me.E_hitPoints = 0
to
Code: [Select]
me.E_isDead = true
me.E_hitPoints = 0
me.E_manaPoints = 0

Find ApplyLife method and modify this
Code: [Select]
me.E_hitPoints = 100to this
Code: [Select]
me.E_hitPoints = 100
me.E_manaPoints = 100

Find E_RegenTimer_tick() method and add a new line like this
Code: [Select]
me.E_manaPoints = MiscUtils:Min(me.E_manaPoints + 10, 100)Note: In case you already did the "combat tutorial" you might want to have different regeneration values for when the character is in combat and different when out of combat.

We're done with this script, so click "Compile" and then "Submit" and close the script.


7. Open server script called E_playerCharacterClassMethods, locate the ProcessXPGain() method and modify this
Code: [Select]
me.E_hitPoints = 100to this
Code: [Select]
me.E_hitPoints = 100
me.E_manaPoints = 100

Compile and Submit the script and close it afterwards.


8. Open server script called E_CharacterCreationSystemClassMethods. Find the HE_CCSCharacterActivated method and modify this
Code: [Select]
char.E_hitPoints = 100to this
Code: [Select]
char.E_hitPoints = 100
char.E_manaPoints = 100

Compile, Submit, Close ...


9. Now we are going to modify the ability scripts so they use mana too. I'm not going to write code for each of those scripts as it's pretty much the same for each of them. Now as abWeaponStrike and abSwipe are kinda basic attacks, we won't modify these (but you can of course, it's up to you).

Open abFireball server script (repeat for abHeal and abRubyFire too)
add function for getting a mana cost
Code: [Select]
shared function GetManaCost() as Integer
  return 50
.
Note: replace 50 with any number you see fit as the cost. Remember we have set 100 as maximum mana, so it would be nice to keep this number lower than that.

Now we need to modify ApplyEffects function to look like this
Code: [Select]
shared function ApplyEffects( owner as NodeRef of Class E_CommonCharacter, target as NodeRef, ability as NodeRef of Class E_Ability )
cost as Integer = GetManaCost()
  if (owner.E_manaPoints >= cost)
    abEffects:ApplyDirectDamage( owner, target, ability, GetMinDamage(), GetMaxDamage() )
    owner.AdjustMana(-cost, ability)
  .
.


10. We should have a working mana system now. Just make sure to add a mana gauge to your status bar or otherwise you won't be able to see how much mana you have.
« Last Edit: Dec 12, 13, 03:25:21 PM by LastJudge »
Logged

runningbird

  • General Accounts
  • *
  • Posts: 37
    • View Profile
    • Runningbird Studios
Re: Simple mana system
« Reply #1 on: Jan 21, 12, 10:53:24 PM »

Great tutorial now I can add Energy and stamina to my players!

Keep up the good work.

Thanks,
Jason
Logged

cloudnine

  • General Accounts
  • *
  • Posts: 80
    • View Profile
    • Youtube
Re: Simple mana system
« Reply #2 on: Jan 22, 12, 01:58:50 PM »

real cool, you make it look easy, nice

I think i got it to work using 2 mana bars
Code: [Select]
shared function ApplyEffects( owner as NodeRef of Class E_CommonCharacter, target as NodeRef, ability as NodeRef of Class E_Ability )
acost as Integer = GetActionCost()
ecost as Integer = GetEnergyCost()
  if (owner.Action >= acost) and  (owner.Energy >=ecost)
  abEffects:ApplyDirectDamage( owner, target, ability, GetMinDamage(), GetMaxDamage() )
  owner.AdjustAction( -acost, ability )
  owner.AdjustEnergy( -ecost, ability )
  .
.
I set the action cost to 50 energy to 10 and can fire 3 fireballs before they dont do any damage
the fx still plays though -
« Last Edit: Jan 22, 12, 03:14:06 PM by cloudnine »
Logged

LastJudge

  • General Accounts
  • *
  • Posts: 215
    • View Profile
Re: Simple mana system
« Reply #3 on: Jan 22, 12, 04:43:50 PM »

Well in my game, players will be kinda able to choose what sort of power to use (there are 4 available, so I made 4 different costs for stuff and so :) ). They are not used all together though, so I don't know how it works out for you.

I wondering what to do next ... either some kind of spellbook so I can drag and drop spells and so or inventory system (which is most probably gonna be very similar).
Logged

runningbird

  • General Accounts
  • *
  • Posts: 37
    • View Profile
    • Runningbird Studios
Re: Simple mana system
« Reply #4 on: Jan 23, 12, 09:10:51 AM »

Either would be a great start... as all of use are looking to do an inventory or probably some kind of spell system and any example would be a great start.

Logged

LastJudge

  • General Accounts
  • *
  • Posts: 215
    • View Profile
Re: Simple mana system
« Reply #5 on: Jan 23, 12, 10:01:01 AM »

Yup, I know many of you want an example of that. Dunno when I'll find some time to do it, cause I have like 3 exams this Wednesday so it would be nice to learn too :D Maybe afterwards or during the weekend I might try :)
Logged

RacerX

  • General Accounts
  • *
  • Posts: 9
    • View Profile
    • Force Strike MMOG
Re: Simple mana system
« Reply #6 on: Jan 24, 12, 12:30:18 PM »

I thank you for this script. I did have one compile error which has had me looking like mad for a solution. this method "AdjustMana" throws a compile error.

method 'AdjustMana' not found.

on this code

shared function ApplyEffects( owner as NodeRef of Class E_CommonCharacter, target as NodeRef, ability as NodeRef of Class E_Ability )
cost as Integer = GetManaCost()
  if (owner.E_manaPoints >= cost)
    abEffects:ApplyDirectDamage( owner, target, ability, GetMinDamage(), GetMaxDamage() )
    owner.AdjustMana(-cost, ability)
  .
.

Any help to solve this problem would be great and thanks for this.
Logged

LastJudge

  • General Accounts
  • *
  • Posts: 215
    • View Profile
Re: Simple mana system
« Reply #7 on: Jan 24, 12, 12:42:49 PM »

The error means to don't have an 'AdjustMana' method. If you happened to overlook it's creation, it's in step 6. If you are sure you created it, check for any spelling mistakes in it's name :)
Logged

RacerX

  • General Accounts
  • *
  • Posts: 9
    • View Profile
    • Force Strike MMOG
Re: Simple mana system
« Reply #8 on: Jan 24, 12, 02:29:12 PM »

The error means to don't have an 'AdjustMana' method. If you happened to overlook it's creation, it's in step 6. If you are sure you created it, check for any spelling mistakes in it's name :)

thanks very much. Awesome script works great!
Logged

LastJudge

  • General Accounts
  • *
  • Posts: 215
    • View Profile
Re: Simple mana system
« Reply #9 on: Jan 24, 12, 03:50:11 PM »

Glad it works :)
Logged

TheAssassin

  • General Accounts
  • *
  • Posts: 2
    • View Profile
Re: Simple mana system
« Reply #10 on: Jan 24, 12, 09:32:41 PM »

hmmm, can I apply this to other source of cost?(probably like mana only color would be different)
examples:

 <AP bar>(red)
<SP bar>(yellow)
<EP bar>(light green)
Logged

LastJudge

  • General Accounts
  • *
  • Posts: 215
    • View Profile
Re: Simple mana system
« Reply #11 on: Jan 25, 12, 12:43:10 AM »

I see no reason why you couldn't. It's just cost, you can apply it to mana, energy, life itself too, fury, rage, stamina, force, or however else you want to name your resource. Also the color doesn't matter too. And you can make your spell use all the costs at once.
Logged

CaSpivey

  • Developers
  • *
  • Posts: 22
  • Programmer
    • View Profile
Re: Simple mana system
« Reply #12 on: Jan 25, 12, 10:15:35 AM »

Im just having an issue getting the UI to register changes with manaPoints, I know its working correctly because if I set the mana cost higher than the base mana the attack does not truly work it plays the animation but no damage is done.

Any suggestions on where to start looking?
Logged

LastJudge

  • General Accounts
  • *
  • Posts: 215
    • View Profile
Re: Simple mana system
« Reply #13 on: Jan 25, 12, 02:48:50 PM »

Have you tried adding some println lines to places where the mana change should be triggered from? If it's not triggered from where is should be (on replication or upon receiving a lightweight event), then just try changing Change Callback to yes for E_manaPoints or however you call your field ;)
Logged

GARDrealms

  • World Owners
  • ****
  • Posts: 18
    • View Profile
Re: Simple mana system
« Reply #14 on: Feb 06, 12, 09:17:04 PM »

During me edits following this tut I got an error compiling so I backed out the edits and now I get errors pointing to the lines below.:

me.name
killer.name
killer.name     me.name

from each line.




  where killer is kindof E_playerCharacter
    msg as String = " You killed " + me.name + "."     <---------------------
    where me is kindof E_nonPlayerCharacter
      // player killed a creature, so give him/her rewards
      xp as Integer = 10 + me.E_level
      killer.E_experiencePoints = killer.E_experiencePoints + xp
      msg = msg + "  You gain " + xp + "xp and "
     
      wealth as Integer = RandomInteger( 12, 22 )
      killer.E_wealth = killer.E_wealth + wealth
      msg = msg + " collect " + wealth + " gold from it!"
    .
   
    // do messaging to the killer
    $CHAT.ChatPlayer( killer, "System", msg )
    add back killer to exclude
  .
 
  // do messaging to target if appropriate
  if me is kindof E_playerCharacter
    $CHAT.ChatPlayer( me, "System", killer.name + " killed you " )      <--------------
    add back me to exclude
  .
 
  // do messaging to everyone else
  $CHAT.ChatExcludeList( exclude, "System", killer.name + " killed " + me.name + "." )         <---------------
« Last Edit: Feb 06, 12, 09:38:44 PM by GARDrealms »
Logged
Pages: [1] 2 3 ... 5