System Advanced Equipment System

Reaction score
341
Advanced Equipment System
TriggerHappy187
attachment.php


Documentation
JASS:
//***************************************************************************
//*
//*  Equipment System - By TriggerHappy187
//*
//***************************************************************************
//*
//*  Installation
//*     + Copy the Equipment System folder to your map
//*     + Copy all of the abilities, and items into your map
//*     + Make sure you have the bonus mod in your map (just copy the bonus folder)
//*     + If you don't want to copy the abilitys, just enable the bonus plugins trigger, though it will increase save time.
//***************************************************************************
//*
//*  Documentation
//*     This equipment system allows your unit to have regular items
//*     and items that are "equipped".
//*
//***************************************************************************
//*
//*  The Functions
//*
//*     EquipmentItem registers an item for the system.
//*
//*     UnitExtendEquipment registers a unit for the system.
//*
//***************************************************************************

Requires
  • JNGP or JassHelper
  • Bonus. (included in demo)

Usage

There are only two public functions in this system, and thats all you will need.

  • JASS:
    function EquipmentItem

    This function is used to register an item for the system, it lets you specify the item type, and bonuses.
  • JASS:
    function UnitExtendEquipment

    registers a unit for the system.

Code

JASS:
//***************************************************************************
//*
//*  Equipment System - By TriggerHappy187
//*
//***************************************************************************
//*
//*  Installation
//*     + Copy the Equipment System folder to your map
//*     + Copy all of the abilities, and items into your map
//*     + Make sure you have the bonus mod in your map (just copy the bonus folder)
//*     + If you don't want to copy the abilitys, just enable the bonus plugins trigger, though it will increase save time.
//***************************************************************************
//*
//*  Documentation
//*     This equipment system allows your unit to have regular items
//*     and items that are "equipped".
//*
//***************************************************************************
//*
//*  The Functions
//*
//*     EquipmentItem registers an item for the system.
//*
//*     UnitExtendEquipment registers a unit for the system.
//*
//***************************************************************************


library EQSys initializer Init requires Bonus

    globals
        private constant integer OPEN_INV    = 'I000'
        private constant integer CLOSE_INV   = 'I001'
        
        private constant integer WEAPON      = 'I002'
        private constant integer ARMOR       = 'I006'
        private constant integer ACCESSORY   = 'I005'
        private constant integer OFFHAND     = 'I003'
        private constant integer HELMET      = 'I004'
    endglobals
    
    globals
        private gamecache g
        integer EQUIPMENT_WEAPON = 0
        integer EQUIPMENT_ARMOR = 1
        integer EQUIPMENT_ACCESSORY = 3
        integer EQUIPMENT_OFFHAND = 4
        integer EQUIPMENT_HELMET = 2
        private integer array gettype
        private integer array thetype
    endglobals
    
    private function U2I takes unit u returns integer
        return u
        return 0
    endfunction
    
    private function GetUnitId takes unit u returns string
        return I2S(U2I(u)-0x100000)
    endfunction
    
    private function Conditions1 takes nothing returns boolean
        return GetItemTypeId(GetManipulatedItem()) == OPEN_INV
    endfunction
    
    private function Conditions2 takes nothing returns boolean
        return GetItemTypeId(GetManipulatedItem()) == CLOSE_INV
    endfunction
    
    private struct data
        
        integer array itm[6]
        integer array inv[6]
        
        trigger open = CreateTrigger()
        trigger close = CreateTrigger()
        
        boolean inInv = false
        boolean hasRoom
        
        static method openBag takes nothing returns nothing
            local unit u = GetTriggerUnit()
            local data d = GetStoredInteger(g, "struct", GetUnitId(u))
            local integer i = 0
            set d.hasRoom = false
            loop
                exitwhen i == 6
                set d.inv<i> = GetItemTypeId(UnitItemInSlot(u, i))
                if GetItemName(UnitItemInSlot(u, i)) == null then
                    set d.hasRoom = true
                endif
                call RemoveItem(UnitItemInSlot(u, i))
                call UnitDropItemSlot(u, UnitAddItemById(u, d.itm<i>), i)
                call SetItemDroppable(UnitItemInSlot(u, i), false)
                set i = i + 1
            endloop
            set d.inInv = true
            call UnitDropItemSlot(u, UnitAddItemById(u, CLOSE_INV), 5)
        endmethod
        
        static method closeBag takes nothing returns nothing
            local unit u = GetTriggerUnit()
            local data d = GetStoredInteger(g, &quot;struct&quot;, GetUnitId(u))
            local integer i = 0
            call RemoveItem(UnitItemInSlot(u, 5))
            loop
                exitwhen i == 6
                set d.itm<i> = GetItemTypeId(UnitItemInSlot(u, i))
                call RemoveItem(UnitItemInSlot(u, i))
                call UnitDropItemSlot(u, UnitAddItemById(u, d.inv<i>), i)
                call SetItemDroppable(UnitItemInSlot(u, i), false)
                set i = i + 1
            endloop
            set d.inInv = false
        endmethod
        
        static method create takes unit u returns data
            local data d = data.allocate()
            local item i
            call StoreInteger(g, &quot;struct&quot;, GetUnitId(u), d)
            
            call TriggerRegisterUnitEvent(d.open, u, EVENT_UNIT_USE_ITEM)
            call TriggerAddAction(d.open, function data.openBag)
            call TriggerAddCondition(d.open, Condition(function Conditions1))
            
            call TriggerRegisterUnitEvent(d.close, u, EVENT_UNIT_USE_ITEM)
            call TriggerAddAction(d.close, function data.closeBag)
            call TriggerAddCondition(d.close, Condition(function Conditions2))
            
            set d.itm[0] = WEAPON 
            set d.itm[1] = ARMOR 
            set d.itm[2] = HELMET 
            set d.itm[3] = ACCESSORY
            set d.itm[4] = OFFHAND

            set i = CreateItem(OPEN_INV, 0, 0)
            call UnitAddItem(u, i)
            call UnitDropItemPoint(u, UnitItemInSlot(u, 5), GetUnitX(u), GetUnitY(u))
            call UnitDropItemSlot(u, i, 5)
            
            set i = null
            return d
        endmethod
        
    endstruct
    
    private struct bonus
    
        integer str 
        integer agi 
        integer int 
        integer dmg 
        integer def
        integer hp
        integer mp
        integer spd
        integer type

    endstruct
    
    
    function UnitExtendEquipment takes unit u returns nothing
        local data d = data.create(u)
    endfunction
    
    function EquipmentItem takes integer rawID, integer s,integer str, integer agi, integer int, integer dmg, integer def, integer hp, integer mp, integer spd returns nothing
        local bonus b = bonus.create()
        set b.str = str
        set b.agi = agi
        set b.int = int
        set b.dmg = dmg
        set b.def = def
        set b.hp = hp
        set b.mp = mp
        set b.spd = spd
        set b.type = s
        call StoreInteger(g, &quot;bonus&quot;, I2S(rawID), b) 
    endfunction
    
    private function GetItemNameById takes integer id returns string
        local item i = CreateItem(id, 0, 0)
        local string s = GetItemName(i)
        set i = null
        return s
    endfunction
    
    private function GetOpenSlot takes data d returns integer
        local integer i = 0
        loop
            exitwhen i == 6
            if d.inv<i> == 0 then
                return i
            endif
            set i = i + 1
        endloop
        return -1
    endfunction
    
    private function Equip takes nothing returns nothing
        local unit u = GetTriggerUnit()
        local integer i = GetItemTypeId(GetManipulatedItem())
        local bonus b = GetStoredInteger(g, &quot;bonus&quot;, I2S(i))
        local data d = GetStoredInteger(g, &quot;struct&quot;, GetUnitId(u))
        if b == 0 or d == 0 then
            return
        endif
        if d.inInv == false then
            if d.itm[b.type] == thetype[b.type] then
                set d.itm[b.type] = i
                
                set Bonus_Armor<u> = Bonus_Armor<u> + b.def
                set Bonus_Damage<u> = Bonus_Damage<u> + (b.dmg/5)
                set Bonus_Life<u> = Bonus_Life<u> + (b.hp/100)
                set Bonus_Mana<u> = Bonus_Mana<u> + (b.mp/100)
                set Bonus_Str<u> = Bonus_Str<u> + (b.str)
                set Bonus_Agi<u> = Bonus_Agi<u> + (b.agi)
                set Bonus_Int<u> = Bonus_Int<u> + (b.int)
                set Bonus_AttackSpeed<u> = Bonus_AttackSpeed<u> + (b.spd/5)
                
                call DisplayTextToPlayer(GetOwningPlayer(u), 0, 0, &quot;|cffffcc00Equipment:|r &quot; + GetItemName(GetManipulatedItem()) + &quot; has been equipped&quot;)
                call RemoveItem(GetManipulatedItem())
            else
                call DisplayTextToPlayer(GetOwningPlayer(u), 0, 0, &quot;|cffffcc00Equipment:|r You already have &quot; + GetItemNameById(d.itm[b.type]) + &quot; equipped&quot;)
            endif
        else
            if d.hasRoom then
                set i = GetOpenSlot(d)
                if i != -1 then
                    set d.inv<i> = GetItemTypeId(GetManipulatedItem())
                else
                    call CreateItem(GetItemTypeId(GetManipulatedItem()), GetUnitX(u), GetUnitY(u))
                endif
            else
                call CreateItem(GetItemTypeId(GetManipulatedItem()), GetUnitX(u), GetUnitY(u))
            endif
            call DisplayTextToPlayer(GetOwningPlayer(u), 0, 0, &quot;|cffffcc00Equipment:|r &quot; + GetItemName(GetManipulatedItem()) + &quot; has been unequipped&quot;)
            call RemoveItem(GetManipulatedItem())
            call UnitAddItemById(u, thetype[b.type])
            set d.itm[b.type] = thetype[b.type]
            
            set Bonus_Armor<u> = Bonus_Armor<u> - b.def
            set Bonus_Damage<u> = Bonus_Damage<u> - (b.dmg/5)
            set Bonus_Life<u> = Bonus_Life<u> - (b.hp/100)
            set Bonus_Mana<u> = Bonus_Mana<u> - (b.mp/100)
            set Bonus_Str<u> = Bonus_Str<u> - (b.str)
            set Bonus_Agi<u> = Bonus_Agi<u> - (b.agi)
            set Bonus_Int<u> = Bonus_Int<u> - (b.int)
            set Bonus_AttackSpeed<u> = Bonus_AttackSpeed<u> - (b.spd/5)
            
        endif
        set u = null
    endfunction
    
    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger()
        call FlushGameCache(InitGameCache(&quot;eqsys&quot;))
        set g = InitGameCache(&quot;eqsys&quot;)
        call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_USE_ITEM )
        call TriggerAddAction(t, function Equip)
        
        set thetype[0] = WEAPON
        set thetype[1] = ARMOR
        set thetype[2] = HELMET
        set thetype[3] = ACCESSORY
        set thetype[4] = OFFHAND
    endfunction
    
endlibrary
</u></u></u></u></u></u></u></u></u></u></u></u></u></u></u></u></i></u></u></u></u></u></u></u></u></u></u></u></u></u></u></u></u></i></i></i></i></i>
 

Attachments

  • EQsys.w3x
    34.2 KB · Views: 295

Angel_Island

Much long, many time, wow
Reaction score
56
Nice :thup:, but the only thing bad is that it takes place in your real inventory. You can also make it a spell instead.
 

D.V.D

Make a wish
Reaction score
73
Its easier for people to do it in the inventory so they don't need to move the mouse back and forth.
 

Nexor

...
Reaction score
74
I've found a bug: if you have an item in the inventory, pick up another and want to equip the not equipped item, there will be an extra item will be created in the center of map
 
Reaction score
341
I've found a bug: if you have an item in the inventory, pick up another and want to equip the not equipped item, there will be an extra item will be created in the center of map

I'm not sure what you mean.

The only item that will be created is if you don't have enough room

in your inventory, and you unequip an item, then it is created at your heroes position.
 

Flare

Stops copies me!
Reaction score
662
Your documentation of the usable functions need some work

Current documentation:
Code:
function EquipmentItem
This function is used to register an item for the system, it lets you specify the item type, and bonuses.

What you forgot to mention
Code:
function EquipmentItem takes [COLOR="Red"]integer rawID, integer s,integer str, integer agi, integer int, integer dmg, integer def, integer hp, integer mp, integer spd[/COLOR] returns nothing
You should list the arguments of the function in order, and what each argument corresponds to - without looking at the code, first question that comes to mind is what is s? What would be a good value to use for it?
'specify item type, and bonuses' isn't good enough, since you don't even explain what bonuses are available...

Might take a look at code later, if/when I get a chance
 

wraithseeker

Tired.
Reaction score
122
Actually this looks good but it seems like something to replace Blade.dk 's AAA inventory which is more efficient and work well more.
 

Immolation

Member
Reaction score
20
When I try to equip an item when I already have equipped something in that slot, another item of the same type is created in the middle of the map.

Fix this, please :D
 

Asdfblah1

New Member
Reaction score
10
He's talking about how, when you equip an item, and then equip an item of the same type, a duplicate is spawned in the center of the map. Try it for yourself--pick up two accessories. Equip one and click the latter.
 

Azlier

Old World Ghost
Reaction score
461
You could really use Table instead of your own game cache.

And:
JASS:
private function GetUnitId takes unit u returns string
    return I2S(U2I(u)-0x100000)
endfunction


With using the string for game cache, the subtraction is totally useless. :rolleyes:

JASS:
call TriggerAddAction(t, function Equip)

Conditions, please.

JASS:
call TriggerAddAction(d.open, function data.openBag)
call TriggerRegisterUnitEvent(d.close, u, EVENT_UNIT_USE_ITEM)
call TriggerAddCondition(d.close, Condition(function Conditions1)
call TriggerAddAction(d.close, function data.closeBag)
call TriggerAddCondition(d.close, Condition(function Conditions2))

Again, conditions exclusively please.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • WildTurkey WildTurkey:
    is there a stephen green in the house?
    +1
  • The Helper The Helper:
    What is up WildTurkey?
  • The Helper The Helper:
    Looks like Google fixed whatever mistake that made the recipes on the site go crazy and we are no longer trending towards a recipe site lol - I don't care though because it motivated me to spend alot of time on the site improving it and at least now the content people are looking at is not stupid and embarrassing like it was when I first got back into this like 5 years ago.
  • The Helper The Helper:
    Plus - I have a pretty bad ass recipe collection now! That section of the site is 10 thousand times better than it was before
  • The Helper The Helper:
    We now have a web designer at my job. A legit talented professional! I am going to get him to redesign the site theme. It is time.
  • Varine Varine:
    I got one more day of community service and then I'm free from this nonsense! I polished a cop car today for a funeral or something I guess
  • Varine Varine:
    They also were digging threw old shit at the sheriff's office and I tried to get them to give me the old electronic stuff, but they said no. They can't give it to people because they might use it to impersonate a cop or break into their network or some shit? idk but it was a shame to see them take a whole bunch of radios and shit to get shredded and landfilled
  • The Helper The Helper:
    whatever at least you are free
  • 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 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