wc3campaigns
WC3C Homepage - www.wc3c.netUser Control Panel (Requires Log-In)Engage in discussions with other users and join contests in the WC3C forums!Read one of our many tutorials, ranging in difficulty from beginner to advanced!Show off your artistic talents in the WC3C Gallery!Download quality models, textures, spells (vJASS/JASS), systems, and scripts!Download maps that have passed through our rigorous approval process!

Go Back   Wc3C.net > Resources > Code Resources > Scripts
User Name
Password
Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar



Reply
 
Thread Tools Search this Thread
Old 04-01-2009, 07:27 PM   #1
grim001
requires vJass
 
grim001's Avatar


Code Moderator
 
Join Date: Nov 2006
Posts: 1,540

Submissions (10)

grim001 is just really nice (277)grim001 is just really nice (277)

Send a message via AIM to grim001
Default AbilityPreload

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.

Collapse 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


Last edited by grim001 : 10-17-2009 at 01:41 AM.
grim001 is offline   Reply With Quote
Sponsored Links - Login to hide this ad!
Old 04-01-2009, 07:57 PM   #2
emjlr3
Rehabbing
 
emjlr3's Avatar
 
Join Date: Jun 2005
Posts: 1,386

Submissions (14)

emjlr3 is a jewel in the rough (151)emjlr3 is a jewel in the rough (151)

Mapping Contest First Place

Send a message via AIM to emjlr3 Send a message via MSN to emjlr3
Default

cant you just give the unit a timedlife?
__________________
emjlr3 is offline   Reply With Quote
Old 04-01-2009, 08:08 PM   #3
grim001
requires vJass
 
grim001's Avatar


Code Moderator
 
Join Date: Nov 2006
Posts: 1,540

Submissions (10)

grim001 is just really nice (277)grim001 is just really nice (277)

Send a message via AIM to grim001
Default

0 duration timedlife doesn't work. it would also leave behind a corpse, leak a unit reference, set off death detection triggers, etc.
grim001 is offline   Reply With Quote
Old 04-01-2009, 08:29 PM   #4
Troll-Brain
User
 
Join Date: Oct 2006
Posts: 1,490

Submissions (1)

Troll-Brain has a spectacular aura about (134)

Default

An hero ability doesn't need to be preloaded ?
Troll-Brain is offline   Reply With Quote
Old 04-01-2009, 09:05 PM   #5
TheKid
User
 
TheKid's Avatar
 
Join Date: Mar 2009
Posts: 195

TheKid will become famous soon enough (37)TheKid will become famous soon enough (37)

Default

It wouldn't leak a unit reference, you would just set the global unit to null when you apply the timed life.
TheKid is offline   Reply With Quote
Old 04-01-2009, 09:09 PM   #6
grim001
requires vJass
 
grim001's Avatar


Code Moderator
 
Join Date: Nov 2006
Posts: 1,540

Submissions (10)

grim001 is just really nice (277)grim001 is just really nice (277)

Send a message via AIM to grim001
Default

You have to keep that global reference until after init, otherwise the function wouldn't work.
grim001 is offline   Reply With Quote
Old 04-01-2009, 09:31 PM   #7
Rising_Dusk
Obscurity, the Art


Projects Director
Project Leader: OD
 
Join Date: Feb 2006
Posts: 9,729

Submissions (27)

Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)

Hero Contest #3 - 1st PlaceApproved Map: Desert of ExileApproved Map: Advent of the ZenithHero Contest #2 - 1st PlaceHero Contest - Third place>

Send a message via AIM to Rising_Dusk Send a message via MSN to Rising_Dusk
Default

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.
__________________
Rising_Dusk is offline   Reply With Quote
Old 04-01-2009, 09:46 PM   #8
akolyt0r
In Flames
 
akolyt0r's Avatar
 
Join Date: Jan 2006
Posts: 1,154

Submissions (3)

akolyt0r has a spectacular aura about (120)

Default

Quote:
Originally Posted by Rising_Dusk
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.

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:
Collapse JASS:
if not preloadblabla(bla) then
debug BJDebugMsg("im dumb")
endif
to notice that they are dumb.

have i missunderstood your thought ?
__________________

Last edited by akolyt0r : 04-01-2009 at 09:48 PM.
akolyt0r is offline   Reply With Quote
Old 04-01-2009, 09:57 PM   #9
grim001
requires vJass
 
grim001's Avatar


Code Moderator
 
Join Date: Nov 2006
Posts: 1,540

Submissions (10)

grim001 is just really nice (277)grim001 is just really nice (277)

Send a message via AIM to grim001
Default

I made it print an error message if you call it either before the library is initialized or after the unit has been removed.

Last edited by grim001 : 04-01-2009 at 10:09 PM.
grim001 is offline   Reply With Quote
Old 04-01-2009, 10:57 PM   #10
Rising_Dusk
Obscurity, the Art


Projects Director
Project Leader: OD
 
Join Date: Feb 2006
Posts: 9,729

Submissions (27)

Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)

Hero Contest #3 - 1st PlaceApproved Map: Desert of ExileApproved Map: Advent of the ZenithHero Contest #2 - 1st PlaceHero Contest - Third place>

Send a message via AIM to Rising_Dusk Send a message via MSN to Rising_Dusk
Default

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.
__________________
Rising_Dusk is offline   Reply With Quote
Old 04-02-2009, 02:08 AM   #11
Anitarf
Procrastination Incarnate


Development Director
 
Join Date: Feb 2004
Posts: 8,186

Submissions (19)

Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)

2008 Spell olympics - Fire - SilverApproved Map: Old School Alliance TacticsHero Contest #2 - 3rd PlaceSpell making session 2 winner

Default

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.
__________________
Anitarf is offline   Reply With Quote
Old 04-02-2009, 02:47 AM   #12
JauntyJackalope
User
 
Join Date: Mar 2009
Posts: 1

JauntyJackalope has little to show at this moment (0)

Default

I don't get why you set a TimedLife AND use a timer. The name will conflict with CS.
JauntyJackalope is offline   Reply With Quote
Old 04-02-2009, 04:49 AM   #13
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,898

Submissions (37)

Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)

Hero Contest #3 - 2nd Place

Default

I don't get why you set a TimedLife AND use a timer. The name will conflict with CS.
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Old 04-02-2009, 05:22 AM   #14
grim001
requires vJass
 
grim001's Avatar


Code Moderator
 
Join Date: Nov 2006
Posts: 1,540

Submissions (10)

grim001 is just really nice (277)grim001 is just really nice (277)

Send a message via AIM to grim001
Default

Quote:
Originally Posted by Rising_Dusk
You should prefix the error message with the debug keyword so that users can choose if they want it to appear or not.

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:
Originally Posted by Anitarf
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.

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:
Originally Posted by Vexorian
I don't get why you set a TimedLife AND use a timer. The name will conflict with CS.

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.
grim001 is offline   Reply With Quote
Old 04-02-2009, 08:09 AM   #15
Troll-Brain
User
 
Join Date: Oct 2006
Posts: 1,490

Submissions (1)

Troll-Brain has a spectacular aura about (134)

Default

An hero abiliy doesnt need to be preloaded ?
Troll-Brain is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT. The time now is 07:08 PM.


Affiliates
The Hubb The JASS Vault Clan WEnW Campaign Creations Clan CBS GamesModding Flixreel Videos

Powered by vBulletin (Copyright ©2000 - 2018, Jelsoft Enterprises Ltd).
Hosted by www.OICcam.com
IT Support and Services provided by Executive IT Services