• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] HELP! i don't know why this doesn't work (vJass)

Status
Not open for further replies.
I have a problem with my http://www.hiveworkshop.com/forums/spells-569/advanced-equipment-system-v-2-2-a-133727/
I coded it and everything worked fine...
i made it mui i thought but then i got the message that it wasn't. i tried it but it was true... when i equip something for a unit like a sword and another unit has inthat slot something in its inventory this thing gets dropped and replaced with the new one:sad:... seems complicated, but try it out... i looked over my code but i couldn't find the mistake.
plz help and i'll +rep you if u want

JASS:
library EquipmentSystem initializer Init

// The_Witcher's Equipment System
//
//This is an easy to use equipment system.
//you have to set up the items in the InitItems function
//
// to give a unit the ability to equip things just use
//
//  call InitEquipment( yourunit )
//
// to implement this system, just copy this trigger in your map
// it requires jngp to work well
//
// have fun^^


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

globals
     private integer inventoryid = 'h007'                        // this is the rawcode of the unit which works as inventory
     private integer itemclasses = 9                             // this is the amount of classes you have (like ring, boots, etc..)
     private integer mainhandclass = 1                           // this is the class you selected as mainhand class
     private integer offhandclass = 2                            // this is the class you selected as offhand class
     private integer exitabi = 'A00G'                            // this is the ability to close the inventory
     private integer openabi = 'A003'                            // this is the ability to open the inventory
     private itemtype inventoryitems = ITEM_TYPE_CAMPAIGN        // all items you want to make equipable must have this itemtype
     // just ignore the following globals
     private integer total = 0
     private integer array normalpic
     private integer items = 0
     private integer array itemm
     private integer array itemclass
     private integer array itemeffekt
     private integer array itempic
     private boolean array twohand
     private string array tag
     // setup part continues here
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, effect, icon, class, twohanded, animation)
    // itemid is the items rawcode, effect the rawcode of the ability 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', 'A008',1,false,"Alternate")   
    //sacred stone        
    call apply_item.evaluate('I000', 'A000', 'A00K',9,false,"")
    //Slizer
    call apply_item.evaluate('I005', 'A005', 'A00H', 1, false, "Alternate")
    //Razor
    call apply_item.evaluate('I006', 'A00I', 'A00J', 1, true, "Channel")
    //shield
    call apply_item.evaluate('I001', 'A006', 'A009', 2, false, "defend")
    //Amulet of darkness
    call apply_item.evaluate('I00A', 'A00S', 'A00B', 3, false, "")
    //Golems Skin
    call apply_item.evaluate('I003', 'A00U', 'A00N', 4, false,"")
    //Windwalkers
    call apply_item.evaluate('I002', 'A00X', 'A00O',5,false,"")
    //Stonefists
    call apply_item.evaluate('I007','A00W','A00P',6,false,"")
    //Arthuriel
    call apply_item.evaluate('I008','A00T','A00Q',7,false,"")
    //Mask of Horror
    call apply_item.evaluate('I009','A00V','A00R',8,false,"")
    //NO MORE ITEMS UNDER THIS LINE
endfunction

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

private struct Inventory
unit owner
unit u
string animtag = ""
static integer array icon
static integer array effekt
static integer array Item

static method create takes unit which returns Inventory
local Inventory dat = Inventory.allocate()
local integer i = 1
local unit u = which
set dat.owner = u
set dat.u = CreateUnit(GetOwningPlayer(dat.owner),inventoryid,0,0,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.effekt[i] = 0
    set dat.Item[i] = 0
    set i = i + 1
endloop
set total = total + 1
set inventories[total - 1] = dat
return dat
endmethod

endstruct

function InitEquipment takes unit whichunit returns nothing
    call Inventory.create(whichunit)
endfunction

globals
     Inventory array inventories
endglobals

function apply_item takes integer itemid, integer effekt, integer icon, integer class, boolean twohanded, string animation returns nothing
    set items = items + 1
    set itemm[items] = itemid
    set itemclass[items] = class
    set itemeffekt[items] = effekt
    set itempic[items] = icon
    set tag[items] = animation
    if class == mainhandclass then
        set twohand[items] = twohanded
    else
        set twohand[items] = false
    endif
endfunction

private function GetData takes unit inventory, unit owner returns Inventory
    local integer i = 0
    if inventory == null then
        loop
            exitwhen i > total
            if inventories[i].owner == owner then
                return inventories[i]
            endif
            set i = i + 1
        endloop
    else
        loop
            exitwhen i > total
            if inventories[i].u == inventory then
                return inventories[i]
            endif
            set i = i + 1
        endloop
    endif
    return 0
endfunction

private function GetIndex takes integer ite, integer abi returns integer
    local integer i = 0
    if ite == 0 then
        loop
            exitwhen i > items
            if itempic[i] == abi then
                return i
            endif
            set i = i + 1
        endloop
    else
        loop
            exitwhen i > items
            if itemm[i] == ite then
                return i
            endif
            set i = i + 1
        endloop
    endif
    return 0
endfunction

private function Itemequip takes nothing returns nothing
    local Inventory dat = GetData(null,GetTriggerUnit())
    local item ite = GetManipulatedItem()
    local integer id = GetItemTypeId(ite)
    local integer i = GetIndex(id,0)
    local integer ii = GetIndex(dat.Item[mainhandclass],0)
    local integer iii = GetIndex(dat.Item[offhandclass],0)
    
    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.effekt[itemclass[iii]])
            call UnitAddItemById(dat.owner, dat.Item[itemclass[iii]])
            set dat.icon[itemclass[iii]] = normalpic[itemclass[iii]]
            set dat.effekt[itemclass[iii]] = 0
            set dat.Item[itemclass[iii]] = 0
            call UnitRemoveAbility(dat.u, dat.icon[itemclass[ii]])
            call UnitRemoveAbility(dat.owner, dat.effekt[itemclass[ii]])
            call UnitAddItemById(dat.owner, dat.Item[itemclass[ii]])
            set dat.icon[itemclass[ii]] = normalpic[itemclass[ii]]
            set dat.effekt[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.effekt[itemclass[ii]])
            call UnitAddItemById(dat.owner, dat.Item[itemclass[ii]])
            set dat.icon[itemclass[ii]] = normalpic[itemclass[ii]]
            set dat.effekt[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.effekt[itemclass[i]])
    call UnitAddItemById(dat.owner, dat.Item[itemclass[i]])
    call UnitAddAbility(dat.owner, itemeffekt[i])
    call UnitAddAbility(dat.u, itempic[i])
    set dat.icon[itemclass[i]] = itempic[i]
    set dat.effekt[itemclass[i]] = itemeffekt[i]
    set dat.Item[itemclass[i]] = itemm[i]
endfunction

private function check takes nothing returns boolean
    if (GetItemType(GetManipulatedItem()) == inventoryitems) then
        return true
    endif
    return false
endfunction

private function access takes nothing returns nothing
    local Inventory dat
    local integer i
    if (GetSpellAbilityId() == exitabi) then
        set dat = GetData(GetTriggerUnit(),null)
        call SelectUnitForPlayerSingle(dat.owner, GetOwningPlayer(dat.owner))
    elseif (GetSpellAbilityId() == openabi) then
        set dat = GetData(null,GetTriggerUnit())
        call SelectUnitForPlayerSingle(dat.u, GetOwningPlayer(dat.u))
    elseif GetUnitTypeId(GetTriggerUnit()) == inventoryid then
        set dat = GetData(GetTriggerUnit(),null)
        set i = GetIndex(0, GetSpellAbilityId())
        call UnitRemoveAbility(dat.u, dat.icon[itemclass[i]])
        call UnitRemoveAbility(dat.owner, dat.effekt[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.effekt[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 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[GetIndex(dat.Item[mainhandclass],0)], true)
            set dat.animtag = tag[GetIndex(dat.Item[mainhandclass],0)]
        endif
    endif
endfunction

private function Init takes nothing returns nothing
    local trigger t = CreateTrigger()
    local trigger tt = CreateTrigger()
    call TriggerAddAction(t, function Itemequip)
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_USE_ITEM )
    call TriggerAddCondition(t, Condition(function check))
    
    call TriggerAddAction(tt, function access)
    call TriggerRegisterAnyUnitEventBJ( tt, EVENT_PLAYER_UNIT_SPELL_CAST )
    
    call InitNormals()
    call InitItems()
endfunction

endlibrary
 
Level 7
Joined
Dec 19, 2008
Messages
276
That so pathetic when people make such tons of code and that errors, you maked that system and you must know how it works...

But, well... you loop trough all units when one unit pickup item? Try use indexing system or condition if that was manipulating unit(Who did equip)

Get Rid off

private function check takes nothing returns boolean
if (GetItemType(GetManipulatedItem()) == inventoryitems) then
return true
endif
return false
endfunction

must be: return GetItemType(GetManipulatedItem()) == inventoryitems
 
Status
Not open for further replies.
Top