HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

function GetUnitWalkAnimIndex

05-07-2009, 02:37 AM#1
cosmicat
Since the issue of SetUnitAnimation(u, "walk") seems to come up every once in a while here, and since this sort of function might be nice to have around even if you weren't initially thinking of using a "walk" animation as a spell effect, and in spite of the fact that this is more than four years overdue, I have decided to put together a brute-force function to attempt to solve the problem. The result is below - it did take more time than I would have liked it to, but it works. More or less.

Due to its brute-force nature, this function fails if you change the model of a melee unit. New units simply have to be added to the function somewhere. I did cut down the "search time" a bit by taking advantage of the race prefix character, but it's still rather clunky.

Also, the only units currently supported are the melee, pre-patch player units. Neutrals, Campaign units, and the newest Tavern heroes are not indexed yet. Assistance with this rather voluminous chore would certainly be appreciated.

Expand JASS:
05-07-2009, 03:23 AM#2
wraithseeker
Isn't it possible to do it with text macros to make it look neater?
05-07-2009, 03:43 AM#3
cosmicat
Quote:
Originally Posted by wraithseeker
Isn't it possible to do it with text macros to make it look neater?
Not to name names or anything, but there are some people here who still don't use vJass. The original purpose of this script (the bit I wrote, anyway) is for just such a person. Feel free to take the concept and textmacro it if you want to.
05-07-2009, 03:58 AM#4
MaD[Lion]
why not make an anim index library... but i think all that is just for waste. cus its alot easier to just use a model editor
05-07-2009, 04:09 AM#5
Kyrbi0
Quote:
Originally Posted by MaD[Lion]
why not make an anim index library... but i think all that is just for waste. cus its alot easier to just use a model editor
Sure, but not if you want this to work for all the in-game units, without having to modify everything and re-import them; that's ridiculous.

That, and for custom races (whole techtrees of custom units with or without custom models that have to be indexed).
05-07-2009, 04:16 AM#6
cosmicat
Reimporting every single unit model will increase the size of your map. Personally I'd rather have a few bytes of code than several hundred kilobytes of re-imported *.mdl files.
05-07-2009, 08:27 AM#7
Silvenon
I think that the CHAR_FIRSTDIGIT is a pretty cool idea to get a race from an ID, I would have never thought of that. Can you please explain me how that works? Since I'm not so good with hexadecimal ids (if that's what they are).
05-07-2009, 10:09 AM#8
Anitarf
This would look a lot nicer if done with gamecache.
05-07-2009, 03:47 PM#9
cosmicat
Quote:
Originally Posted by Silvenon
I think that the CHAR_FIRSTDIGIT is a pretty cool idea to get a race from an ID, I would have never thought of that. Can you please explain me how that works? Since I'm not so good with hexadecimal ids (if that's what they are).

An integer in single quotes represents a byte, and has the same integer value as a char datatype would in a language like C++ or Java. If you're not familiar with that, this means the true integer value of a character in single quotes is its ASCII value. So 'A' = 65, 'a' = 97, and so on. You can see the whole table here. Jass uses extended ASCII (underneath the first table), so there are 256 possible integer values for a character (starting with 0 and ending with 255). So what we really have is a base-256 notation, except there's no easy way to write the equivalent of 1 or 0 since '0' is actually 48 and '1' is really 49.

An object type is represented with a string of four bytes - '####'. So 'abcd' represents
Code:
'a' * 256^3 + 'b' * 256^2 + 'c' * 256^1 + 'd' * 256^0
So to get the first digit, I use integer division by 256^3.

Quote:
Originally Posted by Anitarf
This would look a lot nicer if done with gamecache.

Probably.
05-07-2009, 04:26 PM#10
Vexorian
gamecache would be several times faster than this.
05-07-2009, 05:23 PM#11
MaD[Lion]
why need reimport when u just need the anim index?
05-07-2009, 05:47 PM#12
cosmicat
By popular demand,

Expand JASS:
05-07-2009, 05:57 PM#13
Alevice
globals blocks cant be declared on JASS! :P
05-07-2009, 06:01 PM#14
cosmicat
Sure they can, but only at the top of the global map script. So move it there - is that so hard?

Quote:
Originally Posted by MaD[Lion]
why need reimport when u just need the anim index?
If you change the anim index, you're changing the model file. You have to reimport the *.mdl file to rearrange the animation indices, and not only is that actually *more* work with a project of this scope, but it also takes up precious KBs.
05-07-2009, 06:14 PM#15
Alevice
Quote:
Originally Posted by cosmicat
Sure they can, but only at the top of the global map script. So move it there - is that so hard?

I dont remember i was able to do that. Did I miss something always? Have you tried this in the regular WE?