• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Detecting when unit takes damage from certain spell?

Status
Not open for further replies.
Level 7
Joined
Oct 19, 2015
Messages
286
Wow, thanks man! Being the noob that I am I simply pasted that stuff into a trigger and ofc I got an error message. So this is a "library" huh? Would you mind briefly explaining what a library is? :)
Sure. A library allows you to use the private keyword, which prevents naming conflicts between multiple libraries - this allows you to use simple, short names for your variables and functions and reuse the same names in multiple libraries, which makes it a lot easier and faster to write (and read) code than if you had to type out long, unique names.

Another feature of libraries is that they can be declared to require other libraries, so if library B uses functions from library A then the compiler will make sure that library A is placed into the map script before library B (this is important because you can't call functions that are declared below the line you are calling from). This way, you can place individual libraries into individual "triggers", instead of having to add them all to the map header like you had to do before we had vJass. This helps a lot with code organisation.

I realize now I wrote a lot about how my example works, but I didn't write anything about how to make it work. Here's what you need to do:

First, you need an editor that can work with vJass, like the NewGen pack. I just assumed you have it but I guess not all people do, so I'm mentioning this first.

Then, you need to copy the spell library into your map, best place to put it is inside a GUI trigger converted to JASS.

You need to also include the libraries of all the systems that the spell uses. In the case of my example, I used SpellEvent and xe, I included the links to where you can get those libraries.

Some systems also require some setup and calibration before they're good to go. SpellEvent isn't one of them, you just need to copy the library into a trigger and you're done. xe, on the other hand, takes a few more steps to set up - besides the code, you need to also copy the custom dummy unit it uses and import the custom model for that dummy. Both those things can be found in the xe demo map attached in the linked thread. Once you have the dummy unit in the map, you must also set the appropriate constant in the xebasic library to the unit's rawcode.

Once you have all the needed libraries setup, you can save the map and it should do so without errors. Then, one last step is to edit the calibration constants in the spell library with your spell ability ids, and your spell should be good to go. Note that when you're using vJass, you always need to manually save the map before you test it, if you just click the test map button then the editor will try saving the map without processing the vJass so it won't work ingame.
 
Level 3
Joined
Mar 9, 2016
Messages
45

ok, thanks! But don't libraries add additional functionality also? I always thought libraries were collections of custom, community made, functions that aren't in the "vanilla" editor. The way you describe it here they sound more like quality-of-life-improvers?

Anyway, thanks for the information, I'll try to look into it but like I said earlier im learning on all cylinders atm already :D
 
Level 7
Joined
Oct 19, 2015
Messages
286
I was just explaining what the library functionality in vJass does. This, in turn, enables users to write and share custom systems like you described.

Theoretically, users could write such systems without vJass libraries and in fact, before vJass was around, they did! For example, the Caster System, which was the predecessor of xe that I linked to, was written before vJass. However, it was not very practical to write, maintain, share and use such code, so most people didn't bother to do it. Nowadays, though, it's a piece of cake. Even if you're doing this sort of thing for the first time, I'm pretty sure that it would still take you less time to get my example to work than to make the whole spell from scratch in GUI.
 
Level 3
Joined
Mar 9, 2016
Messages
45
I was just explaining what the library functionality in vJass does. This, in turn, enables users to write and share custom systems like you described.

Theoretically, users could write such systems without vJass libraries and in fact, before vJass was around, they did! For example, the Caster System, which was the predecessor of xe that I linked to, was written before vJass. However, it was not very practical to write, maintain, share and use such code, so most people didn't bother to do it. Nowadays, though, it's a piece of cake. Even if you're doing this sort of thing for the first time, I'm pretty sure that it would still take you less time to get my example to work than to make the whole spell from scratch in GUI.
oh, sorry i must have misunderstodd/misread. ill re-read :) thanks again
 
Status
Not open for further replies.
Top