Item rot

Level 2
Joined
Aug 9, 2015
Messages
18
Phew, I'm dealing with a tough issue atm. So far I managed to tackle all my triggering dead ends myself but this one is really giving me a hard time.

So there is an item called meat. When meat is created it gets assigned a custom value and every second this custom value is reduced by 1. Once it reaches zero, the meat disappears.

I have units with a 1 slot unit inventory that can pick this item up, also ships with a 6 slot hero inventory, that can do the same. Ships have a hero inventory, since they hunt big fish on the ocean and just making the meat drop on open water doesn't really work so it has to be added to the killing unit directly which apparently only works with hero inventories *sigh*

While meat is in a units inventory (either regular troops or ships) it won't be detected by my trigger that causes the custom value subtraction / removal of items with custom value = 0

How the fudge do I make my item loose custom value / get removed while being carried?

  • Item decay time
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Owner of (Triggering unit)) Equal to Neutral Passive
    • Actions
      • Set Temp_Point = (Position of (Triggering unit))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Or - Any (Conditions) are true
            • Conditions
              • (Unit-type of (Triggering unit)) Equal to Stag
              • (Unit-type of (Triggering unit)) Equal to Seal
              • (Unit-type of (Triggering unit)) Equal to Pig
        • Then - Actions
          • Item - Create Meat at Temp_Point
          • Item - Set the custom value of (Last created item) to 60
          • Item - Create Meat at Temp_Point
          • Item - Set the custom value of (Last created item) to 60
          • Item - Create Meat at Temp_Point
          • Item - Set the custom value of (Last created item) to 60
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • And - All (Conditions) are true
                • Conditions
                  • (Unit-type of (Triggering unit)) Equal to Northern Bullhead
                  • (Unit-type of (Killing unit)) Equal to Whaling Ship
            • Then - Actions
              • Hero - Create Meat and give it to (Killing unit)
              • Item - Set the custom value of (Last created item) to 60
            • Else - Actions
              • Item - Create Meat at Temp_Point
              • Item - Set the custom value of (Last created item) to 60
      • Custom script: call RemoveLocation (udg_Temp_Point)
  • Item decay time 2
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Item - Pick every item in (Playable map area) and do (Actions)
        • Loop - Actions
          • Item - Set the custom value of (Picked item) to ((Custom value of (Picked item)) - 1)
  • Item decay time 3
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Item - Pick every item in (Playable map area) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Custom value of (Picked item)) Equal to 0
            • Then - Actions
              • Item - Remove (Picked item)
            • Else - Actions
Posting this here made me realize that I can combine the second and third one pretty easily...
If you guys can't help me out at least I got that much out of the experience xD
 
Level 11
Joined
Jun 2, 2004
Messages
849
The Pick Every Item in Blah action only detects items within the region... and held items aren't considered within that region.

You'll probably need to store a reference to each meat item when you create it, either in a hashtable or an array (since there's no Item Group type). Wc3's generic collections aren't suited for this type of problem unfortunately, so you'll likely have to keep track of how many meats exist too, along with sorting new ones into empty slots and the like.
 
Level 10
Joined
Jan 25, 2017
Messages
213
Ships have a heroinventory, since they hunt big fish on the ocean and just making the meat drop on open water doesn't really work so it has to be added to the killing unit directly which apparently only works with hero inventories *sigh*

... wait really? That's not the case in my maps- I give items to units with unit inventories all the time. [Hero- create item and give to (triggering unit)]
 
Level 17
Joined
Nov 21, 2012
Messages
834
Item Timed Life mini-system
code
JASS:
// ----------------------------------------------------------------
// Item Timed Life by ZibiTheWand3r3r
// ----------------------------------------------------------------
// text size=10, visible for owner of unit
//use visibleForPlayer = null to make text visible for all
// ----------------------------------------------------------------
function CreateTextOnXY takes string s, real x, real y, player visibleForPlayer returns nothing
    set bj_lastCreatedTextTag = CreateTextTag()
    call SetTextTagText(bj_lastCreatedTextTag, s, 0.023)  //size 10
    call SetTextTagPos(bj_lastCreatedTextTag, x, y, 30.00) // 2
    call SetTextTagColor(bj_lastCreatedTextTag, 255, 255, 255, 255) // 3
    //for speed 64, for angle 90: 
    call SetTextTagVelocity(bj_lastCreatedTextTag, 0.00, 0.0355)
    call SetTextTagPermanent(bj_lastCreatedTextTag, false)
    call SetTextTagLifespan(bj_lastCreatedTextTag, 3.00)
    call SetTextTagFadepoint(bj_lastCreatedTextTag, 1.50)
    if visibleForPlayer != null then
        call SetTextTagVisibility(bj_lastCreatedTextTag, (GetLocalPlayer() == visibleForPlayer))
    endif
endfunction
// ----------------------------------------------------------------
// ----------------------------------------------------------------
function ITL_Loop takes nothing returns nothing
    local integer modulus
    local integer id=1
    loop
        exitwhen id>udg_ITL_count
        //-------------------------
        set udg_ITL_dur[id] = udg_ITL_dur[id] - 1.00
        //floating text
        set modulus = R2I(udg_ITL_dur[id]) - ((R2I(udg_ITL_dur[id])/5)*5)
        if modulus==0 and udg_ITL_dur[id]>0.00 and GetWidgetLife(udg_ITL_i[id])>0.405 and (not IsItemOwned(udg_ITL_i[id])) then
            call CreateTextOnXY(I2S(R2I(udg_ITL_dur[id])), GetItemX(udg_ITL_i[id]), GetItemY(udg_ITL_i[id]), null)
        endif
        //floating text end
        //        call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "item (" + I2S(id) + ") duration: " + R2S(udg_ITL_dur[id]))
        if udg_ITL_dur[id] <= 0.00 then
            if GetWidgetLife(udg_ITL_i[id])>0.405 then
                call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "Item " + GetItemName(udg_ITL_i[id]) + " expired.")
            endif
            call SetWidgetLife(udg_ITL_i[id], 0.00)
            set udg_ITL_i[id] = udg_ITL_i[udg_ITL_count]
            set udg_ITL_dur[id] = udg_ITL_dur[udg_ITL_count]
                
            set udg_ITL_count = udg_ITL_count - 1
            set id = id - 1
            if udg_ITL_count==0 then
                call PauseTimer(udg_ITL_timer)
            endif
        endif
        //-------------------------
        set id=id+1
    endloop    
endfunction
//---------------------------------------------------------------
//---------------------------------------------------------------
function ItemApplyTimedLife takes item itm, real time returns nothing
    if itm != null and (GetWidgetLife(itm) > 0.405) then
        set udg_ITL_count = udg_ITL_count + 1
        set udg_ITL_i[udg_ITL_count] = itm
        set udg_ITL_dur[udg_ITL_count] = time
        if udg_ITL_count==1 then
            call TimerStart(udg_ITL_timer, 1.00, true, function ITL_Loop)
        endif
        call CreateTextOnXY(I2S(R2I(time)) + " sec.", GetItemX(itm), GetItemY(itm), null)
    endif
endfunction
//---------------------------------------------------------------
function Trig_ITL_Actions takes nothing returns nothing
    call ItemApplyTimedLife(udg_ITL_ITEM, udg_ITL_DURATION)
endfunction
//===========================================================================
function InitTrig_ITL takes nothing returns nothing
    set gg_trg_ITL = CreateTrigger(  )
    call TriggerAddAction( gg_trg_ITL, function Trig_ITL_Actions )
endfunction

use:
  • dies
    • Events
      • Unit - A unit Dies
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Triggering unit)) Equal to Footman
        • Then - Actions
          • Item - Create Cheese at (Position of (Triggering unit))
          • Set ITL_ITEM = (Last created item)
          • Set ITL_DURATION = 14.00
          • Trigger - Run ITL <gen> (ignoring conditions)
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Triggering unit)) Equal to Rifleman
            • Then - Actions
              • Item - Create Urn of King Terenas at (Position of (Triggering unit))
              • Set ITL_ITEM = (Last created item)
              • Set ITL_DURATION = 22.00
              • Trigger - Run ITL <gen> (ignoring conditions)
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Unit-type of (Triggering unit)) Equal to Peasant
                • Then - Actions
                  • Item - Create Rusty Mining Pick at (Position of (Triggering unit))
                  • Set ITL_ITEM = (Last created item)
                  • Set ITL_DURATION = 30.00
                  • Trigger - Run ITL <gen> (ignoring conditions)
                • Else - Actions
 

Attachments

  • ItemTimedLife.w3x
    20.8 KB · Views: 28
Top