help with auto-item transfer trigger.

afisakov

You can change this now in User CP.
Reaction score
37
I am trying to make a trigger that automatically transfers items from the buying unit to a designated recipient.
The idea is to have a central box players buy to store newly bought items and use recipies. Then is summons mini-boxes to extend its buying range. Whenever a mini-box buys an item it then automatically gives that item to the main box. The main box has an ability to give items to ur hero when u want it to.

Progress... item give range set to 9999 under global constants.
Created box and mini-box. Box has ability tat successfully gives items to hero, and is capable of summoning mini-boxes.
miniboxes buy items but do NOT transfer them to the box like they should.

my trigger for transfer
Code:
trigger trg_transitem=null
...
function isbox takes nothing returns boolean
    return GetUnitTypeId(GetFilterUnit())=='n02C' and GetOwningPlayer(GetFilterUnit())==GetOwningPlayer(GetBuyingUnit())
endfunction
function Trig_transitem_Conditions takes nothing returns boolean
    return GetUnitTypeId((GetBuyingUnit()))=='h02D'
endfunction     
function Trig_transitem_Actions takes nothing returns nothing
    local unit u
    set tg=GetUnitsInRectMatching(GetPlayableMapRect(),Condition(function isbox))
    set u=FirstOfGroup(tg)
    call UnitDropItemTargetBJ(GetBuyingUnit(),GetManipulatedItem(),u)
    call DestroyGroup(tg)
    set u=null
endfunction
...
    set trg_transitem=CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(trg_transitem,EVENT_PLAYER_UNIT_SELL_ITEM)
call TriggerAddCondition(trg_transitem,Condition(function Trig_transitem_Conditions))
call TriggerAddAction(trg_transitem,function Trig_transitem_Actions)
fyi: n02C is the box and n02D is the mini-box

my transfer from box to hero trigger, in case anyone is curious, tested and works
Code:
trigger trg_minibox=null
...
function buildings takes nothing returns boolean
    return IsUnitAliveBJ(GetFilterUnit()) and IsUnitType(GetFilterUnit(),UNIT_TYPE_STRUCTURE) and GetOwningPlayer(GetFilterUnit())==GetOwningPlayer(GetTriggerUnit())
endfunction
function Trig_minibox_Conditions takes nothing returns boolean
    return (GetSpellAbilityId()=='A0QV')
endfunction
function Trig_minibox_Actions takes nothing returns nothing
    local player p=GetOwningPlayer(GetTriggerUnit())
    set tg=GetUnitsInRectMatching(GetPlayableMapRect(),Condition(function buildings))
    set fint1=CountUnitsInGroup(tg)*100
if GetPlayerState(p,PLAYER_STATE_RESOURCE_GOLD)>fint1 then
    call AdjustPlayerStateBJ(-fint1,p,PLAYER_STATE_RESOURCE_GOLD)
    set tp1=GetSpellTargetLoc()
    call CreateNUnitsAtLoc(1,'n02D',p,tp1,270)
    call RemoveLocation(tp1)
else
    call DisplayTimedTextToGamers(5,"building a mini box requires "+I2S(fint1)+" gold")
endif
    call DestroyGroup(tg)
    set p=null
endfunction
...
    set trg_minibox=CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(trg_minibox,EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(trg_minibox,Condition(function Trig_minibox_Conditions))
call TriggerAddAction(trg_minibox,function Trig_minibox_Actions)

I am hoping someone can tell me why my transfer trigger doesn't work or suggest a way to fix it / better way of doing it. Thanks in advance for the help.
 

dracolich

TH.net Regular
Reaction score
15
use trigger for picking up items, not for selling.
cant say actual reasons, cause i used only unit-based item selling.

Probably there are something wrong with returned values of ManipulatedItem(), cause, actually, its related to the item event, not player event
 

Wardonis

Cool Member
Reaction score
0
perhaps you can set a trigger to immediately drop the item last bought, set last dropped item to a variable. move the item to unit position and then order unit to pick it up.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top