[SOLVED]need help with some variables

Get help using Construct 2

Post » Sun May 12, 2013 1:18 pm

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


delgado2013-05-12 21:04:07
B
93
S
19
G
34
Posts: 1,840
Reputation: 27,963

Post » Sun May 12, 2013 1:23 pm

Add a check in your event sheet. If damage is less than 1, reduce HP by 1. Else, reduce HP by attack - defense.
I got a game that you multiply, breath fire with two heads and brawl foes to oblivion with your clones: http://www.newgrounds.com/portal/view/660664 (use Chrome on Windows for best performance)

My sites:
http://twinblazar.deviantart.com
http://twinblazar.newgrounds.com
https://twitter.com/twinblazar
http://www.pixiv.net/member.php?id=15072448
B
23
S
9
G
11
Posts: 408
Reputation: 8,015

Post » Sun May 12, 2013 1:27 pm

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
B
10
S
2
Posts: 94
Reputation: 1,536

Post » Sun May 12, 2013 1:53 pm

@keroberos if i set: reduce HP by 'attack - defense'

i have
- 15hp(oponent attack) + -10hp(defense player) = -25hp not 5 as we expect

delgado2013-05-12 14:34:03
B
93
S
19
G
34
Posts: 1,840
Reputation: 27,963

Post » Sun May 12, 2013 2:19 pm

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.
I got a game that you multiply, breath fire with two heads and brawl foes to oblivion with your clones: http://www.newgrounds.com/portal/view/660664 (use Chrome on Windows for best performance)

My sites:
http://twinblazar.deviantart.com
http://twinblazar.newgrounds.com
https://twitter.com/twinblazar
http://www.pixiv.net/member.php?id=15072448
B
23
S
9
G
11
Posts: 408
Reputation: 8,015

Post » Sun May 12, 2013 2:32 pm

@keroberos 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

delgado2013-05-12 14:38:16
B
93
S
19
G
34
Posts: 1,840
Reputation: 27,963

Post » Sun May 12, 2013 3:53 pm

@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^^^
B
10
S
2
Posts: 94
Reputation: 1,536

Post » Sun May 12, 2013 3:54 pm

May I ask, what do you use Clamp for?
B
10
S
2
Posts: 94
Reputation: 1,536

Post » Sun May 12, 2013 4:07 pm

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

Yeah, easiest way is abandon clamp i think
B
93
S
19
G
34
Posts: 1,840
Reputation: 27,963

Post » Sun May 12, 2013 4:16 pm

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).
B
10
S
2
Posts: 94
Reputation: 1,536

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 28 guests