Preload script

Yizzy

New Member
Reaction score
20
Would anyone like to make me a trigger that preload my abilities..

I'm not that experianced with JAZZ..
My thought was to add a unit at init, add and remove all abilities and then remove the unit.. the problem is that the abilities are listed as a hex number and I only know how to make a loop with an integer..
Code:
function Trig_Preloading_Test_Actions takes nothing returns nothing
    set udg_TempPoint = GetRectCenter(GetPlayableMapRect())
    call CreateNUnitsAtLoc( 1, 'H01K', Player(PLAYER_NEUTRAL_PASSIVE), udg_TempPoint, bj_UNIT_FACING )
    set udg_TempUnit = GetLastCreatedUnit()
    set bj_forLoopAIndex = 0
    set bj_forLoopAIndexEnd = 149
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        call UnitAddAbilityBJ( 'A000+bj_forLoopAIndex', udg_TempUnit )
        call UnitRemoveAbilityBJ( 'A000+bj_forLoopAIndex', udg_TempUnit )
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
    call RemoveUnit( GetTriggerUnit() )
endfunction

//===========================================================================
function InitTrig_Preloading_Test takes nothing returns nothing
    set gg_trg_Preloading_Test = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Preloading_Test, function Trig_Preloading_Test_Actions )
endfunction

Thx
 

Exide

I am amazingly focused right now!
Reaction score
448
Try this trigger:
Not sure if it works, didn't test it:

JASS:

function Trig_Preloading_Test_Actions takes nothing returns nothing
    local location temppoint = GetRectCenter(GetPlayableMapRect())
    local integer abilitynr = 'A000'
    local integer loopnr = 0
    local unit preloadunit

    call CreateNUnitsAtLoc( 1, 'H01K', Player(PLAYER_NEUTRAL_PASSIVE), temppoint, 270 )
    set preloadunit = GetLastCreatedUnit()

    loop
        exitwhen loopnr > 149
        call UnitAddAbility( preloadunit, abilitynr )
        call UnitRemoveAbility( preloadunit, abilitynr )
        set loopnr = loopnr + 1
        set abilitynr = (abilitynr + loopnr)
    endloop

    call RemoveUnit( preloadunit )
    call RemoveLocation(temppoint)
    set preloadunit = null
    set temppoint = null
endfunction

//===========================================================================
function InitTrig_Preloading_Test takes nothing returns nothing
    set gg_trg_Preloading_Test = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Preloading_Test, function Trig_Preloading_Test_Actions )
endfunction
 

Yizzy

New Member
Reaction score
20
@Darthfett: As far as I can tell, the function responds to calls by ability_id, getting that was my issue. Meybe I'm wrong, thanks anyway, +rep

@Exide: Doesn't seem to work, +rep for trying ;). I realized that the ability id isen't a hex number as the name go up to 'z', instead of 'f', which would make it have the base 36 instead of 16 as in hexadecimal.. that would however make A000 = 466560, (A000 = 40960 in hex)

i tried this function just to test:
Code:
function Trig_Preloading_UI_Actions takes nothing returns nothing
    set udg_TempInt = 'A000'
    call DisplayTextToForce( GetPlayersAll(), I2S(udg_TempInt) )
    set udg_TempInt = 466560
    call DisplayTextToForce( GetPlayersAll(), I2S(udg_TempInt) )
endfunction

//===========================================================================
function InitTrig_Preloading_UI takes nothing returns nothing
    set gg_trg_Preloading_UI = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Preloading_UI, function Trig_Preloading_UI_Actions )
endfunction
my game says that A000 >> 466560. :banghead:

As I have 332 custom abilities (maybe not all neded to be preloaded, but atleast ~100), I would greatly appreciate if it is possible to make a loop in some way..


Donno if it's the best idea, for my search in this forum the only solution seems to be: create a unit and load each ability by hand..

Is that easier than what I'm proposing? Is that what experianced mappers do when the have a lot of abilities to preload, or are they just smart enough to use a smaller number of abilities..?
 

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
Ahh, you're having trouble getting the ability ID's ?

Go into the object editor, find your ability and press "Ctrl + D"

The first four characters are the ability id.

If it's a custom object, it will have 4 more characters after it, which is the ability id the custom ability is based off of.
 

Yizzy

New Member
Reaction score
20
@Darthfett:I'm too lazy to do that with 332 abilties.. :p

Hoped that you knew a better way..

Thanks anyway, I guess I have to do that..
 

Exide

I am amazingly focused right now!
Reaction score
448

Yizzy

New Member
Reaction score
20
@AceHart: They aren't on any units, I've based it off Baka_ranger's custom hero system. Do you know how he does it?

Still don't get why 'A000' would be 1093677104 ..?

BTW can I change the typo in the title of this topic..? I tried but it didn't work..
EDIT: Hmm, now it seem fixed.. :S
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
Hm... come to think of it, are you really sure you actually need this?
300+ abilities will take some time to load.
And it does not really make sense to preload them all if only some 20+ are used every game.
 

Yizzy

New Member
Reaction score
20
Good point, though it will cause lagg if players repick.. guess I'm gonna have to live with that.. Thx a lot anyway.. ;)
 

SFilip

Gone but not forgotten
Reaction score
634
> Still don't get why 'A000' would be 1093677104
It's base 256.
Think: ('A'*256^3)+('0'*256^2)+('0'*256^1)+('0'*256^0) where 'A' and '0' are corresponding ASCII values (65 and 48 respectively).

Anyway, I believe what AceHart actually suggested is that you preplace all your heroes in some region and remove them when the game starts (0.01 elapsed game time event or so). That's the same as preloading and therefore it would increase loading time, as already said.
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
Well, "Custom Hero", along with that link, suggests that the Heroes do not have any abilities to start with.
As such, putting them on the map only helps with the models, not the spells.
 

Cohadar

master of fugue
Reaction score
209
> Still don't get why 'A000' would be 1093677104
It's base 256.
Think: ('A'*256^3)+('0'*256^2)+('0'*256^1)+('0'*256^0) where 'A' and '0' are corresponding ASCII values (65 and 48 respectively).

I confirm this as true, furthermore you do not know to need the ascii table to use this since jass supports using one digit ascii numbers:
JASS:

    local integer i = 0

    // one ascii digit (8-bit byte)
    set i = 'A' // OK
    set i = '0' // OK
    set i = 'x' // OK

    // 4 ascii digits (32-bit integer)
    set i = 'Armf' // OK
    set i = 'R001' // OK
    set i = 'Itom' // OK

    // anything else
    set i = 'Ar' // ERROR
    set i = 'R00' // ERROR
 

Yizzy

New Member
Reaction score
20
Ok, after modifying Exide's function, in the 2nd post, I came up with this:
Code:
function Trig_Preloading_Test_Actions takes nothing returns nothing
    local integer abilitynr = 'A000'
    local integer loopnr = 0
    local unit preloadunit

    set preloadunit = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE), 'H01K', -8000, -6200, 270)

    loop
        exitwhen loopnr > 36
        call UnitAddAbility( preloadunit, abilitynr )
        call UnitRemoveAbility( preloadunit, abilitynr )
        set loopnr = loopnr + 1
        set abilitynr = abilitynr + 1
    endloop

    set loopnr = 0
    set abilitynr = 'A010'

    loop
        exitwhen loopnr > 36
        call UnitAddAbility( preloadunit, abilitynr )
        call UnitRemoveAbility( preloadunit, abilitynr )
        set loopnr = loopnr + 1
        set abilitynr = abilitynr + 1
    endloop

    set loopnr = 0
    set abilitynr = 'A020'

    loop
        exitwhen loopnr > 36
        call UnitAddAbility( preloadunit, abilitynr )
        call UnitRemoveAbility( preloadunit, abilitynr )
        set loopnr = loopnr + 1
        set abilitynr = abilitynr + 1
    endloop

    set loopnr = 0
    set abilitynr = 'A030'

    loop
        exitwhen loopnr > 36
        call UnitAddAbility( preloadunit, abilitynr )
        call UnitRemoveAbility( preloadunit, abilitynr )
        set loopnr = loopnr + 1
        set abilitynr = abilitynr + 1
    endloop

    set loopnr = 0
    set abilitynr = 'A040'

    loop
        exitwhen loopnr > 36
        call UnitAddAbility( preloadunit, abilitynr )
        call UnitRemoveAbility( preloadunit, abilitynr )
        set loopnr = loopnr + 1
        set abilitynr = abilitynr + 1
    endloop

    set loopnr = 0
    set abilitynr = 'A050'

    loop
        exitwhen loopnr > 36
        call UnitAddAbility( preloadunit, abilitynr )
        call UnitRemoveAbility( preloadunit, abilitynr )
        set loopnr = loopnr + 1
        set abilitynr = abilitynr + 1
    endloop

    set loopnr = 0
    set abilitynr = 'A060'

    loop
        exitwhen loopnr > 36
        call UnitAddAbility( preloadunit, abilitynr )
        call UnitRemoveAbility( preloadunit, abilitynr )
        set loopnr = loopnr + 1
        set abilitynr = abilitynr + 1
    endloop

    set loopnr = 0
    set abilitynr = 'A070'

    loop
        exitwhen loopnr > 36
        call UnitAddAbility( preloadunit, abilitynr )
        call UnitRemoveAbility( preloadunit, abilitynr )
        set loopnr = loopnr + 1
        set abilitynr = abilitynr + 1
    endloop

    set loopnr = 0
    set abilitynr = 'A080'

    loop
        exitwhen loopnr > 36
        call UnitAddAbility( preloadunit, abilitynr )
        call UnitRemoveAbility( preloadunit, abilitynr )
        set loopnr = loopnr + 1
        set abilitynr = abilitynr + 1
    endloop

    set loopnr = 0
    set abilitynr = 'A090'

    loop
        exitwhen loopnr > 5
        call UnitAddAbility( preloadunit, abilitynr )
        call UnitRemoveAbility( preloadunit, abilitynr )
        set loopnr = loopnr + 1
        set abilitynr = abilitynr + 1
    endloop

    call RemoveUnit( preloadunit )
    set preloadunit = null
endfunction

//===========================================================================
function InitTrig_Preloading_Test takes nothing returns nothing
    set gg_trg_Preloading_Test = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Preloading_Test, function Trig_Preloading_Test_Actions )
endfunction

Which cause a several seconds lagg on startup but seem to work.. is this a very bad way to solve this problem?
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top