Jump to content

Calculating character health


traeumer

Recommended Posts

I'm using the urwigo builder to create my first module based on my Nebit the Gnome fantasy game. I have created a basic game, but I don't know how to reduce a character's health after an unsuccessful battle. I also want player character's to be able to be healed by gone to a healing zone. Any advice would be great. Thanks for your help ahead of time!

Link to comment

After the enemy attacks and you do the damage calculation, use an if/else statement. If the character's health is above zero, change the fight command input's text to reflect the character's remaining HP and then show a message box with a message like "The enemy performed the attack 'Firefall' for 294 HP damage. You have 410 HP left." with a callback to the input that asks for the character's attack, else deactivate the fight zone, activate the healing zone, set the character's HP to zero (to avoid showing negative health), and show a message stating the character needs to heal. Likewise, when you do the character's attack's damage calculation, if the enemy's HP is above zero, show a message like "You performed the attack 'Bleeding Point' for a critical hit of 425 HP. The enemy has 529 HP remaining." with a callback to a function that decides the enemy's action, else hide the enemy character if shown, perform whatever EXP assignment is necessary, and show the message "You defeated the enemy!"

 

Note: The attack names are from a large story/game world I created around fifteen years ago, called "The Phoenix Cycle", separated into three books: "Phoenix's Rising", "Phoenix's Flourish", and "Phoenix's Fall".

Link to comment

Thanks for your help. I'm using the if/else commands, but something isn't working properly because a character gets the new story arc zone activated - even if the battle is lost - when in fact they should continue fighting until they either win or lose enough hit points to go to the healing zone. I've attached several screenshots of my program. Screenshots 2 & 3 are functions. Perhaps you can see the error?

post-105643-063711500 1417363015_thumb.jpg

post-105643-057079600 1417363023_thumb.jpg

post-105643-063927700 1417363037_thumb.jpg

Link to comment

Wondering why the admins are not able to solve the problem with the attached pics. :angry:

What to do now, decreasing health if the player lose the combat until an assigned value is reached (i.g 5) then close the combat zone and activate the healing zone ? If the player won what to do then ?

Link to comment

And after I wrote my previous post, the thumbnails showed up. I wonder what's going on. Anyway...

 

If the character starts at six health, losing health once will cause the story arc to proceed. And if the character starts at five health, the arc will proceed without combat. If the character starts at four health, the character will fight once and then nothing will happen if the character is injured. Deciding what to do based on "health equals x" isn't a good idea. You could say, "If health is greater than one, combat; else do the healing zone."

 

In your screen shots, I do not see what click first triggers the function, nor do I see what keeps it going. At most, it seems the combat function will be called twice, depending upon the character's health.

 

Here's what I'm thinking. While most of this is valid code, I'm not sure about making the callback in the way I defined it. You can replace it with a message box callback function, anyway. I was trying to make the functions dealing with combat generic enough that you could use them for multiple combat scenarios.

local playerHealth = 5
local zoneToActivateWhenCombatWon = nil
local zoneCurrentCombatZone = nil

function zoneCombat:OnProximity()
   --Because I activate the combat zone again if battle was unsuccessful.
   if playerHealth > 1 then
     zoneCombat.Active = false  --So OnProximity is not called due to coordinate jitter
     zoneCurrentCombatZone = zoneCombat
     zoneToActivateWhenCombatWon = zoneNextTown
     CombatTurn()
   end
end

function CombatTurn()
   local rand = math.random(1,100)
   if rand > 80 then
       CombatWon()
   else
       AssignDamage()
       if playerHealth > 1 then
          Wherigo.MessageBox{Text=[[You took damage, but you can try again!]], Callback=CombatTurn}
       else
          Wherigo.MessageBox{Text=[[You fled battle because you almost died.  Go and heal, then try again.]],}
          zoneHealingSpring.Active = true
          zoneCurrentCombatZone.Active = true
       end
   end
end

function AssignDamage()
   playerHealth = playerHealth - 1
end

function CombatWon()
   Wherigo.MessageBox{Text=[[You defeated the enemy!]],}
   zoneToActivateWhenCombatWon.Active = true
end

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...