• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Equipment System + Level Requirement

Status
Not open for further replies.
Level 5
Joined
Jan 29, 2009
Messages
92
I'm using the "Advanced Equipment System v.10.0" and i was wondering if anyone knew how to slightly change the code so that only units with a level higher than/equal to that of the item's level can equip it.
JASS:
library EquipmentSystem initializer Init

// The_Witcher's Equipment System     [1.24 compatible]
//
// This is an easy to use equipment system.
// you have to set up the items in the InitItems function
// for better understanding:  -index means an integer value given from this system
//                             to the items you register
//                            -ID means the rawcode of an item
//
// to give a unit the ability to equip things just use
//
//  call InitEquipment( yourunit )
//
// to check whether a unit has something equipped in a class use
//
//   IsEquipmentClassEmpty(  u,   class)        it returns a boolean
//                        unit  integer
//
// in case you want the rawcode of an equipped item use
//   GetEquipItemID (owner, class)            it returns an integer
//                   unit  integer
//
// if you want to force an item to be equipped use
//   EquipItemByID  (u,    id)
//                  unit integer
//
// use the following one to force equipping by index
//   EquipItemByIndex (u,  index)
//                    unit  integer
//
// for getting the index of an item use
//   GetItemIndex   ( ite)              it returns an integer
//                  integer
//
// if you want to make a item unaquipable(false)/equipable(true) for a unit use these:
//   EnableItemEquipByID ( u,   id,   flag )
//                      unit integer boolean
//
//   EnableItemEquipByIndex ( u,   index,   flag )
//                           unit  integer  boolean
//
// if you want to transfer the equipment of a unit to another one (for example because you had to replace the unit) use:
//   TransferEquipment (a,   b)
//                    unit  unit
//
//----- For SAVE/LOAD systems use these functions: -----
//
//  use this function to get the index of the equipped item of class xyz (save these values in your load code) ...
//   GetEquipItemIndex (u,  class)         it returns an integer
//                    unit integer
//
//  ... and this function to equip a new item by this index (which you read out from the load code)!
//   EquipItemByID  (u,  index)
//                 unit integer
//
//
// to implement this system, just copy this trigger in your map
// it requires jngp to work well
//
// have fun^^


//--------------Customizeable  Part----------------------

globals
     private constant integer inventoryid = 'h007'                        // this is the rawcode of the unit which works as inventory
     private constant integer itemclasses = 9                             // this is the amount of classes you have (like ring, boots, etc..)
     private constant integer mainhandclass = 1                           // this is the class you selected as mainhand class
     private constant integer offhandclass = 2                            // this is the class you selected as offhand class
     private constant integer exitabi = 'A00G'                            // this is the ability to close the inventory
     private constant integer openabi = 'A003'                            // this is the ability to open the inventory
     private constant string  no  =  " can't equip "                      // this is the text shown when a unit is trying to equip an item which isnt allowed to
                                                                          // example: " can't equip " becomes ingame something like   Soldier can't equip Giant Sword
     // just ignore the following global
     private integer array normalpic
endglobals

// this is my setup for testmap
//class 1 = mainhand
//class 2 = offhand
//class 3 = amulet
//class 4 = armor
//class 5 = boots
//class 6 = gloves
//class 7 = ring
//class 8 = helmet
//class 9 = special

private function InitNormals takes nothing returns nothing // here you have to give an icon ability for every empty slot
    set normalpic[1] = 'A00D'
    set normalpic[2] = 'A00E'
    set normalpic[3] = 'A00A'
    set normalpic[4] = 'A007'
    set normalpic[5] = 'A00F'
    set normalpic[6] = 'A004'
    set normalpic[7] = 'A00C'
    set normalpic[8] = 'A00L'
    set normalpic[9] = 'A00M'
endfunction

private function InitItems takes nothing returns nothing  // in this part you set up the items
    //call apply_item(itemid, effect1, effekt2, effekt3, icon, class, twohanded, animation)
    // itemid is the items rawcode, effect1,effect2 and effect3 the rawcodes of up to 3 abilities the item gives,
    // icon the rawcode of the icon ability shown on the inventory screen,
    // class is an integer for the class you sort the item into, twohanded a boolean(self explaining) and animation a string which is added as an animationtag
    // if the class isn't mainhand or offhand then animation can be anything, it won't change anything
    // if the class isn't mainhand twohanded is always false
    //Silversword
    call apply_item.evaluate('I004', 'A002', 0, 0, 'A008', 1, false, "Alternate")
    //sacred stone
    call apply_item.evaluate('I000', 'A000', 'A00Y', 0, 'A00K', 9, false, "")
    //Slizer
    call apply_item.evaluate('I005', 'A005', 0, 0, 'A00H', 1, false, "Alternate")
    //Razor
    call apply_item.evaluate('I006', 'A00I', 0, 0, 'A00J', 1, true, "Channel")
    //shield
    call apply_item.evaluate('I001', 'A006', 0, 0, 'A009', 2, false, "defend")
    //Amulet of darkness
    call apply_item.evaluate('I00A', 'A00S', 0, 0, 'A00B', 3, false, "")
    //Golems Skin
    call apply_item.evaluate('I003', 'A00U', 0, 0, 'A00N', 4, false, "")
    //Windwalkers
    call apply_item.evaluate('I002', 'A00X', 0, 0, 'A00O', 5, false, "")
    //Stonefists
    call apply_item.evaluate('I007', 'A00W', 0, 0, 'A00P', 6, false, "")
    //Arthuriel
    call apply_item.evaluate('I008', 'A00T', 0, 0, 'A00Q', 7, false, "")
    //Mask of Horror
    call apply_item.evaluate('I009', 'A00V', 0, 0, 'A00R', 8, false, "")
    //NO MORE ITEMS UNDER THIS LINE
endfunction

//--------------------------------------------------------
//---------------system code------------------------------
//--------------------------------------------------------

private struct Inventory
unit owner
unit u
string animtag = ""
integer array icon[12]
integer array effekt1[12]
integer array effekt2[12]
integer array effekt3[12]
integer array Item[12]
boolean array enabled[200]
endstruct

globals
     private integer items = 0
     private integer array itemm
     private integer array itemclass
     private integer array itemeffekt1
     private integer array itemeffekt2
     private integer array itemeffekt3
     private integer array itempic
     private boolean array twohand
     private string array tag
     private hashtable h = InitHashtable()
endglobals

function InitEquipment takes unit whichunit returns nothing
    local Inventory dat = Inventory.create()
    local integer i = 1
    local unit u = whichunit
    set dat.owner = u
    set dat.u = CreateUnit(GetOwningPlayer(dat.owner),inventoryid,GetUnitX(dat.owner),GetUnitY(dat.owner),0)
    call UnitAddAbility(dat.u,exitabi)
    call UnitAddAbility(dat.owner,openabi)
    loop
        exitwhen i > itemclasses
        call UnitAddAbility(dat.u,normalpic[i])
        set dat.icon[i] = normalpic[i]
        set dat.effekt1[i] = 0
        set dat.effekt2[i] = 0
        set dat.effekt3[i] = 0
        set dat.Item[i] = 0
        set i = i + 1
    endloop
    set i = 0
    loop
        exitwhen i > items
        set dat.enabled[i] = true
        set i = i + 1
    endloop
    call SaveInteger(h,GetHandleId(u),1,dat)
    call SaveInteger(h,GetHandleId(dat.u),1,dat)
    set u = null
endfunction

function apply_item takes integer itemid, integer ability1,integer ability2,integer ability3, integer icon, integer class, boolean twohanded, string animation returns nothing
    set items = items + 1
    set itemm[items] = itemid
    set itemclass[items] = class
    set itemeffekt1[items] = ability1
    set itemeffekt2[items] = ability2
    set itemeffekt3[items] = ability3
    set itempic[items] = icon
    set tag[items] = animation
    if class == mainhandclass then
        set twohand[items] = twohanded
    else
        set twohand[items] = false
    endif
    call SaveInteger(h,itemid,1,items)
    call SaveInteger(h,icon,1,items)
endfunction

private function Equip takes unit u, item ite returns nothing
    local Inventory dat = LoadInteger(h,GetHandleId(u),1)
    local integer id = GetItemTypeId(ite)
    local integer i = LoadInteger(h,id,1)
    local integer ii = LoadInteger(h,dat.Item[mainhandclass],1)
    local integer iii = LoadInteger(h,dat.Item[offhandclass],1)
    call RemoveItem(ite)
    if itemclass[i] == mainhandclass or itemclass[i] == offhandclass then
        if twohand[i] == true then
            call UnitRemoveAbility(dat.u, dat.icon[itemclass[iii]])
            call UnitRemoveAbility(dat.owner, dat.effekt1[itemclass[iii]])
            call UnitRemoveAbility(dat.owner, dat.effekt2[itemclass[iii]])
            call UnitRemoveAbility(dat.owner, dat.effekt3[itemclass[iii]])
            call UnitAddItemById(dat.owner, dat.Item[itemclass[iii]])
            set dat.icon[itemclass[iii]] = normalpic[itemclass[iii]]
            set dat.effekt1[itemclass[iii]] = 0
            set dat.effekt2[itemclass[iii]] = 0
            set dat.effekt3[itemclass[iii]] = 0
            set dat.Item[itemclass[iii]] = 0
            call UnitRemoveAbility(dat.u, dat.icon[itemclass[ii]])
            call UnitRemoveAbility(dat.owner, dat.effekt1[itemclass[ii]])
            call UnitRemoveAbility(dat.owner, dat.effekt2[itemclass[ii]])
            call UnitRemoveAbility(dat.owner, dat.effekt3[itemclass[ii]])
            call UnitAddItemById(dat.owner, dat.Item[itemclass[ii]])
            set dat.icon[itemclass[ii]] = normalpic[itemclass[ii]]
            set dat.effekt1[itemclass[ii]] = 0
            set dat.effekt2[itemclass[ii]] = 0
            set dat.effekt3[itemclass[ii]] = 0
            set dat.Item[itemclass[ii]] = 0
        elseif twohand[ii] == true then
            call UnitRemoveAbility(dat.u, dat.icon[itemclass[ii]])
            call UnitRemoveAbility(dat.owner, dat.effekt1[itemclass[ii]])
            call UnitRemoveAbility(dat.owner, dat.effekt2[itemclass[ii]])
            call UnitRemoveAbility(dat.owner, dat.effekt3[itemclass[ii]])
            call UnitAddItemById(dat.owner, dat.Item[itemclass[ii]])
            set dat.icon[itemclass[ii]] = normalpic[itemclass[ii]]
            set dat.effekt1[itemclass[ii]] = 0
            set dat.effekt2[itemclass[ii]] = 0
            set dat.effekt3[itemclass[ii]] = 0
            set dat.Item[itemclass[ii]] = 0
            call UnitAddAbility(dat.u,normalpic[offhandclass])
            call UnitAddAbility(dat.u,normalpic[mainhandclass])
        endif
        if dat.Item[offhandclass] == 0 then
            call AddUnitAnimationProperties(dat.owner, dat.animtag, false)
            call AddUnitAnimationProperties(dat.owner, tag[i], true)
            set dat.animtag = tag[i]
        endif
    endif
    call UnitRemoveAbility(dat.u, dat.icon[itemclass[i]])
    call UnitRemoveAbility(dat.owner, dat.effekt1[itemclass[i]])
    call UnitRemoveAbility(dat.owner, dat.effekt2[itemclass[i]])
    call UnitRemoveAbility(dat.owner, dat.effekt3[itemclass[i]])
    call UnitAddItemById(dat.owner, dat.Item[itemclass[i]])
    call UnitAddAbility(dat.owner, itemeffekt1[i])
    call UnitAddAbility(dat.owner, itemeffekt2[i])
    call UnitAddAbility(dat.owner, itemeffekt3[i])
    call UnitAddAbility(dat.u, itempic[i])
    set dat.icon[itemclass[i]] = itempic[i]
    set dat.effekt1[itemclass[i]] = itemeffekt1[i]
    set dat.effekt2[itemclass[i]] = itemeffekt2[i]
    set dat.effekt3[itemclass[i]] = itemeffekt3[i]
    set dat.Item[itemclass[i]] = itemm[i]
endfunction

private function check takes nothing returns boolean
    return LoadInteger(h,GetItemTypeId(GetManipulatedItem()),1) != 0
endfunction

private function access takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local Inventory dat = LoadInteger(h,GetHandleId(u),1)
    local integer i = LoadInteger(h,GetSpellAbilityId(),1)
    if (GetSpellAbilityId() == exitabi) then
        call SelectUnitForPlayerSingle(dat.owner, GetOwningPlayer(dat.owner))
    elseif (GetSpellAbilityId() == openabi) then
        set dat = LoadInteger(h,GetHandleId(u),1)
        call SelectUnitForPlayerSingle(dat.u, GetOwningPlayer(dat.u))
    elseif GetUnitTypeId(u) == inventoryid then
        call UnitRemoveAbility(dat.u, dat.icon[itemclass[i]])
        call UnitRemoveAbility(dat.owner, dat.effekt1[itemclass[i]])
        call UnitRemoveAbility(dat.owner, dat.effekt2[itemclass[i]])
        call UnitRemoveAbility(dat.owner, dat.effekt3[itemclass[i]])
        call UnitAddItemById(dat.owner, dat.Item[itemclass[i]])
        call UnitAddAbility(dat.u,normalpic[itemclass[i]])
        set dat.icon[itemclass[i]] = normalpic[itemclass[i]]
        set dat.effekt1[itemclass[i]] = 0
        set dat.effekt2[itemclass[i]] = 0
        set dat.effekt3[itemclass[i]] = 0
        set dat.Item[itemclass[i]] = 0
        if twohand[i] == true then
            call UnitAddAbility(dat.u,normalpic[offhandclass])
        endif
        if itemclass[i] == mainhandclass and dat.Item[offhandclass] == 0 then
            call AddUnitAnimationProperties(dat.owner, dat.animtag, false)
            set dat.animtag = ""
        elseif itemclass[i] == offhandclass then
            call AddUnitAnimationProperties(dat.owner, dat.animtag, false)
            call AddUnitAnimationProperties(dat.owner, tag[LoadInteger(h,dat.Item[mainhandclass],1)], true)
            set dat.animtag = tag[LoadInteger(h,dat.Item[mainhandclass],1)]
        endif
    endif
    set u = null
endfunction

function TransferEquipment takes unit a, unit b returns nothing
    local integer i = 1
    local Inventory dat = LoadInteger(h,GetHandleId(a),1)
    loop
        exitwhen i > itemclasses
        call UnitRemoveAbility(a,itemeffekt1[LoadInteger(h,dat.Item[i],1)])
        call UnitAddAbility(b,itemeffekt1[LoadInteger(h,dat.Item[i],1)])
        call UnitRemoveAbility(a,itemeffekt2[LoadInteger(h,dat.Item[i],1)])
        call UnitAddAbility(b,itemeffekt2[LoadInteger(h,dat.Item[i],1)])
        call UnitRemoveAbility(a,itemeffekt3[LoadInteger(h,dat.Item[i],1)])
        call UnitAddAbility(b,itemeffekt3[LoadInteger(h,dat.Item[i],1)])
        set i = i + 1
    endloop
    call SaveInteger(h,GetHandleId(b),1,dat)
    set dat.owner = b
    call UnitAddAbility(b,openabi)
    call UnitRemoveAbility(a,openabi)
    call AddUnitAnimationProperties(a, dat.animtag, false)
    call AddUnitAnimationProperties(b, dat.animtag, true)
endfunction

function IsEquipmentClassEmpty takes unit u, integer class returns boolean
    local Inventory dat = LoadInteger(h,GetHandleId(u),1)
    return dat.icon[class] == normalpic[class]
endfunction

function GetEquipItemID takes unit u, integer class returns integer
    local Inventory dat = LoadInteger(h,GetHandleId(u),1)
    return dat.Item[class]
endfunction

function GetItemIndex takes item ite returns integer
    return LoadInteger(h,GetItemTypeId(ite),1)
endfunction

function EnableItemEquipByID takes unit u, integer id, boolean flag returns nothing
    local Inventory dat = LoadInteger(h,GetHandleId(u),1)
    set dat.enabled[LoadInteger(h,id,1)] = flag
endfunction

function EnableItemEquipByIndex takes unit u, integer index, boolean flag returns nothing
    local Inventory dat = LoadInteger(h,GetHandleId(u),1)
    set dat.enabled[index] = flag
endfunction

function GetEquipItemIndex takes unit u, integer class returns integer
    local Inventory dat = LoadInteger(h,GetHandleId(u),1)
    return LoadInteger(h,dat.Item[class],1)
endfunction

function EquipItemByID takes unit u, integer id returns nothing
    call Equip(u,CreateItem(id,0,0))
endfunction

function EquipItemByIndex takes unit u, integer index returns nothing
    call Equip(u,CreateItem(itemm[index],0,0))
endfunction

private function Itemequip takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local item ite = GetManipulatedItem()
    local Inventory dat = LoadInteger(h,GetHandleId(u),1)
    if dat.enabled[LoadInteger(h,GetItemTypeId(ite),1)] then
        call Equip(u,ite)
    else
        call DisplayTextToPlayer(GetOwningPlayer(u), 0, 0, GetUnitName(u) + no + GetItemName(ite))
    endif
endfunction

private function Init takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerAddAction(t, function Itemequip)
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_USE_ITEM )
    call TriggerAddCondition(t, Condition(function check))

    set t = CreateTrigger()
    call TriggerAddAction(t, function access)
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_CAST )

    call InitNormals()
    call InitItems()
endfunction

endlibrary
 
Try changing

JASS:
private function check takes nothing returns boolean
    return LoadInteger(h,GetItemTypeId(GetManipulatedItem()),1) != 0
endfunction

to

JASS:
private function check takes nothing returns boolean
    return LoadInteger(h,GetItemTypeId(GetManipulatedItem()),1) != 0/*
    */and GetHeroLevel(GetManipulatingUnit()) >= GetItemLevel(GetManipulatedItem())
endfunction
 
Level 5
Joined
Jan 29, 2009
Messages
92
great! +rep

now does anyone know how to make it say the hero's level is too low ONLY for when it's true?

sorry i don't know jass, but am learning
 
Level 5
Joined
Jul 2, 2005
Messages
60
JASS:
private function check takes nothing returns boolean

    if not GetHeroLevel(GetManipulatingUnit())>=GetItemLevel(GetManipulatedItem())  then
       call BJdebugMsg("Your text")
       return false
    else
        return LoadInteger(h,GetItemTypeId(GetManipulatedItem()),1) != 0/**/
    endif

endfunction
 
Status
Not open for further replies.
Top