• 🏆 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!

Moving Item From Slot X To Slot Y

Status
Not open for further replies.
Level 33
Joined
Mar 27, 2008
Messages
8,035
The title says it all, how do I move items in inventory of a unit from Slot 1 to Slot 2 via triggers ?

EDIT:
Got it, it's under Issue Move Item In Inventory Order

EDIT 2:
Is there any Event that is able to detect when Player is switching item from Slot X to Slot Y ?
Like an Event detects Player 1 switching this item from Slot 3 to Slot 6.
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
also it is regular event Unit is issued an order with no target I believe with those Ids
  • Untitled Trigger 001
    • Events
      • Unit - A unit Is issued an order with no target
    • Conditions
    • Actions
      • Custom script: local integer i = GetIssuedOrderId()
      • Custom script: call BJDebugMsg(I2S(i))
This doesn't work (no integer is catched when I move Item from Slot X to Slot Y)
 
Level 9
Joined
Jul 10, 2011
Messages
562
if you wanna restrict the players to move an item from one slot to another just CnP the follwing trigger in your map.

JASS:
scope SlotChangeRestriction

struct SlotChangeRestriction extends array
    implement Alloc
    private integer tempIndex
    private unit tempUnit
    private item tempItem
    
    private static trigger moveTrigger
    
    private static method moveCallback takes nothing returns nothing
        local thistype this=ReleaseTimer(GetExpiredTimer())
        call DisableTrigger(thistype.moveTrigger)
        call IssueTargetOrderById(this.tempUnit,this.tempIndex,this.tempItem)
        call EnableTrigger(thistype.moveTrigger)
        call this.deallocate()
    endmethod
    static method create takes unit triggerUnit,item triggerItem returns thistype
        local thistype this=thistype.allocate()
        local integer i=0
        set this.tempUnit=triggerUnit
        set this.tempItem=triggerItem
        loop
            if UnitItemInSlot(this.tempUnit,i)==this.tempItem then
                set this.tempIndex=i+852002
            endif
            set i=i+1
            exitwhen i==6
        endloop
        call TimerStart(NewTimerEx(this),.01,false,function thistype.moveCallback)
        return this
    endmethod
    private static method onMove takes nothing returns boolean
        if GetIssuedOrderId()>852001 and GetIssuedOrderId()<852008  then
            call thistype.create(GetTriggerUnit(),GetOrderTargetItem())
        endif
        return false
    endmethod
    private static method onInit takes nothing returns nothing
        set thistype.moveTrigger=CreateTrigger()
        call TriggerRegisterPlayerUnitEvent(thistype.moveTrigger,Player(0),EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER,null)
        call TriggerAddCondition(thistype.moveTrigger,Condition(function thistype.onMove))
    endmethod

endstruct

endscope

there i got the order ids from....


edit: oh i see my mistake....the ids are from 852002 to 852007.....sorry for that.
 
Status
Not open for further replies.
Top