Jump to content

Photo

Links defense issue


  • Please log in to reply
5 replies to this topic

#1 Avaro

Avaro

    o_o

  • Members
  • Real Name:Robin
  • Location:Germany

Posted 14 January 2017 - 06:03 PM

Hey! I got an issue with a scripted damage divisor. Here's the script:

float LinksDefense = 0;

global script Active{
    void run(){
        int lastFrameLinkHP = Link->HP;
        while(true){
            Waitdraw();
            if ( Link->HP < lastFrameLinkHP && LinksDefense > 0 ) {
                Link->HP += (lastFrameLinkHP - Link->HP) / LinksDefense;
            }
            lastFrameLinkHP = Link->HP;
            Waitframe();
        }
    }
}

I have items that set LinksDefense to 1.5 or 2 or whatever. The issue now is when Link gets very low. It feels like the lower he gets, the higher his defense becomes somehow. I can't figure out how to fix this. :o



#2 Deedee

Deedee

    Bug Frog Dragon Girl

  • Moderators
  • Real Name:Deedee
  • Pronouns:She / Her, They / Them
  • Location:Canada

Posted 14 January 2017 - 06:19 PM

Hey! I got an issue with a scripted damage divisor. Here's the script:

float LinksDefense = 0;

global script Active{
    void run(){
        int lastFrameLinkHP = Link->HP;
        while(true){
            Waitdraw();
            if ( Link->HP < lastFrameLinkHP && LinksDefense > 0 ) {
                Link->HP += (lastFrameLinkHP - Link->HP) / LinksDefense;
            }
            lastFrameLinkHP = Link->HP;
            Waitframe();
        }
    }
}

I have items that set LinksDefense to 1.5 or 2 or whatever. The issue now is when Link gets very low. It feels like the lower he gets, the higher his defense becomes somehow. I can't figure out how to fix this. :o

Simple: Link's health is both A: Rounded, and B: will never go below 0 (feel free to correct me on these if I'm wrong). The combination of these mean that Link will either be invincible or have extremely high defense the less health he has. Let's say Link has 2 health left, and a weapon does 8 damage.

Normally, with a theoretical defense of 2 and if Link's health could go below 0, his health would be set to -6 (2 - 8 = -6), and then his health would be raised by 4 (2 - -6 = 8,  8 / 2 = 4), leaving him with -2 health, meaning he is still dead.

However, because Link's health can't go below 0, it would go more like this: his health would be set to 0 (2 - 8 = -6, -6 -> 0), then his health would be raised by 1 (2 - 0 = 2, 2 / 2 = 1), leaving him with 1 health, still alive. With a defense of 2, this would mean he is invincible, as with even 1 health left, and he takes any amount of damage, his health would be raised by 0.5 health (1 - 0 = 1, 1 / 2 = 0.5), which rounds up 1, meaning he cannot die.


Frankly, I'd just use peril rings to simulate having higher defenses.


Edited by Dimentio, 14 January 2017 - 06:20 PM.


#3 Jamian

Jamian

    ZC enthusiast

  • Members

Posted 14 January 2017 - 06:52 PM

IIRC you can use Game->Counter[CR_LIFE] instead of Link->HP. That counter is not bound by the same rules.

 

It can still cause bugs if you don't have safeguards though, so it will still require you to check whether Link's health is valid. In either case you need to check whether the player should die before you boost his health.


Edited by Jamian, 14 January 2017 - 07:06 PM.

  • Avaro likes this

#4 Saffith

Saffith

    IPv7 user

  • Members

Posted 14 January 2017 - 08:45 PM

What's setting LinkDefense? How is it supposed to work?
The name suggests that the higher LinkDefense is, the less damage Link takes, but the reverse is true - higher LinkDefense, more damage. Is that how you meant for it to work?

#5 Avaro

Avaro

    o_o

  • Members
  • Real Name:Robin
  • Location:Germany

Posted 15 January 2017 - 09:34 AM

What's setting LinkDefense? How is it supposed to work?
The name suggests that the higher LinkDefense is, the less damage Link takes, but the reverse is true - higher LinkDefense, more damage. Is that how you meant for it to work?

I think you just misread my script. What it does is heal Link for a part of the damage he takes.

 

But yeah, thanks guys. That should help me out.



#6 Saffith

Saffith

    IPv7 user

  • Members

Posted 15 January 2017 - 11:24 AM

Right, but the higher it is, the less HP it'll restore. If LinkDefense is 2, it will restore half the health he lost; if it's 1, it restores all of it. If that's what you intended, it's fine. It's just counterintuitive, so I want to make sure that's not a mistake.

Looking at the HP handling code a bit, the game does indeed refuse to set Link->HP below 0 normally. That's true internally, as well; getting hit by an enemy won't reduce HP below 0. You could counter this by have an invisible heart container or two and killing Link when the damage eats into those.
  • Avaro likes this


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users