A System for Summoned Units' Inventories?

SanKakU

Member
Reaction score
21
we need to get certain summoned units with inventory to keep their inventory everytime they get summoned...

...if there were some way to treat them as heroes so that they keep their items, that would be great, but obviously you don't want them gaining experience and ripping off your hero from getting experience...right? i've seen a lot of threads in the various forums with someone asking how to do the dota syllabear spirit bear thing and no one really gives a solution...

it feels like it could add a lot of gameplay value to a map to have a system like what i'm describing, but apparently nobody's developed it yet...

it can't be impossible because i've seen it when playing dota, lots of people have. so how come nobody's released a system for it, yet? cuz i sure don't know how to do it, and plenty of other people don't either.

my map idea involves an Illidan kindof guy summons two Naga serpent chicks, and they each have 3 inventory slots...and a spellbreaker hero summons a blood elf lieutenant, and he has 6 inventory slots...

but i can't get any of that to work at all...items seem to be the ultimate in difficulty when it comes to coding, if you ask me...well, that and graphics is kinda hard too...but items should be so easy and they're not! it drives me crazy how hard i try with them only to fail...maybe i'm just testing what i'm coding inefficiently and that's why it takes forever to fail and fail and fail again...but...well, whatever. i can't figure it out. i refuse to waste time trying to figure it out anymore. got better things to do in my world editor than to fruitlessly slave away trying to figure this thing out...but i really need it figured out for me because the hero idea of a summoned unit carrying items is really great!
 

Narks

Vastly intelligent whale-like being from the stars
Reaction score
90
Illidan kindof guy summons two Naga serpent chicks
hawt


It should be really easy, though. When the units are summoned, just give them an inventory. When they are unsummoned, store the items they held in global variables. When they are resummoned, restore the items.
 

SanKakU

Member
Reaction score
21
it should be, but it isn't. if you think it's so easy, you can try to do it. if you succeed, then post a test map as proof. i have tried and tried and tried and i couldn't do it.
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
JASS:
scope SpiritBear initializer Init
    
    private struct Data
        unit bear
        unit cs
        item array items [6]
        integer itemsCount
        
        //! runtextmacro PUI()
    endstruct
    
    private struct bearData
        Data cs
        trigger trig
        
        //! runtextmacro PUI()
                
        static method Death takes nothing returns boolean
            local thistype d = thistype[GetTriggerUnit()]
            local integer i = 0
            loop
            exitwhen i > 6
                set d.cs.items<i> = UnitItemInSlot(d.cs.bear,i)
                call UnitDropItemPoint(d.cs.bear,d.cs.items<i>,GetUnitX(d.cs.bear),GetUnitY(d.cs.bear))
                call SetItemVisible(d.cs.items<i>,false)
                set i = i + 1
            endloop
            call DisableTrigger(d.trig)
            call DestroyTrigger(d.trig)
            set d.trig = null
            call d.destroy()
            return false
        endmethod
        
        method register takes nothing returns nothing
            set this.trig = CreateTrigger()
            call TriggerRegisterUnitEvent(this.trig,this.cs.bear,EVENT_UNIT_DEATH)
            call TriggerAddCondition(this.trig,Condition(function thistype.Death))
        endmethod

    endstruct
    
    private function Act takes nothing returns nothing
        local Data d = Data[GetTriggerUnit()]
        local bearData z
        local integer i 
        if d == 0 then
            set d = Data.create()
            set d.cs = GetTriggerUnit()
        endif
        set d.bear = CreateUnit(GetOwningPlayer(d.cs),&#039;n000&#039;,GetUnitX(d.cs),GetUnitY(d.cs),0)
        set z = bearData.create()
        set z.cs = d
        call z.register()
        set bearData[d.bear] = z
        if d.itemsCount &gt; 0 then
            set i = 0
            loop
            exitwhen i &gt; 6
                call SetItemVisible(d.items<i>,true)
                call UnitAddItem(d.bear,d.items<i>)
                set i = i + 1
            endloop
        endif
    endfunction
    
    private function Cond takes nothing returns boolean
        if GetSpellAbilityId() == &#039;A000&#039; then
            call Act()
        endif
        return false
    endfunction
    
    private function Init takes nothing returns nothing
        local trigger trig = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(trig,EVENT_PLAYER_UNIT_SPELL_EFFECT)
        call TriggerAddCondition(trig,Condition(function Cond))
    endfunction
endscope
</i></i></i></i></i>


It is something like this. (Havn't tested)
 

SanKakU

Member
Reaction score
21
don't post it if you haven't tested it. i thought i said that already.

edit: ok i tested that, and i suppose that was an interesting try...using aids huh?

well anyway whatever. it didn't work, the item isn't getting grabbed(by the system) or even removed(from game). it drops to the ground about a second after the summon dies.
and when you resummon it it doesn't come back with it.

was there any ability in particular it should have been? i just used a summon and made the units be 0 after i realized that your trigger was summoning a unit.
 

SanKakU

Member
Reaction score
21
yeah, i know AIDS uses pui and your idea uses pui. i used aids and i'm telling you, it doesn't work.
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
Hehe, this should work. Tested. Yay!
JASS:
scope SpiritBear initializer Init
    
    private struct Data
        unit bear
        unit cs
        trigger pickupItem
        trigger dropItem
        integer array itemtypes [6]
        player p
        
        method onDestroy takes nothing returns nothing
            local integer i = 0
            loop
            exitwhen i == 6
                set itemtypes<i> = 0
                set i = i + 1
            endloop
            call DisableTrigger(this.pickupItem)
            call DestroyTrigger(this.pickupItem)
            call DisableTrigger(this.dropItem)
            call DestroyTrigger(this.dropItem)
            set this.bear = null
            set this.cs = null
            set this.pickupItem = null
            set this.dropItem = null
            set this.p = null
        endmethod
        
        //! runtextmacro PUI()
        
        static method GetItemSlotInUnit takes unit whichUnit, item whichItem returns integer
            local integer i = 0
            loop
                if UnitItemInSlot(whichUnit,i) == whichItem then
                    return i
                endif
                set i = i + 1
                exitwhen i == 6
            endloop
            return 6
        endmethod
        
        static method RecordItem takes nothing returns boolean
            local thistype this = thistype[GetTriggerUnit()]
            local item itemz = GetManipulatedItem()
            set this.itemtypes[GetItemSlotInUnit(this.bear,itemz)] = GetItemTypeId(itemz)
            set itemz = null
            return false
        endmethod
        
        static method DeleteItem takes nothing returns boolean
            local thistype this = thistype[GetTriggerUnit()]
            local integer itemtyp = GetItemTypeId(GetManipulatedItem())
            local integer i = 0
            loop
                if this.itemtypes<i> == itemtyp then
                    set this.itemtypes<i> = 1
                endif
                set i = i + 1
            exitwhen i == 6 or this.itemtypes<i> == 1
            endloop
            return false
        endmethod
        
        method register takes nothing returns nothing
            local integer i = 0
            if this.pickupItem != null then
                call DisableTrigger(this.pickupItem)
                call DestroyTrigger(this.pickupItem)
                call DisableTrigger(this.dropItem)
                call DestroyTrigger(this.dropItem)
            endif
            
            set this.pickupItem = CreateTrigger()
            call TriggerRegisterUnitEvent(this.pickupItem,this.bear,EVENT_UNIT_PICKUP_ITEM)
            call TriggerAddCondition(this.pickupItem,Condition(function thistype.RecordItem))
            
            set this.dropItem = CreateTrigger()
            call TriggerRegisterUnitEvent(this.dropItem,this.bear,EVENT_UNIT_DROP_ITEM)
            call TriggerAddCondition(this.dropItem,Condition(function thistype.DeleteItem))
            
            set thistype[this.bear] = this
            
            loop
            exitwhen i == 6
                call UnitAddItem(this.bear,CreateItem(this.itemtypes<i>,0.,0.))
                set i = i + 1
            endloop
        endmethod
        
    endstruct
    
    private function Act takes nothing returns nothing
        local Data d = Data[GetTriggerUnit()]
        if d == 0 then
            set d = Data.create()
            set d.cs = GetTriggerUnit()
            set d.p = GetOwningPlayer(d.cs)
        endif
        if IsUnitType(d.bear,UNIT_TYPE_DEAD) == true or d.bear == null then
            set d.bear = CreateUnit(d.p,&#039;h000&#039;,GetUnitX(d.cs),GetUnitY(d.cs),0.)
        else
            call DisplayTextToPlayer(d.p,0.,0.,&quot;Bear already summoned!&quot;)
        endif
        call d.register()
        set Data[d.cs] = d
    endfunction
    
    private function Cond takes nothing returns boolean
        if GetSpellAbilityId() == &#039;A001&#039; then
            call Act()
        endif
        return false
    endfunction
    
    private function Init takes nothing returns nothing
        local trigger trig = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(trig,EVENT_PLAYER_UNIT_SPELL_EFFECT)
        call TriggerAddCondition(trig,Condition(function Cond))
    endfunction
endscope
</i></i></i></i></i>
 

SanKakU

Member
Reaction score
21
lol, are you serious? how are you testing it?

because i'm testing it by having the summon pick up an item and then killing it. then i try to summon him again...and when i do...now i get a message saying that he's already summoned...

oh and btw, he still drops the item when he dies of course...
 

SanKakU

Member
Reaction score
21
the only way i've found so far that i can prevent a summon from dropping units is to give him some sort of reincarnation ability. haha. ok great. so i finally figured it out. as far as i can tell, dota probably does that too. i think there's more to it than that, anyone else care to try to figure out the rest? i suppose it isn't particularly important, now that it works just fine, i'm just curious.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      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