| 04-01-2009, 07:27 PM | #1 |
Requires vJass This library gives you one new function: call AbilityPreload(abilityid). It will remove the delay the first time an ability is loaded into the game. Vexorian's xe system includes a preload module, but it has not been available as a script until now. JASS:library AbilityPreload //=========================================================================== // Information: //============== // // Preloading removes the noticeable delay the first time an ability // is loaded in a game. If an ability was not already on a pre-placed unit // or a unit that was created during initialization, preloading is needed // to prevent a delay. // //=========================================================================== // AbilityPreload API: //===================== // // AbilityPreload(abilityid) : // Call this before any time has elapsed to preload a specific // ability. If debug mode is enabled, you will see an error message // if you call this after initialization, or if you try to preload // an ability that does not exist. Will inline to a UnitAddAbility // call if debug mode is disabled. // // AbilityRangePreload(start, end) : // Same as AbilityPreload, but preloads a range of abilities. // It will iterates between the two rawcode values and preload // every ability along the way. It will not show an error message // for non-existent abilities. // //=========================================================================== // Configuration: //================ globals private constant integer PreloadUnitRawcode = 'zsmc' //This is the rawcode for "Sammy!". It is never used and has no model, //which makes an ideal preloading unit. Change it if you want to. endglobals //=========================================================================== globals private unit PreloadUnit endglobals function AbilityPreload takes integer abilityid returns nothing static if DEBUG_MODE then if GetUnitTypeId(PreloadUnit) == 0 then call BJDebugMsg("AbilityPreload error: Can't preload an ability after initialization") return endif endif call UnitAddAbility(PreloadUnit, abilityid) static if DEBUG_MODE then if GetUnitAbilityLevel(PreloadUnit, abilityid) == 0 then call BJDebugMsg("AbilityPreload error: Attempted to preload a non-existent ability") endif endif endfunction function AbilityRangePreload takes integer start, integer end returns nothing local integer i = 1 static if DEBUG_MODE then if GetUnitTypeId(PreloadUnit) == 0 then call BJDebugMsg("AbilityPreload error: Can't preload an ability after initialization") return endif endif if start > end then set i = -1 endif loop exitwhen start > end call UnitAddAbility(PreloadUnit, start) set start = start + i endloop endfunction //=========================================================================== private struct Init extends array private static method onInit takes nothing returns nothing set PreloadUnit = CreateUnit(Player(15), PreloadUnitRawcode, 0., 0., 0.) call UnitApplyTimedLife(PreloadUnit, 0, .001) call ShowUnit(PreloadUnit, false) call UnitAddAbility(PreloadUnit, 'Aloc') endmethod endstruct endlibrary |
| 04-01-2009, 07:57 PM | #2 |
cant you just give the unit a timedlife? |
| 04-01-2009, 08:08 PM | #3 |
0 duration timedlife doesn't work. it would also leave behind a corpse, leak a unit reference, set off death detection triggers, etc. |
| 04-01-2009, 08:29 PM | #4 |
An hero ability doesn't need to be preloaded ? |
| 04-01-2009, 09:05 PM | #5 |
It wouldn't leak a unit reference, you would just set the global unit to null when you apply the timed life. |
| 04-01-2009, 09:09 PM | #6 |
You have to keep that global reference until after init, otherwise the function wouldn't work. |
| 04-01-2009, 09:31 PM | #7 |
You should make it return a boolean and have that boolean be false if called after map initialization. It is always good to protect users from themselves. |
| 04-01-2009, 09:46 PM | #8 | |
Quote:
lol .. why not a simple debug message ? yes ..those users which are to dumb to use this in init-triggers will surely do something like: JASS:if not preloadblabla(bla) then debug BJDebugMsg("im dumb") endif have i missunderstood your thought ? |
| 04-01-2009, 09:57 PM | #9 |
I made it print an error message if you call it either before the library is initialized or after the unit has been removed. |
| 04-01-2009, 10:57 PM | #10 |
Hrm, it is true that the returned boolean would be pretty useless, so I agree that an error message is the better solution. You should prefix the error message with the debug keyword so that users can choose if they want it to appear or not. Once that is done, this is more than ready to be approved. |
| 04-02-2009, 02:08 AM | #11 |
Wait, can you call it before the init function runs? Without function interfaces at least? Any library that requires this one would get initialised after it. |
| 04-02-2009, 02:47 AM | #12 |
I don't get why you set a TimedLife AND use a timer. The name will conflict with CS. |
| 04-02-2009, 04:49 AM | #13 |
I don't get why you set a TimedLife AND use a timer. The name will conflict with CS. |
| 04-02-2009, 05:22 AM | #14 | |||
Quote:
I don't think that all error messages should necessarily be debug. My rule is: if there's any valid reason they could encounter the error message when using the library correctly, it should be debug so it doesn't disrupt gameplay. In this case, getting an error message means you really screwed it up, so debug would just be a way to help the user not notice that. Let me know if you disagree. Quote:
You can do it by calling the function from a struct's onInit method. Vex might add other ways to do things "before init" later on. Quote:
Typo from when I was checking emjlr3's suggestion, fixed it. About the name conflict, I am not sure what to do. Pros of leaving it alone: 1.) PreloadAbility is a pretty specific function name, changing it would be lame. 2.) The user won't need this library if they have CS in their map. 3.) CS does not seem to be be used often anymore. Cons: 1.) If they need both CS and a library that requires this, they would have to delete this library and make things not require it. I am leaning toward leaving it alone. |
| 04-02-2009, 08:09 AM | #15 |
An hero abiliy doesnt need to be preloaded ? |
