| 05-07-2009, 02:37 AM | #1 |
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. JASS:globals constant integer CHAR_FIRSTDIGIT = 256*256*256 constant integer MOVE_ANIM_DEFAULT = 0 endglobals function GetUnitMoveAnimIndex takes unit u returns integer local integer t = GetUnitTypeId(u) local integer unitRace = (t / (CHAR_FIRSTDIGIT)) // HEROES if unitRace >= 'A' and unitRace <= 'Z' then if t == 'Hpal' then return 12 elseif t == 'Hamg' then return 0 elseif t == 'Hmkg' then return 7 elseif t == 'Hblm' then return 2 elseif t == 'Obla' then return 6 elseif t == 'Ofar' then return 3 elseif t == 'Otch' then return 3 elseif t == 'Oshd' then return 0 elseif t == 'Udea' then return 0 elseif t == 'Ulic' then return 4 elseif t == 'Udre' then return 5 elseif t == 'Ucrl' then return 2 elseif t == 'Ekee' then return 2 elseif t == 'Emoo' then return 6 elseif t == 'Edem' then return 8 elseif t == 'Edmm' then return 14 elseif t == 'Ewar' then return 2 elseif t == 'Nalc' then // Alchemist return 0 // ??? elseif t == 'Nalm' or t == 'Nal2' or t == 'Nal3' then // Enraged Alchemist return 0 // ??? elseif t == 'Nngs' then return 1 elseif t == 'Ntin' then // Tinker return 0 // ??? elseif t == 'Nrob' then // Robo-Tinker return 0 // ??? elseif t == 'Nbst' then return 0 elseif t == 'Nbrn' then return 8 elseif t == 'Nfir' then // Firelord return 0 // ??? elseif t == 'Npbm' then return 0 elseif t == 'Nplh' then return 1 endif // NEUTRALS elseif unitRace == 'n' then return 1 // HUMANS elseif unitRace == 'h' then if t == 'hpea' then return 10 elseif t == 'hmil' then return 5 elseif t == 'hfoo' then return 6 elseif t == 'hkni' then return 0 elseif t == 'hrif' then return 6 elseif t == 'hmtm' then return 0 elseif t == 'hgyr' then return 4 elseif t == 'hmpr' then return 1 elseif t == 'hsor' then return 2 elseif t == 'hmtt' or t == 'hrtt' then return 2 elseif t == 'hspt' then return 1 elseif t == 'hdhw' then return 4 elseif t == 'hwat' or t == 'hwt2' or t == 'hwt3' then return 3 elseif t == 'hphx' then return 4 endif // ORCS elseif unitRace == 'o' then if t == 'opeo' then return 1 elseif t == 'ogru' then return 0 elseif t == 'orai' then return 2 elseif t == 'otau' then return 2 elseif t == 'ohun' then return 4 elseif t == 'otbk' then return 17 elseif t == 'ocat' then return 0 elseif t == 'okod' then return 6 elseif t == 'owyv' then return 4 elseif t == 'otbr' then return 2 elseif t == 'odoc' then return 8 elseif t == 'oshm' then return 7 elseif t == 'ospw' or t == 'ospm' then return 2 elseif t == 'osw1' or t == 'osw2' or t == 'osw3' then return 2 endif // UNDEAD elseif unitRace == 'u' then if t == 'uaco' then return 2 elseif t == 'ushd' then return 5 elseif t == 'ugho' then return 1 elseif t == 'uabo' then return 1 elseif t == 'umtw' then return 0 elseif t == 'ucry' or t == 'ucrm' then return 2 elseif t == 'ugar' or t == 'ugrm' then return 1 elseif t == 'uban' then return 2 elseif t == 'unec' then return 6 elseif t == 'uobs' then return 10 elseif t == 'ufro' then return 3 elseif t == 'uske' then return 6 elseif t == 'uskm' then return 3 elseif t == 'ubsp' then return 3 elseif t == 'ucs1' or t == 'ucs2' or t == 'ucs3' or t == 'ucsB' or t == 'ucsC' then return 2 endif // NIGHT ELVES elseif unitRace == 'e' then if t == 'ewsp' then return 0 elseif t == 'earc' then return 7 elseif t == 'esen' then return 7 elseif t == 'edry' then return 8 elseif t == 'ebal' then return 0 elseif t == 'ehip' then return 3 elseif t == 'ehpr' then return 3 elseif t == 'echm' then return 3 elseif t == 'edot' then return 13 elseif t == 'edoc' then return 8 elseif t == 'emtg' then return 1 elseif t == 'efdr' then return 2 elseif t == 'edtm' then return 6 elseif t == 'edcm' then return 13 elseif t == 'efon' then return 2 elseif t == 'espv' then return 1 elseif t == 'even' then return 5 endif endif return MOVE_ANIM_DEFAULT endfunction |
| 05-07-2009, 03:23 AM | #2 |
Isn't it possible to do it with text macros to make it look neater? |
| 05-07-2009, 03:43 AM | #3 | |
Quote:
|
| 05-07-2009, 03:58 AM | #4 |
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 | |
Quote:
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 |
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 |
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 |
This would look a lot nicer if done with gamecache. |
| 05-07-2009, 03:47 PM | #9 | ||
Quote:
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 Quote:
Probably. |
| 05-07-2009, 04:26 PM | #10 |
gamecache would be several times faster than this. |
| 05-07-2009, 05:23 PM | #11 |
why need reimport when u just need the anim index? |
| 05-07-2009, 05:47 PM | #12 |
By popular demand, JASS:function GetUnitWalkAnim takes unit u returns integer return GetStoredInteger(udg_animcache, "walk", I2S(GetUnitTypeId(u))) endfunction function StoreUnitWalkAnims takes nothing returns nothing set udg_animcache = InitGameCache("anims.gc") // HEROES call StoreInteger(udg_animcache, "walk", I2S('Hpal'), 12) call StoreInteger(udg_animcache, "walk", I2S('Hamg'), 0) call StoreInteger(udg_animcache, "walk", I2S('Hmkg'), 7) call StoreInteger(udg_animcache, "walk", I2S('Hblm'), 2) call StoreInteger(udg_animcache, "walk", I2S('Obla'), 6) call StoreInteger(udg_animcache, "walk", I2S('Ofar'), 3) call StoreInteger(udg_animcache, "walk", I2S('Otch'), 3) call StoreInteger(udg_animcache, "walk", I2S('Oshd'), 0) call StoreInteger(udg_animcache, "walk", I2S('Udea'), 0) call StoreInteger(udg_animcache, "walk", I2S('Ulic'), 4) call StoreInteger(udg_animcache, "walk", I2S('Udre'), 5) call StoreInteger(udg_animcache, "walk", I2S('Ucrl'), 2) call StoreInteger(udg_animcache, "walk", I2S('Ekee'), 2) call StoreInteger(udg_animcache, "walk", I2S('Emoo'), 6) call StoreInteger(udg_animcache, "walk", I2S('Edem'), 8) call StoreInteger(udg_animcache, "walk", I2S('Edmm'), 14) call StoreInteger(udg_animcache, "walk", I2S('Ewar'), 2) // Alchemist, Chemical Rage: ‘Nalc’, ‘Nalm’, ‘Nal2’, ‘Nal3’ call StoreInteger(udg_animcache, "walk", I2S('Nngs'), 1) // Tinker, Robo-Goblin: ‘Ntin’, ‘Nrob’ call StoreInteger(udg_animcache, "walk", I2S('Nbst'), 0) call StoreInteger(udg_animcache, "walk", I2S('Nbrn'), 8) // Firelord: ‘Nfir’ call StoreInteger(udg_animcache, "walk", I2S('Npbm'), 0) call StoreInteger(udg_animcache, "walk", I2S('Nplh'), 1) // NEUTRALS // HUMANS call StoreInteger(udg_animcache, "walk", I2S('hpea'), 10) call StoreInteger(udg_animcache, "walk", I2S('hmil'), 5) call StoreInteger(udg_animcache, "walk", I2S('hfoo'), 6) call StoreInteger(udg_animcache, "walk", I2S('hkni'), 0) call StoreInteger(udg_animcache, "walk", I2S('hrif'), 6) call StoreInteger(udg_animcache, "walk", I2S('hmtm'), 0) call StoreInteger(udg_animcache, "walk", I2S('hgyr'), 4) call StoreInteger(udg_animcache, "walk", I2S('hmpr'), 1) call StoreInteger(udg_animcache, "walk", I2S('hsor'), 2) call StoreInteger(udg_animcache, "walk", I2S('hmtt'), 2) call StoreInteger(udg_animcache, "walk", I2S('hrtt'), 2) call StoreInteger(udg_animcache, "walk", I2S('hspt'), 1) call StoreInteger(udg_animcache, "walk", I2S('hdhw'), 4) call StoreInteger(udg_animcache, "walk", I2S('hwat'), 3) call StoreInteger(udg_animcache, "walk", I2S('hwt2'), 3) call StoreInteger(udg_animcache, "walk", I2S('hwt3'), 3) call StoreInteger(udg_animcache, "walk", I2S('hphx'), 4) // ORCS call StoreInteger(udg_animcache, "walk", I2S('opeo'), 1) call StoreInteger(udg_animcache, "walk", I2S('ogru'), 0) call StoreInteger(udg_animcache, "walk", I2S('orai'), 2) call StoreInteger(udg_animcache, "walk", I2S('otau'), 2) call StoreInteger(udg_animcache, "walk", I2S('ohun'), 4) call StoreInteger(udg_animcache, "walk", I2S('otbk'), 17) call StoreInteger(udg_animcache, "walk", I2S('ocat'), 0) call StoreInteger(udg_animcache, "walk", I2S('okod'), 6) call StoreInteger(udg_animcache, "walk", I2S('owyv'), 4) call StoreInteger(udg_animcache, "walk", I2S('otbr'), 2) call StoreInteger(udg_animcache, "walk", I2S('odoc'), 8) call StoreInteger(udg_animcache, "walk", I2S('oshm'), 7) call StoreInteger(udg_animcache, "walk", I2S('ospw'), 2) call StoreInteger(udg_animcache, "walk", I2S('ospm'), 2) call StoreInteger(udg_animcache, "walk", I2S('osw1'), 2) call StoreInteger(udg_animcache, "walk", I2S('osw2'), 2) call StoreInteger(udg_animcache, "walk", I2S('osw3'), 2) // UNDEAD call StoreInteger(udg_animcache, "walk", I2S('uaco'), 2) call StoreInteger(udg_animcache, "walk", I2S('ushd'), 5) call StoreInteger(udg_animcache, "walk", I2S('ugho'), 1) call StoreInteger(udg_animcache, "walk", I2S('uabo'), 1) call StoreInteger(udg_animcache, "walk", I2S('umtw'), 0) call StoreInteger(udg_animcache, "walk", I2S('ucry'), 2) call StoreInteger(udg_animcache, "walk", I2S('ucrm'), 2) call StoreInteger(udg_animcache, "walk", I2S('ugar'), 1) call StoreInteger(udg_animcache, "walk", I2S('ugrm'), 1) call StoreInteger(udg_animcache, "walk", I2S('uban'), 2) call StoreInteger(udg_animcache, "walk", I2S('unec'), 6) call StoreInteger(udg_animcache, "walk", I2S('uobs'), 10) call StoreInteger(udg_animcache, "walk", I2S('ufro'), 3) call StoreInteger(udg_animcache, "walk", I2S('uske'), 6) call StoreInteger(udg_animcache, "walk", I2S('uskm'), 3) call StoreInteger(udg_animcache, "walk", I2S('ubsp'), 3) call StoreInteger(udg_animcache, "walk", I2S('ucs1'), 2) call StoreInteger(udg_animcache, "walk", I2S('ucs2'), 2) call StoreInteger(udg_animcache, "walk", I2S('ucs3'), 2) call StoreInteger(udg_animcache, "walk", I2S('ucsB'), 2) call StoreInteger(udg_animcache, "walk", I2S('ucsC'), 2) // NIGHT ELVES call StoreInteger(udg_animcache, "walk", I2S('ewsp'), 0) call StoreInteger(udg_animcache, "walk", I2S('earc'), 7) call StoreInteger(udg_animcache, "walk", I2S('esen'), 7) call StoreInteger(udg_animcache, "walk", I2S('edry'), 8) call StoreInteger(udg_animcache, "walk", I2S('ebal'), 0) call StoreInteger(udg_animcache, "walk", I2S('ehip'), 3) call StoreInteger(udg_animcache, "walk", I2S('ehpr'), 3) call StoreInteger(udg_animcache, "walk", I2S('echm'), 3) call StoreInteger(udg_animcache, "walk", I2S('edot'), 13) call StoreInteger(udg_animcache, "walk", I2S('edoc'), 8) call StoreInteger(udg_animcache, "walk", I2S('emtg'), 1) call StoreInteger(udg_animcache, "walk", I2S('efdr'), 2) call StoreInteger(udg_animcache, "walk", I2S('edtm'), 6) call StoreInteger(udg_animcache, "walk", I2S('edcm'), 13) call StoreInteger(udg_animcache, "walk", I2S('efon'), 2) call StoreInteger(udg_animcache, "walk", I2S('espv'), 1) call StoreInteger(udg_animcache, "walk", I2S('even'), 5) endfunction |
| 05-07-2009, 05:57 PM | #13 |
globals blocks cant be declared on JASS! :P |
| 05-07-2009, 06:01 PM | #14 | |
Sure they can, but only at the top of the global map script. So move it there - is that so hard? Quote:
|
| 05-07-2009, 06:14 PM | #15 | |
Quote:
I dont remember i was able to do that. Did I miss something always? Have you tried this in the regular WE? |
