- Joined
- Jun 5, 2007
- Messages
- 73
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.
Btw, the function "Kasta" (throw in swedish) doesn't return anything.
JASS:
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