• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Crash] killing unit has item of type crashes?

Status
Not open for further replies.
Level 5
Joined
Aug 19, 2015
Messages
68
Hi guys,
My map has been very stable recently and when i added this trigger, it crashed pretty fast so i think this was the reason.
What's wrong with this code?
  • Bonus Gold Item
    • Events
      • Unit - A unit Dies
    • Conditions
      • ((Killing unit) has an item of type Anatomic map) Equal to True
    • Actions
      • Player - Add 3 to (Owner of (Killing unit)) Current gold
The JASS looks fine to me

In JASS, the trigger looks like this:
JASS:
function Trig_Untitled_Trigger_001_Copy_Conditions takes nothing returns boolean
    if ( not ( UnitHasItemOfTypeBJ(GetKillingUnitBJ(), 'I000') == true ) ) then
        return false
    endif
    return true
endfunction

function Trig_Untitled_Trigger_001_Copy_Actions takes nothing returns nothing
    call AdjustPlayerStateBJ( 3, GetOwningPlayer(GetKillingUnitBJ()), PLAYER_STATE_RESOURCE_GOLD )
endfunction

//===========================================================================
function InitTrig_Untitled_Trigger_001_Copy takes nothing returns nothing
    set gg_trg_Untitled_Trigger_001_Copy = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Untitled_Trigger_001_Copy, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition( gg_trg_Untitled_Trigger_001_Copy, Condition( function Trig_Untitled_Trigger_001_Copy_Conditions ) )
    call TriggerAddAction( gg_trg_Untitled_Trigger_001_Copy, function Trig_Untitled_Trigger_001_Copy_Actions )
endfunction

I looked up UnitHasItemOfTypeBJ
http://wiki.thehelper.net/wc3/jass/Blizzard.j/UnitHasItemOfTypeBJ
JASS:
function UnitHasItemOfTypeBJ takes unit whichUnit, integer itemId returns boolean
    return GetInventoryIndexOfItemTypeBJ(whichUnit, itemId) > 0
endfunction

and GetInventoryIndexOfItemTypeBJ
http://wiki.thehelper.net/wc3/jass/Blizzard.j/GetInventoryIndexOfItemTypeBJ
JASS:
function GetInventoryIndexOfItemTypeBJ 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
            return index + 1
        endif

        set index = index + 1
        exitwhen index >= bj_MAX_INVENTORY
    endloop
    return 0
endfunction



Thanks.
 
Status
Not open for further replies.
Top