• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] how to remove a lag?

Status
Not open for further replies.
Level 7
Joined
Mar 22, 2010
Messages
228
i was used to this script before but now i wasnt able to make it right..i dont know why.. and it causes me lag before so i want to configure a bit but i dont know how..

JASS:
scope ItemGet initializer onInit

globals
    private constant integer MY_ITEM    = 'I000'
    private constant integer MY_SPELL   = 'A000'
    private constant integer MY_SPELLBOOK   = 'A001'
endglobals

private function a takes nothing returns nothing
    local unit hero = GetTriggerUnit()
    local integer level = GetUnitAbilityLevel(hero, MY_SPELL)
    
    if level == 0 then
        call UnitAddAbility(hero, MY_SPELLBOOK)
    else
        call SetUnitAbilityLevel(hero, MY_SPELL, level + 1)
    endif

    set hero = null
    
endfunction

private function c takes nothing returns boolean
    return GetItemTypeId(GetManipulatedItem()) == MY_ITEM
endfunction

private function onInit takes nothing returns nothing
    local trigger t = CreateTrigger(  )
    TriggerAddCondition(t, Condition(function c))
    TriggerAddAction(t, function a)
    TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_PICKUP_ITEM)
endfunction

endscope

i have no idea why it gives me syntax errors
 
Level 37
Joined
Mar 6, 2006
Messages
9,243
JASS:
private function onInit takes nothing returns nothing
    local trigger t = CreateTrigger(  )
    call TriggerAddCondition(t, Condition(function c))
    call TriggerAddAction(t, function a)
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_PICKUP_ITEM)
endfunction

You forgot the calls.

Also this call TriggerAddCondition(t, Condition(function c)) can be just call TriggerAddCondition(t, function c) but it's not that important.

Does it lag every time the spell is used or just the first time? You could create a unit at initialization, give it the ability and then remove the unit.
 
Level 37
Joined
Mar 6, 2006
Messages
9,243
If you make the init trigger like this, then the ability will be cached and it will work faster the following times.

JASS:
private function onInit takes nothing returns nothing
    local trigger t = CreateTrigger(  )
    call TriggerAddCondition(t, Condition(function c))
    call TriggerAddAction(t, function a)
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_PICKUP_ITEM)
    set bj_lastCreatedUnit = CreateUnit(Player(15), 'Hpal', 0, 0, 0)
    call UnitAddAbility(bj_lastCreatedUnit, MY_SPELLBOOK)
    call UnitApplyTimedLife(bj_lastCreatedUnit, 1, 0.01)
endfunction
 
Status
Not open for further replies.
Top