HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

How do these Add/Drop Item functions work?

05-03-2007, 08:44 AM#1
Danat
Hi. I'm developing a program (in C#) that would simulate war3 engine behaviour and can execute Jass script. It already compiles jass script and executes it, but there are still some native functions that aren't implemented and are bypassed by my engine.
What I need to know is how do these functions work:
  • UnitAddItem
  • UnitAddItemById
  • UnitAddItemToSlotById
  • UnitDropItemSlot
  • UnitDropItemTarget
  • UnitDropItemPoint

A detailed reply would be appreciated, because, for example I don't understand how come this (copied from here):
Code:
function UnitAddItemToSlot takes unit hero, item it,integer slot returns boolean
   local boolean b=UnitAddItem(hero,it)
   local boolean c= UnitDropItemSlot(hero,it,slot)
   return (b and c)
endfunction
can add an item to the specified slot (as it says in description). For example if my hero has 6 empty slots in his inventory, then I thought UnitAddItemToSlot(hero,item,4) would add item to first available slot -> 1, and then drop item in slot 5 (which will do nothing in this case).
05-03-2007, 11:38 AM#2
Tide-Arc Ephemera
Quote:
Originally Posted by Danat
  • UnitAddItem
  • UnitAddItemById
  • UnitAddItemToSlotById
  • UnitDropItemSlot
  • UnitDropItemTarget
  • UnitDropItemPoint

A detailed reply would be appreciated, because, for example I don't understand how come this (copied from here):
Collapse JASS:
function UnitAddItemToSlot takes unit hero, item it,integer slot returns boolean
   local boolean b=UnitAddItem(hero,it)
   local boolean c= UnitDropItemSlot(hero,it,slot)
   return (b and c)
endfunction
can add an item to the specified slot (as it says in description). For example if my hero has 6 empty slots in his inventory, then I thought UnitAddItemToSlot(hero,item,4) would add item to first available slot -> 1, and then drop item in slot 5 (which will do nothing in this case).

Hey, I'm not the most JASSy person, but I'm guessing that AddItemToSlotById would work because of a simple clause... I don't know too much about JASS (I know enough to cut memory leaks out), but I'm hoping what I said will help.

I didn't fully understand that aswell, so um... do you mean like if it has 6 slots and it acquires an item, it will move to the lowest open slot?
05-03-2007, 11:53 AM#3
Danat
I haven't tested it myself but this code was referenced on this forum somewhere. I have just guessed that UnitAddItem adds item to the first available slot, which makes sense to me, BUT makes the code above senseless :). Anyway I can't think of a good explanation on how does it work. I think that any jass programmer that have used those functions in his code can tell me what exactly do they do and whether that code above is correct/incorrect (I would be glad to hear that UnitAddItemToSlot function does not work as stated in description)
05-03-2007, 12:01 PM#4
Tide-Arc Ephemera
Um... going slightly off topic (just like how this appears to meant to be in the trigger section), but I've been using GUI for a long, long, long, long, long, long, long, long long, long, long, long, long, long, long, long long, long, long, long, long, long, long, long long, long, long, long, long, long, long, long long, long, long, long, long, long, long, long long, long, long, long, long, long, long, long time. Any idea of how I can learn JASS without spending endless hours?

On topic. What exactly DO YOU WANT? You didn't quiet clarify that, so is what you want rather than going to the first slot of the inventory, to go to the last slot?

If so, you could always try making the hero drop the item, pick up a bucket load of dummy items, and then pick it up again so that it will be acquired in the last slot, but that's silly, well... I tried my best with blind stabs...
05-03-2007, 12:09 PM#5
Danat
1. Ok I'll create the same thread in trigger section (I have posted here since my previous question about InitGameCache in triggers section was moved to this forum).
EDIT: already moved there :)
2. You probably haven't read my 1-st post carefully:
Quote:
I'm developing a program (in C#) that would simulate war3 engine behaviour and can execute Jass script.
05-03-2007, 01:24 PM#6
Vexorian
Quote:
which will do nothing in this case

I don't get what made you rush into that conclusion .
05-03-2007, 01:54 PM#7
Danat
I made that conclusion because I thought that UnitDropItemSlot drops item from the specified slot. And if that slot is empty then no item is dropped.
I have asked this question (post #1) on the other forum and someone told me that UnitDropItemSlot simply moves item to the specified slot.
However I'm still not sure what will happen if the specified slot contains an item.