HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

UnitRemoveItem

07-12-2008, 09:32 AM#1
d07.RiV
I suppose it was already asked, but

If I call UnitRemoveItem or functions like that (e.g. UnitDropItem) in response to EVENT_PLAYER_UNIT_SELL_ITEM (remove the sold item) the unit will still get item bonuses.
I could work around that by inserting TriggerSleepAction but this way the item icon briefly appears in the inventory.
Is there any other way to do it?
07-12-2008, 09:41 AM#2
TEC_Ghost
You could make the shop sell dummy items, then when the items in the Hero's possession, run a check to see if they can use it, if they can, replace it with the real item, if not remove it and give an error message. :)
07-12-2008, 09:47 AM#3
DiscipleOfLife
My guess:
Expand JASS:
07-12-2008, 03:58 PM#4
d07.RiV
Yes theres the way with fake items but i was wondering if anything can be done without it ><

And DiscipleOfLife, why do it that way when this is much better:
Collapse JASS:
globals
  private unit array rem_u
  private item array rem_i
  private integer num_rem = 0
  private timer rem_t = CreateTimer ()
endglobals
function ItemRemoveTimer takes nothing returns nothing
  local integer i = 0
  loop
    exitwhen i >= num_rem
    call UnitRemoveItem (rem_u[i], rem_i[i])
    set rem_u[i] = null
    set rem_i[i] = null
    set i = i + 1
  endloop
  set num_rem = 0
endfunction
function UnitRemoveItemEx takes unit u, item it returns nothing
  set rem_u[num_rem] = u
  set rem_i[num_rem] = it
  set num_rem = num_rem + 1
  if num_rem == 1 then
    call TimerStart (rem_t, .0, false, function ItemRemoveTimer)
  endif
endfunction
But that would still create a flashing item (just like in your example).
07-12-2008, 05:21 PM#5
Troll-Brain
Instead of using the EVENT_PLAYER_UNIT_SELL_ITEM check the orders maybe ?
07-12-2008, 07:56 PM#6
DiscipleOfLife
Quote:
Originally Posted by d07.RiV
And DiscipleOfLife, why do it that way when this is much better:

Because it doesn't look like crap, it is only mildly worse and it was only ment to show you how damn easy it is to solve your TriggerSleepAction(0) problem.


btw did you actually try and see if the item flashes or did you just guess?
I have used this exact method to handle items, but haven't seen any flashing myself, but then again I haven't used them at the sell event.
07-12-2008, 08:12 PM#7
d07.RiV
I didn't mean TriggerSleepAction, I meant any way of pausing execution until next frame.
I put triggersleepaction in to see if it works and it did, but the items did flash.

I did need to handle sell and pickup events separately because on pickup event, you make the unit drop that item. On sell you remove the item and give the gold back.

I don't trust in cancelling orders because thats theoretically possible to bypass (pretty sure thats possible, by spamming orders or if you have lag, or shift key or whatever).
07-12-2008, 08:34 PM#8
Troll-Brain
Quote:
I don't trust in cancelling orders because thats theoretically possible to bypass (pretty sure thats possible, by spamming orders or if you have lag, or shift key or whatever).
Anyway i tested, the buying unit don't get an order and the shop get an immediate order, so ...