1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. We have recently started the 16th edition of the Mini Mapping Contest. The theme is mini RPG. Do check it out and have fun.
    Dismiss Notice
  4. Dismiss Notice
  5. The Highway to Hell has been laid open. Come along and participate in the 5th Special Effect Contest.
    Dismiss Notice
  6. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

Massive lag...

Discussion in 'Triggers & Scripts' started by Risc, Jul 23, 2008.

  1. Risc

    Risc

    Joined:
    Jun 5, 2007
    Messages:
    81
    Resources:
    1
    Tools:
    1
    Resources:
    1
    I have a map in which you can throw a hat :)P). When a unit starts to cast the throw-hat ability I check if the caster has the "hat-item". However, even if he doesn't have the item, and the trigger doesn't start, it causes massive lag after a few iterations. Even if I uncomment the lines that actually "throws" the hat and starts the timer, it lags. Could someone please take a look at this? (oh yeah, i modified the BJ's a bit too as you can see)

    Btw, the function "Kasta" (throw in swedish) doesn't return anything.

    Code (vJASS):

    function GetInventoryIndexOfItemType takes unit whichUnit, integer itemId returns integer
        local integer index
        local item    indexItem

        set index = 0
        loop
            set indexItem = UnitItemInSlot(whichUnit, index)
            if (indexItem != null) and (GetItemTypeId(indexItem) == itemId) then
                call RemoveItem(indexItem)
                return index + 1
            endif

            set index = index + 1
            call RemoveItem(indexItem)
            exitwhen index >= bj_MAX_INVENTORY
        endloop
        call RemoveItem(indexItem)
        return 0
    endfunction

    function GetItemOfTypeFromUnit takes unit whichUnit, integer itemId returns item
        local integer index = GetInventoryIndexOfItemType(whichUnit, itemId)

        if (index == 0) then
            return null
        else
            return UnitItemInSlot(whichUnit, index - 1)
        endif
    endfunction

    function Trig_Throw_Hat_Conditions takes nothing returns boolean
        if ( not ( GetSpellAbilityId() == 'A002' ) ) then
            return false
        endif
        if( GetInventoryIndexOfItemType(GetSpellAbilityUnit(), 'I000') == 0 ) then
            return false
        endif
        return true
    endfunction

    function Trig_Throw_Hat_Actions takes nothing returns nothing
        //kasta
        local item item_hatten
        set item_hatten = GetItemOfTypeFromUnit(GetTriggerUnit(), 'I000')
        call Kasta(GetTriggerUnit(), GetSpellTargetLoc())
        //ta bort item hatt
        call UnitRemoveItem(GetTriggerUnit(), item_hatten)
        call RemoveItem(item_hatten)
    endfunction

    //===========================================================================
    function InitTrig_Throw_Hat takes nothing returns nothing
        set gg_trg_Throw_Hat = CreateTrigger(  )
        call TriggerRegisterAnyUnitEventBJ( gg_trg_Throw_Hat, EVENT_PLAYER_UNIT_SPELL_CAST )
        call TriggerAddCondition( gg_trg_Throw_Hat, Condition( function Trig_Throw_Hat_Conditions ) )
        call TriggerAddAction( gg_trg_Throw_Hat, function Trig_Throw_Hat_Actions )
    endfunction
     
     
  2. Risc

    Risc

    Joined:
    Jun 5, 2007
    Messages:
    81
    Resources:
    1
    Tools:
    1
    Resources:
    1
    Solved it. Based it on the shockwave ability, which when set to 0 length caused the game to lag.