HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Item SLot Exchanges EVENT/ACTION

06-01-2004, 03:57 AM#1
Danexx
I made a EVENT to Responing a unit Changes Item's Slot in Inventory.
and a ACTION to Exchange two Items' Slot..

I hope That could be addon to WEU or UMSWE...

Code:
function GetUnitChangesSourceItemSlot takes integer STFlag returns integer
    local integer TargetSlot = 0
    local integer SourceSlot = 0
    local item TargetItem = null
    local item SourceItem = GetOrderTargetItem()
    local integer ForLoopIndex = 1
    local integer ForLoopIndexEnd = 6
    loop
        exitwhen ( (ForLoopIndex > ForLoopIndexEnd) or (SourceSlot != 0) )
        if (SourceItem == UnitItemInSlotBJ(GetTriggerUnit(), ForLoopIndex)) then
            set SourceSlot = ForLoopIndex
        endif
        set ForLoopIndex = ForLoopIndex + 1
    endloop
    set TargetSlot = GetIssuedOrderIdBJ() - 852001
    set TargetItem = UnitItemInSlotBJ(GetTriggerUnit(), TargetSlot)
    if (STFlag == 0) then
        return SourceSlot
    else
        return TargetSlot
    endif
endfunction

function ChangesItemSlotCondition takes nothing returns boolean
    if ( not ( (GetIssuedOrderIdBJ() > 852001) and (GetIssuedOrderIdBJ() < 852008) ) ) then
        return false
    endif
    return true
endfunction

function TriggerRegisterUnitEventDA takes trigger whichTrigger, unit whichUnit returns nothing
    call TriggerRegisterUnitEvent( whichTrigger, whichUnit, EVENT_UNIT_ISSUED_TARGET_ORDER )
    call TriggerAddCondition( whichTrigger, Condition( function ChangesItemSlotCondition ) )
endfunction
function TriggerRegisterPlayerUnitEventSimpleDA takes trigger whichTrigger, player whichPlayer returns nothing
    call TriggerRegisterPlayerUnitEvent( whichTrigger, whichPlayer, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER, null )
    call TriggerAddCondition( whichTrigger, Condition( function ChangesItemSlotCondition ) )
endfunction
function TriggerRegisterAnyUnitEventDA takes trigger whichTrigger returns nothing
    call TriggerRegisterAnyUnitEventBJ( whichTrigger, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER )
    call TriggerAddCondition( whichTrigger, Condition( function ChangesItemSlotCondition ) )
endfunction

function MoveItemSlotDA takes unit ExcUnit, integer SourceSlot, integer TargetSlot returns nothing
    local item SourceItem = null
    local integer Order = 0
    if (UnitItemInSlotBJ(ExcUnit, SourceSlot) != null) then
        set SourceItem = UnitItemInSlotBJ(ExcUnit, SourceSlot)
        set Order = 852001 + TargetSlot
    else
        set SourceItem = UnitItemInSlotBJ(ExcUnit, TargetSlot)
        set Order = 852001 + SourceSlot
    endif
    call IssueTargetOrderById(ExcUnit, Order, SourceItem)
endfunction
06-01-2004, 06:20 AM#2
BBDino
I must say it sounds quite useful!
06-01-2004, 09:03 AM#3
35263526
The action is somewhat useful, but the event just isn't. Each item slot has an order code for things being moved to it, so you don't need a specific action. Just use the Unit uses an ability even.
06-01-2004, 11:00 PM#4
Vexorian
This was done before a lot in the past actually, check weaaddar's back pack, also a trigger can have a lot of events, did you know? you don't add the condition, you add a conditional boolexpr for the unitevent, uses natives instead of BJ fuctions

Edit: And this stuff HAS to go to the repository, moved