Exclude dropped item from counting function

LurkerAspect

Now officially a Super Lurker
Reaction score
118
XXXX==--SOLVED--==XXXX

Hi again all :D I'm becoming a main source of rep for some of you :D

Anyway, my problem today is that I'm running a function every time a unit drops an item, however the function that follows it almost immediately is still counting the item the unit just dropped, which is messing with my other systems. Any tips on how to fix this?
Here's the code:
JASS:
private function ElementalTally takes unit u returns integer //this is the function that gets run immediately from the actions; this is the function that is counting the dropped item
    local integer i = 1
    local boolean has_air = false
    local boolean has_dark = false
    local boolean has_earth = false
    local boolean has_fire = false
    local boolean has_light = false
    local boolean has_water = false
    local integer tally = 0
    loop
        exitwhen i > 6 
        if GetItemTypeId(UnitItemInSlot(u,i)) == AIR_ITEM and has_air == false then
            set has_air = true
            set tally = tally+32
        elseif GetItemTypeId(UnitItemInSlot(u,i)) == DARK_ITEM and has_dark == false then
            set has_dark = true
            set tally = tally+16
        elseif GetItemTypeId(UnitItemInSlot(u,i)) == EARTH_ITEM and has_earth == false then
            set has_earth = true
            set tally = tally+8
        elseif GetItemTypeId(UnitItemInSlot(u,i)) == FIRE_ITEM and has_fire == false then
            set has_fire = true
            set tally = tally+4
        elseif GetItemTypeId(UnitItemInSlot(u,i)) == LIGHT_ITEM and has_light == false then
            set has_light = true
            set tally = tally+2
        elseif GetItemTypeId(UnitItemInSlot(u,i)) == WATER_ITEM and has_water == false then
            set has_water = true
            set tally = tally+1
        endif
        set i = i+1
    endloop
    return tally
endfunction

//bla bla bla

private function Actions2 takes nothing returns nothing
    local unit u = GetTriggerUnit()
    call RemoveElementalPowers(u)
    call UnitAddAbility(u,ELEMENTAL_ABILITY[ElementalTally(u)])
    set u = null
endfunction

private function Conditions1 takes nothing returns boolean
    return GetUnitTypeId(GetTriggerUnit()) == 'h000' and not UnitHasItemAlready(GetTriggerUnit(),GetManipulatedItem()) and IsItemElemental(GetManipulatedItem())
endfunction

Don't worry about the other undefined functions and global variables, they don't affect the performance of the main tally function.

Any help is much appreciated :D
 

Tyrulan

Ultra Cool Member
Reaction score
37
It sounds like when an item is dropped it is still considered as 'Manipulated' and in the inventory. I would add a parameter to your tally function and do a not equals comparison to exclude it.

Let me know if this helps you with your problem. If not, I'll investigate further.

EDIT: Apologies, did not read the SOLVED tag at the front of the post. Could you post the solution please? Intellectual curiosity.
 

LurkerAspect

Now officially a Super Lurker
Reaction score
118
I modified the functions; ElementalTally now takes an item as well as a unit argument, and then checks if the current item in slot is the given item, and if it is, it's not counted. That way, I just input the GetManipulatedItem(), and it works perfectly :). It was fairly simple actually. Basically, the function looks like this now:
JASS:
function GetElementalTally takes unit u, item exception returns integer
    //exception is the item you DON'T want added to tally
    //use with 'Drop' functions so that the dropped element doesn't get counted
    local integer i = 0
    local boolean has_air = false
    local boolean has_dark = false
    local boolean has_earth = false
    local boolean has_fire = false
    local boolean has_light = false
    local boolean has_water = false
    local integer tally = 0
    set tally = 0
    loop
        exitwhen i > 6 
        if UnitItemInSlot(u,i) != exception then
            if GetItemTypeId(UnitItemInSlot(u,i)) == AIR_ITEM and has_air == false then
                set has_air = true
                set tally = tally+32
            elseif GetItemTypeId(UnitItemInSlot(u,i)) == DARK_ITEM and has_dark == false then
                set has_dark = true
                set tally = tally+16
            elseif GetItemTypeId(UnitItemInSlot(u,i)) == EARTH_ITEM and has_earth == false then
                set has_earth = true
                set tally = tally+8
            elseif GetItemTypeId(UnitItemInSlot(u,i)) == FIRE_ITEM and has_fire == false then
                set has_fire = true
                set tally = tally+4
            elseif GetItemTypeId(UnitItemInSlot(u,i)) == LIGHT_ITEM and has_light == false then
                set has_light = true
                set tally = tally+2
            elseif GetItemTypeId(UnitItemInSlot(u,i)) == WATER_ITEM and has_water == false then
                set has_water = true
                set tally = tally+1
            endif
        endif
        set i = i+1
    endloop
    //call BJDebugMsg("tally = "+I2S(tally))
    return tally
endfunction
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top