[SOLVED]need help with some variables

0 favourites
  • 12 posts
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • My player sprite has variable called 'defense' and global variable 'hp' for example i set this 'defense' var. to 10.

    Now when oponent has variable 'atk' to 15 and he hit the player, player should be lose 5 hp.

    But when oponent 'atk' is equal to players 'defense', player should be lose 1 hp by one hit

    I cant figure out how make this.

    this is my example sytem

    <img src="https://dl.dropboxusercontent.com/u/44710358/linia3.png" border="0" />

  • Add a check in your event sheet. If damage is less than 1, reduce HP by 1. Else, reduce HP by attack - defense.

  • Here comes psuedo code:

    DEFINE Globals:(

    HP as Numner

    PlayerDefense as Number = 15

    EnemyAttack as Number = 10

    )

    On Colision with a Sprite DO:(

    • IF PlayerDefense = EnemyAttack THEN

    -- HP = HP - 1

    • ELSE IF PlayerDefense > EnemyAttack THEN

    -- Output("Player sustained no damage from the attack!")

    • ELSE

    -- HP = HP - (PlayerDefense - EnemyAttack)

    )

    Something like that I think :P

  • if i set: reduce HP by 'attack - defense'

    i have

    • 15hp(oponent attack) + -10hp(defense player) = -25hp not 5 as we expect
  • reduce variable should be:

    15 - 10 = 5

    And why are you using addition and negative variable values? That might complicate things a bit in mathematics.

  • of course is 5 but is not what i mean, when you set event with CLAMP function: substract from 'hp' 15 -10 you get -25

    <img src="https://dl.dropboxusercontent.com/u/44710358/PALETT.png" border="0" />

  • delgado I think it would be easier if you didn't use Clamp and instead used "HP - (SmallMonster2.attack - DEFENSEPlayer)"

    You should also set a condition for when the Player's Defense is larger than the Monster's attack, otherwise the player will be healed every time it gets hit with an attack that is weaker than the Player Defense. Look at my psuedo code above^^^

  • May I ask, what do you use Clamp for?

  • marlon667 i use this clamp to set minimum and maximum hp.

    Yeah, easiest way is abandon clamp i think

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Yeah, It would be easier to use conditions instead of clamp, one for zero HP and one for max (make a global variable called MAXHP, makes it easier for level ups and stuff).

  • yes yes:) now works fine Thanks for your time

  • Your Welcome :)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)