Jump to content

Photo

Elemental Damage


  • Please log in to reply
77 replies to this topic

#16 Binx

Binx

    Formerly Lineas

  • Members
  • Real Name:Brian
  • Location:Lancaster, CA

Posted 16 August 2013 - 11:29 PM

So, um... I think it's incompatible with "zora" type enemies. Ever since I added this script, it auto-kills all zora enemies on screen (and I have a feeling it'll have problems with leevers as well). I think it has something to do with the diving/surfacing mechanic.



#17 grayswandir

grayswandir

    semi-genius

  • Members

Posted 16 August 2013 - 11:50 PM

So, turns out Zoras don't like having exactly 100 extra hp. You can take out the extra hp completely. Just changing the constant to 200 worked for me as well.

 

Remove

  // Set their new HP to increase by the fake amount
  n->HP += NPC_FAKE_HP;

and

  // If actual hp has hit 0, die.
  if (n->HP <= NPC_FAKE_HP) {
    n->HP = 0;}


#18 Binx

Binx

    Formerly Lineas

  • Members
  • Real Name:Brian
  • Location:Lancaster, CA

Posted 17 August 2013 - 12:30 AM

Ah, that's MUCH better :)



#19 grayswandir

grayswandir

    semi-genius

  • Members

Posted 18 August 2013 - 08:49 PM

Also, I was thinking - you could probably have elemental 'stun damage' as well, by giving weapons a damage from 1 to 9. (So no neutral stun, sadly - you'd have to rely on the builtin stun.) Something like:

// Check if enemies are damaged by 0 damage weapons.
if (damage == 0 && n->MiscFlags & 1) {damage = 1;}
// Stun enemy.
if (damage == 0) {
  n->Stun = 120 * GetDamageMultiplier(element, n->Misc[MISC_NPC_ELEMENT]);}

Edited by grayswandir, 18 August 2013 - 08:52 PM.


#20 Binx

Binx

    Formerly Lineas

  • Members
  • Real Name:Brian
  • Location:Lancaster, CA

Posted 18 August 2013 - 09:26 PM

That's actually a neat idea, but I tend to think that stunning already breaks the game a bit to much, I prefer having them just take 0 damage, instead.



#21 Binx

Binx

    Formerly Lineas

  • Members
  • Real Name:Brian
  • Location:Lancaster, CA

Posted 21 August 2013 - 03:30 PM

Argh, Ok, I'm REALLY trying to do this myself, but I'm totally lost on this part of the script (on which parts need to be changed so that it affects Link, instead of enemies) I figure that I just replace "NPC" with "Link" in most places, but I have no idea which ones I am supposed to replace, which functions need to be removed completely, and which areas need a new function added. 

// Updates all npcs.
void NPC_Update() {
  for (int i = 1; i <= Screen->NumNPCs(); i++) {
    NPC_Update(Screen->LoadNPC(i));}}
 
// Updates this npc.
void NPC_Update(npc n) {
  NPC_Initialize(n);
  NPC_Damage(n);}
 
// If this NPC hasn't been initialized, do so and mark it.
void NPC_Initialize(npc n) {
  // Exit out if they've already been initialized.
  if (n->Misc[MISC_NPC_INIT] != 0) {return;}
  // Record their current HP.
  n->Misc[MISC_NPC_OLD_HP] = n->HP;
  // Set their element to Misc Attribute 11.
  n->Misc[MISC_NPC_ELEMENT] = n->Attributes[10];
  // Mark them as initialized.
  n->Misc[MISC_NPC_INIT] = 1;}
 
// Take damage as appropriate.
void NPC_Damage(npc n) {
  // See if we took any hits, and quit if we didn't.
  int hit = n->Misc[MISC_NPC_OLD_HP] - n->HP;
  if (hit <= 0) {return;}
  // Go back up to the hp we had before (so we can subtract the proper
  // amount this time.)
  n->HP = n->Misc[MISC_NPC_OLD_HP];
  // Item editor only let's us specify damage in increments of 2,
  // so half the damage here where we interpret it.
  hit >>= 1;
  // Interpret the hit value.
  int element = hit % 10;
  int damage = (hit * 0.2) >> 0;
  // Damage multipliers
  damage *= GetDamageMultiplier(element, n->Misc[MISC_NPC_ELEMENT]);
  // Apply damage.
  n->HP -= damage;
  // Update the 'old' value to the new amount.
  n->Misc[MISC_NPC_OLD_HP] = n->HP;
}

Part of this is that I need to add it to a tunic, rather than Link directly, but I figure that would be easy as adding 

int Link_Element = 0;


item script ElementTunic
{
 void run(int TunicElement)
 {
  Link_Element == TunicElement;  //Actually, I'm not sure if I did this part right, I can't remember if I just need to change the Link_Element variable or if I needed a pointer, here.
 }
}

Or something like that.



#22 grayswandir

grayswandir

    semi-genius

  • Members

Posted 21 August 2013 - 05:42 PM

The main difference between enemies and Link is that there's only 1 Link, while there are many enemies. So anything that you need to keep track of on a per-enemy basis (Like their HP, or 1 of their Misc slots) you can get away with just a global variable for Link. (Some of the existing variables, of course, are of the form Link->HP. But that's just how they were chosen to be - having the variable LinkHP would have worked as well.)

 

NPC_Initialize is called every frame so if any new enemies appear, it can set their default values for them. Since there's only 1 Link, and he's always there, you can get away with doing anything in that function at the very beginning of the script, or even just as the initial values for the global variables.

 

So the only real thing you need to do is change NPC_Damage() to, say, Link_Damage(), and call it every frame. Take any of the n->X variables and replace them with the corresponding variable for Link (n->HP to Link->HP), or make a global variable for it if Link doesn't already have one.

 

 

 

Your item script looks good, you just need to change the == to =. Later on you can add the other special effects when you pick up the tunic as well, but that's all you'll need for the element.

 

And remember that you'll want all the tunics to have their defense value set to 1, so it doesn't mess up the elements. You might want to have the tunics set a Link_Defense variable as well when you pick them up.

 

 

 

Edit: In case you didn't know, to see what variables already exist, just open up zscript.txt and search for "Link Functions" to bring you to the section with all the Link->X variables.


Edited by grayswandir, 21 August 2013 - 05:43 PM.


#23 Binx

Binx

    Formerly Lineas

  • Members
  • Real Name:Brian
  • Location:Lancaster, CA

Posted 21 August 2013 - 06:30 PM

Gah, I can never get straight when I'm supposed to use "=" and when I'm supposed to use "==", I thought you use "==" to say "x equals y" and "=" to assign a value to a variable (which, in math, would also be x equals y).


Edited by Lineas, 21 August 2013 - 06:31 PM.


#24 David

David

    Fallen leaves... adorn my night.

  • Administrators
  • Real Name:David
  • Pronouns:He / Him

Posted 21 August 2013 - 06:33 PM

Ya, that's sort of it. When you assign a value to any variable, you use "=". If you are asking the question "does variable x = variable y", you use "==". So you'd use the "==" for if statements and the like.



#25 Binx

Binx

    Formerly Lineas

  • Members
  • Real Name:Brian
  • Location:Lancaster, CA

Posted 21 August 2013 - 06:47 PM

Well, yeah, but in the case of the item script... Oh wait, so if I use "=" it reads it as "reassign the value of variable x to the value of variable y". but if I use "==" it reads it as "the value of variable x is equal to the value of variable y" which would break down, since one of the variables would, of course,  not equal the other. But that leaves the question, why the difference between assigning a variable and assigning equality? I mean, if I wanted to make it so Link_Element doesn't get changed, wouldn't I just assign it as a constant, instead? Why do we need two different equivalency commands? I mean, I'm coming at this from the point of view of someone who doesn't understand programming. All I know is that this stuff is math, and I'm usually good at math, but in regular math, "=" is used for both assigning and equivalency, because in most cases, they're the same thing. I'm trying not to sound whiny, because I know that the "why" isn't important, since it's just the way things are, but it's hard for me to wrap my head around.



#26 David

David

    Fallen leaves... adorn my night.

  • Administrators
  • Real Name:David
  • Pronouns:He / Him

Posted 21 August 2013 - 06:52 PM

Ya, that's it.

And also, I think it is something that got accepted into all programming languages. I don't know the answer to that; only a person that makes programming languages or is a programming master would now that. I just learned it that way and it's the way I understand it... So ya :D

#27 grayswandir

grayswandir

    semi-genius

  • Members

Posted 21 August 2013 - 07:08 PM

= is assignment. When x = y is run, it makes x take on the value of y. To make this more clear, some languages use stuff like x <- y or x := y.

 

== is a test for equality. When x == y is run, you can think of it as replacing itself with true or false in the code. Here's an example, step by step, of what the code actually does:

(1 == 1) && (2 == 3)

(true) && (2 == 3)

true && (2 == 3)

true && (false)

true && false

false

 

In regular math, = is used for saying "these two values are equal to each other". There's no such thing as assignment in regular math, because there's no way for a variable to change it's value. For a certain problem, if you say "x = 14", you can't later turn around and make x = 15.

 

 

Anyway, the point is that = is for changing a variable, and == is for testing a variable. They're two completely different things, they just happen to have similar symbols.

 

If you didn't have =, you wouldn't be able to change the value of a variable (it would effectively be a constant).

 

If you didn't have ==, you'd have no way to actually use the variable (for some things, anyway). You'd be able to set Link's element to whatever you wanted, but you'd have no way to say "If Link's element is Fire, do this", because you'd end up changing Link's element instead.


Edited by grayswandir, 21 August 2013 - 07:14 PM.


#28 David

David

    Fallen leaves... adorn my night.

  • Administrators
  • Real Name:David
  • Pronouns:He / Him

Posted 21 August 2013 - 07:15 PM

And there's your beatiful answer! :D

#29 Binx

Binx

    Formerly Lineas

  • Members
  • Real Name:Brian
  • Location:Lancaster, CA

Posted 21 August 2013 - 07:16 PM

Ah, ok, I get that. It does seem a bit backwards, though. Maybe that's what was getting to me, since "=" is equality in mathematics, my brain expects that if they're going to add a new function (like assigning a value, which as you pointed out, doesn't really exist in basic math), then THAT would  be the one to use "==" but whatever, thanks for the explanation, that really cleared it up :)

 

EDIT: Although, in most cases of multiple variables, the variables themselves CAN change, just not their relation to each other (for example, if x=3y, both x and y can change their values, but x will always be 3 times what y's value is), like when you plot out an equation on a graph, but that would basically be the equivalent of a mathematical "if statement", I suppose, since changing one value changes all the others in the equation.


Edited by Lineas, 21 August 2013 - 07:21 PM.


#30 David

David

    Fallen leaves... adorn my night.

  • Administrators
  • Real Name:David
  • Pronouns:He / Him

Posted 21 August 2013 - 07:19 PM

Ya, I always thought that too when I first learned to program. But then I forced my brain to think the other way! :D

It'd be funny if someone in math put a double equal instead of one, and the teacher got confused... :lol: Ya, okay. :)


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users