HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Detecting Non-existing Items in Rects?

06-14-2006, 07:44 PM#1
Ignitedstar
Is there a way to detect an item that is inside a rect? I wanted try something new with recipes. Where, the recipe item is put inside of a unit. This unit has an ability called "Upgrade", which checks to see if the correct items are within the rects around the unit with the correct item. If they are, the unit upgrades the item, "using" what's inside the rects.

The trigger is suppose to look like this. But the problem is, I wasn't able to find an item condition that checks for a non-existant item. Without it, the trigger doesn't work at all.
Trigger:
Upgrading an Item(Rough Version)
Collapse Events
Unit - A unit starts the effect of an ability
Collapse Conditions
Ability being cast equal to Upgrade
Collapse And - All conditions are true
Item 1 exists in Rect 1
Item 2 exists in Rect 2
Item 3 exists in Rect 3
Comment - They are suppose to be something like (Potion of Health is in Rect 1)
Collapse Actions
Collapse Item - Pick every item in Rect 1 and do Actions
Remove (Picked Item) from the game
Collapse Item - Pick every item in Rect 2 and do Actions
Remove (Picked Item) from the game
Collapse Item - Pick every item in Rect 3 and do Actions
Remove (Picked Item) from the game
Item - Create (New Item) in Rect 4

Can someone help?

Oh, right. By non-existant item, I mean an item that never started on the map.

If I'm being clear enough, please say so. Thanks in advance.
06-15-2006, 05:41 AM#2
Naakaloh
Edit 2: I found your problem interesting, so I decided to make an example. I've attached a map; it should be pretty easy to figure out how to use.

Healing Potion + Healing Salve => Potion of Greater Healing
Ring of Prot. +1 + Jade Ring + Ancient Figurine => Ring of Prot. +2
Ring of Prot. +2 + Jade Ring + Ancient Figurine => Ring of Prot. +3

Item Upgrade Example.w3x

Anyone's free to use it, Have fun!

---------------

I don't have World Editor at the moment so I can't look up anything in the GUI for you, but I believe in JASS you would want to use.

Collapse JASS:
EnumItemsInRect( rect r, boolexpr filter, code actionFunc )

That gives you the you the ability to provide a condition and a function.

I've never worked with items much before and since there doesn't seem to be many options I can only guess at a solution and my solution is basically to make my own conditions. But off the top of my head, I would say that you could try something like the following, but before continuing keep in mind that I have no idea if this would work the way you want it to since I've never really messed with items before (Also, some names may be incorrectly notated since WE isn't readily available to me at the moment):

Stuff in [] brackets should be filled in with what you need it to be.

Collapse JASS:

function Upgrade_AbilityCondition takes nothing returns boolean
 return ( GetSpellAbilityId() == [Ability_Rawcode]
endfunction

function Upgrade_Condition_Item1 takes nothing returns boolean
 return ( GetItemTypeId( FilterItem()) == [Item1_Rawcode] )
endfunction 

function Upgrade_SetFirstItem takes nothing returns nothing
   set udg_1stItem = EnumItem()
endfunction

// You would have duplicates of the above functions for howevermany items you need for your upgrade and a Global item variable for up to as many items as you plan to use.

function Upgrade_CheckForItemsInRectAndUpgrade takes rect r returns nothing
 call EnumItemsInRect( r, Condition( function Upgrade_Condition_Item1 ), function Upgrade_SetFirstItem )
// You would have other calls here for whatever items you would 
// need just change which item you check for in the condition and
// which global item you'd set if it finds an item.  Basically what it will 
// do is it will set up a group of items if they are of the type you're
// looking for.  Then, if the group contains at least one item, the value
// of one item of the appropriate type will be assigned to the global.

// After doing that all you have to do is check that the the globals are not null.

 if( udg_1stItem != null ) then   // If you wanted more items you'd just use: and udg_2ndItem != null and (etc.)
   call RemoveItem( udg_1stItem )
   call CreateItem( [UpgradedItemRawcode], [NewItemXPos], [NewItemYPos] )
 endif

 set udg_1stItem = null // Be sure to set them to null afterward so that they don't accidentally get used when they aren't in the rect.
endfunction

function Trig_Upgrade_Actions takes nothing returns nothing
 local rect r = [CreateTheRectHere]

 call Upgrade_CheckForItemsInRectAndUpgrade( r )
 call RemoveRect( r )

 set r = null
endfunction

function Init_Trig_Upgrade takes nothing returns nothing
 set gg_trg_Upgrade = CreateTrigger()
 call TriggerAddAction( gg_trg_Upgrade, function Trig_Upgrade_Actions )
 call TriggerAddCondition( gg_trg_Upgrade, Condition( function Upgrade_AbilityCondition ) )
 call TriggerRegisterAnyUnitEventBJ( gg_trg_Upgrade, EVENT_PLAYER_UNIT_SPELL_EFFECT )
endfunction

Edit: Instead of calling them 'non-existant' items, call them 'non-preplaced' items or something like that, since they would certainly exist, just not before the game is actually run.
Attached Files
File type: w3xItem Upgrade Example.w3x (20.4 KB)
06-16-2006, 12:48 AM#3
Ignitedstar
Thanks, Neekaloh, even though I don't really understand JASS. It's okay, I'll learn how use JASS to in the near future(hopefully).