wc3campaigns
WC3C Homepage - www.wc3c.netUser Control Panel (Requires Log-In)Engage in discussions with other users and join contests in the WC3C forums!Read one of our many tutorials, ranging in difficulty from beginner to advanced!Show off your artistic talents in the WC3C Gallery!Download quality models, textures, spells (vJASS/JASS), systems, and scripts!Download maps that have passed through our rigorous approval process!

Go Back   Wc3C.net > Resources > Code Resources > Scripts
User Name
Password
Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar



Reply
 
Thread Tools Search this Thread
Old 12-02-2009, 12:44 AM   #1
grim001
requires vJass
 
grim001's Avatar


Code Moderator
 
Join Date: Nov 2006
Posts: 1,540

Submissions (10)

grim001 is just really nice (277)grim001 is just really nice (277)

Send a message via AIM to grim001
Default ItemUtils

Requires Itemdex, ItemHolder, xebasic

This library was created as a collection of useful item handling functions and events. It contains several functions that should have already been natives or BJs, along with events to abstract away the annoying steps involved in detecting item dragging, trading, and usage. ItemUtils uses the values 0-5 to represent inventory slots and -1 for no slot.

Expand JASS:

Last edited by grim001 : 02-01-2010 at 12:18 PM.
grim001 is offline   Reply With Quote
Sponsored Links - Login to hide this ad!
Old 12-02-2009, 06:44 PM   #2
Rising_Dusk
Obscurity, the Art


Projects Director
Project Leader: OD
 
Join Date: Feb 2006
Posts: 9,729

Submissions (27)

Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)

Hero Contest #3 - 1st PlaceApproved Map: Desert of ExileApproved Map: Advent of the ZenithHero Contest #2 - 1st PlaceHero Contest - Third place>

Send a message via AIM to Rising_Dusk Send a message via MSN to Rising_Dusk
Default

I very much support this being one library with the events instead of two.
Collapse JASS:
// OnUnitPickupItem(ItemFunc)
//   Runs the specified ItemFunc when a unit picks up a powerup item.
//
// OnUnitPickupItem(ItemFunc)
//   Runs the specified ItemFunc when a unit picks up an item.
These two can probably be merged in the documentation.
__________________
Rising_Dusk is offline   Reply With Quote
Old 12-02-2009, 07:03 PM   #3
grim001
requires vJass
 
grim001's Avatar


Code Moderator
 
Join Date: Nov 2006
Posts: 1,540

Submissions (10)

grim001 is just really nice (277)grim001 is just really nice (277)

Send a message via AIM to grim001
Default

That was a typo which I just fixed. The first one was supposed to be "OnUnitPickupPowerup."
grim001 is offline   Reply With Quote
Old 12-03-2009, 09:03 PM   #4
Anitarf
Procrastination Incarnate


Development Director
 
Join Date: Feb 2004
Posts: 8,190

Submissions (19)

Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)

2008 Spell olympics - Fire - SilverApproved Map: Old School Alliance TacticsHero Contest #2 - 3rd PlaceSpell making session 2 winner

Default

I had a comment here about private triggers being declared in the calibration section, but I see now the calibration section was meant to end before that point, maybe that should be marked more clearly.

UnitGetRandomItem "leaks" items (if they are ever removed, their handle id will not get recycled), you should use a global item array or a local integer array that stores full item slots instead of items directly, which would also save on UnitItemInSlot calls for all that's worth.

What does UnitInventorySize return for null units? If 0, then most functions like UnitGetItemOfTypeSlot don't require the safety u==null check since they'll just skip their loop anyway.

Could the UnitSwapInventorySlots function be improved with a more low-level approach? Right now it does the whole UnitPickupItemToSlot procedure twice if there are two items, woldn't it be simpler to just fill the inventory up to the higher of the two slots with dummy items once, then drop the items in the two slots (whether they're both actual items or one of them is a dummy item doesn't matter), pick them up in reverse order, remove all dummy items from the unit, then run the events for the items in the slots in the end? Right now, when the drag event occurs for the first item, the second one isn't even in the unit's inventory yet when it probably should be.

The documentation for UnitAddItemToSlot is slightly ambigous, I actually understood it the wrong way the first time I read it. I suggest the following clarification:
// Adds the specified item to the specified slot of the specified
// unit. If an item is already in the specified slot, itthat item will be moved
// to the first free slot, or dropped if the inventory is full.


If ItemDex throws out bug messages when encountering something as normal as an item with charges, that should probably be fixed in ItemDex rather than requireing fixes in ItemUtils.

That's all I've got for now, looking good otherwise.
__________________
Anitarf is offline   Reply With Quote
Old 12-04-2009, 05:41 PM   #5
grim001
requires vJass
 
grim001's Avatar


Code Moderator
 
Join Date: Nov 2006
Posts: 1,540

Submissions (10)

grim001 is just really nice (277)grim001 is just really nice (277)

Send a message via AIM to grim001
Default

Quote:
Originally Posted by Anitarf
UnitGetRandomItem "leaks" items
Fixed.

Quote:
Originally Posted by Anitarf
most functions like UnitGetItemOfTypeSlot don't require the safety u==null check since they'll just skip their loop anyway.
Fixed.

Quote:
Originally Posted by Anitarf
Could the UnitSwapInventorySlots function be improved with a more low-level approach?
Fixed.

Quote:
Originally Posted by Anitarf
The documentation for UnitAddItemToSlot is slightly ambigous
Fixed.

Quote:
Originally Posted by Anitarf
If ItemDex throws out bug messages when encountering something as normal as an item with charges, that should probably be fixed in ItemDex rather than requireing fixes in ItemUtils.
Vex has been ignoring all his system threads lately. Maybe he will revive someday. But for now, it works fine.
grim001 is offline   Reply With Quote
Old 01-01-2010, 04:08 AM   #6
Sinnergy
User
 
Sinnergy's Avatar
 
Join Date: Apr 2009
Posts: 173

Sinnergy has little to show at this moment (8)

Default

very nice, I'll just wait for the approval, I'm just confused on some stuffs in the readme inside the script
Quote:
By the way, please don't kill any items in your maps
did you mean by triggering only? or any attempts of killing an item (unit is ordered to attack an item; a user orders his/her hero to kill an item)?

UnitGetItemOfOfType , double "of" (itemOfOf)?

Collapse JASS:
// OnUnitPickupItem(ItemFunc)
//   Runs the specified ItemFunc when a unit picks up a powerup item.
//
// OnUnitPickupItem(ItemFunc)
//   Runs the specified ItemFunc when a unit picks up an item.
The same function names?
__________________
Current Project:
Rise of Sinnergy v1.00

Last edited by Sinnergy : 01-01-2010 at 04:09 AM.
Sinnergy is offline   Reply With Quote
Old 01-01-2010, 12:51 PM   #7
Rising_Dusk
Obscurity, the Art


Projects Director
Project Leader: OD
 
Join Date: Feb 2006
Posts: 9,729

Submissions (27)

Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)

Hero Contest #3 - 1st PlaceApproved Map: Desert of ExileApproved Map: Advent of the ZenithHero Contest #2 - 1st PlaceHero Contest - Third place>

Send a message via AIM to Rising_Dusk Send a message via MSN to Rising_Dusk
Default

The first one is supposed to be "OnUnitPickupPowerup" and it's a typo in the documentation he apparently hasn't fixed.
__________________
Rising_Dusk is offline   Reply With Quote
Old 01-01-2010, 09:40 PM   #8
grim001
requires vJass
 
grim001's Avatar


Code Moderator
 
Join Date: Nov 2006
Posts: 1,540

Submissions (10)

grim001 is just really nice (277)grim001 is just really nice (277)

Send a message via AIM to grim001
Default

I thought I fixed that... OK, I'm going to update this sometime tonight.

Quote:
Originally Posted by Sinnergy
did you mean by triggering only?
Yes, I added something to the documentation to clarify that.

Quote:
Originally Posted by Sinnergy
double "of"
Fixed.

Quote:
Originally Posted by Sinnergy
The same function names?
Fixed.

OK, this thing should be ready for final review now.

Last edited by grim001 : 01-01-2010 at 11:20 PM.
grim001 is offline   Reply With Quote
Old 01-24-2010, 09:45 PM   #9
Anitarf
Procrastination Incarnate


Development Director
 
Join Date: Feb 2004
Posts: 8,190

Submissions (19)

Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)

2008 Spell olympics - Fire - SilverApproved Map: Old School Alliance TacticsHero Contest #2 - 3rd PlaceSpell making session 2 winner

Default

GetItemSlot seems to only return -1 for an item on the ground if that item has been picked up and dropped once, otherwise it returns 0. GetItemPrevSlot also returns 0 for items that have not yet been picked up.
__________________
Anitarf is offline   Reply With Quote
Old 01-25-2010, 09:04 AM   #10
Anachron
User
 
Anachron's Avatar
 
Join Date: Mar 2009
Posts: 1,079

Anachron will become famous soon enough (51)Anachron will become famous soon enough (51)

Default

I've made something similar for my current inventory system.
However, its not released to public yet and features the same functionality with fullscreeninventories aswell.

What I miss is some (optional) bridge to UnitMaxState and BonusMod.
__________________
CustomInventory [Discussion - Download] - Got Directors Cut!
CustomMissle [Discussion - [Download (not yet)] - In development!
Other systems [Spawn System] [Move System] [CustomBar] [SpellBar]
Anachron is offline   Reply With Quote
Old 02-01-2010, 12:20 PM   #11
grim001
requires vJass
 
grim001's Avatar


Code Moderator
 
Join Date: Nov 2006
Posts: 1,540

Submissions (10)

grim001 is just really nice (277)grim001 is just really nice (277)

Send a message via AIM to grim001
Default

Quote:
Originally Posted by Anitarf
GetItemSlot seems to only return -1 for an item on the ground if that item has been picked up and dropped once, otherwise it returns 0. GetItemPrevSlot also returns 0 for items that have not yet been picked up.
Fixed it.

Quote:
Originally Posted by Anachron
What I miss is some (optional) bridge to UnitMaxState and BonusMod.
Your idea of what this library is supposed to do is confused if you think it needs that stuff.

Once again, should be ready for someone to look it over and approve it if no issues are found.
grim001 is offline   Reply With Quote
Old 02-01-2010, 12:42 PM   #12
Anitarf
Procrastination Incarnate


Development Director
 
Join Date: Feb 2004
Posts: 8,190

Submissions (19)

Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)

2008 Spell olympics - Fire - SilverApproved Map: Old School Alliance TacticsHero Contest #2 - 3rd PlaceSpell making session 2 winner

Default

Approved.
__________________
Anitarf is offline   Reply With Quote
Old 04-04-2011, 04:59 AM   #13
SanKakU
User
 
Join Date: Jan 2009
Posts: 136

SanKakU has a little shameless behaviour in the past (-2)

Send a message via AIM to SanKakU Send a message via MSN to SanKakU Send a message via Yahoo to SanKakU
Default

i guess it might be useful...but can't you make some of the used libraries optional? i don't know what hiding items is for...

Last edited by SanKakU : 04-04-2011 at 05:01 AM.
SanKakU is offline   Reply With Quote
Old 09-20-2011, 05:04 PM   #14
Anitarf
Procrastination Incarnate


Development Director
 
Join Date: Feb 2004
Posts: 8,190

Submissions (19)

Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)

2008 Spell olympics - Fire - SilverApproved Map: Old School Alliance TacticsHero Contest #2 - 3rd PlaceSpell making session 2 winner

Default

I have a minor bug to report. The bug occurs when swapping items if the dragged item is removed in one of the event responses. Removing the dragged item cancels the swap, which means that the draggedto item remains where it was while ItemUtils thinks it is in a different slot now. This causes all sorts of errors in future drag events and elsewhere.

Until this is fixed, users shouldn't remove the dragged item in any OnUnitDragItem and OnUnitSwapItems event responses. Removing the draggedto item is safe, though, since that doesn't appear to cancel the item swap.


Edit:

The same error also occurs if a new item is put into an empty slot to which an item is being dragged. The bug also occurs if the dragged item is dropped from the inventory, not only if it's removed.

Another issue I noticed is that ItemUtils ignores drag events where the item is dropped onto itself, however detecting these events could be useful for some things like item stack splitting. Either drag events should run even when an item is dragged to the same slot or a separate event should be provided for such occasions.


Edit 2:

There is a bug in the event handling code:
Expand JASS:
If you're looping backwards, then the initial value of n should be $NAME$funcs_n. However, ideally the functions should be run in the order they were registered, so I think that this is a better correction:
Expand JASS:

Another small thing: In the OnDropItem function, perhaps the ClearItemOwnerDelayed should be called before running the events. The reason I mention this is that I use 0.0 timers on that event too (to find out where the dropped item ended up) and right now those timers expire before the ClearItemOwnerDelayed timer does, which means the item owner is not yet properly reset. Right now, when my timer expires, I have to compare the item's owner to the dropping unit rather than to null to establish that the item was dropped to the ground, which is a bit counter-intuitive. That also means that if another event function were to give the item back to the dropping unit, I'd have no way of knowing that.

This might remain a problem even if ClearItemOwnerDelayed is called before the event functions: I see nothing in the code that would ensure that if a unit reacquires an item it just dropped, the ClearItemOwnerDelayed_Sub function won't reset that item's owner anyway. The OnPickupItem function likely needs to be modified to account for that possibility.
__________________

Last edited by Anitarf : 10-06-2011 at 01:13 PM.
Anitarf is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT. The time now is 10:54 PM.


Affiliates
The Hubb The JASS Vault Clan WEnW Campaign Creations Clan CBS GamesModding Flixreel Videos

Powered by vBulletin (Copyright ©2000 - 2019, Jelsoft Enterprises Ltd).
Hosted by www.OICcam.com
IT Support and Services provided by Executive IT Services