Question on how to read out data

dabum

New Member
Reaction score
0
I'm a beginner to JASS & vJASS, but i've read some tutorials. However I'm still learning and currently I need some help with structs. I've read the tutorial posted on this forum, but I still dont understand how to read out the data put into them. Which is why i'm wondering if anyone can help me with this equipment system.

It uses private structs to store in the specific player, the unit thats using the system, and the item/icon/effects. My question is, how exactly do I get that information to display as data like "Hpal" or "I001" and so forth.

Any help would be appreciated - below is the code

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
//
// 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
//
// 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
     // 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 itemeffekt1
     private integer array itemeffekt2
     private integer array itemeffekt3
     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, 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]
endstruct

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 inventories[total] = dat
    set total = total + 1
    set u = null
endfunction

globals
     Inventory array inventories
endglobals

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
endfunction

private function GetDataFromInventory takes unit u returns Inventory
    local integer i = 0
    local Inventory dat
    loop
        exitwhen i &gt; total
        set dat = inventories<i>
        if dat.u == u then
            return dat
        endif
        set i = i + 1
    endloop
    return 0
endfunction

private function GetDataFromOwner takes unit u returns Inventory
    local integer i = 0
    local Inventory dat
    loop
        exitwhen i &gt; total
        set dat = inventories<i>
        if dat.owner == u then
            return dat
        endif
        set i = i + 1
    endloop
    return 0
endfunction

private function GetIndex takes integer ite, integer abi returns integer
    local integer i = 0
    if ite == 0 then
        loop
            exitwhen i &gt; items
            if itempic<i> == abi then
                return i
            endif
            set i = i + 1
        endloop
    else
        loop
            exitwhen i &gt; 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 = GetDataFromOwner(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.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>
    set ite = null
endfunction

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

private function access takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local Inventory dat = GetDataFromInventory(u)
    local integer i = GetIndex(0, GetSpellAbilityId())
    if (GetSpellAbilityId() == exitabi) then
        call SelectUnitForPlayerSingle(dat.owner, GetOwningPlayer(dat.owner))
    elseif (GetSpellAbilityId() == openabi) then
        set dat = GetDataFromOwner(u)
        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 = &quot;&quot;
        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
    set u = null
endfunction

function IsEquipmentClassEmpty takes unit u, integer class returns boolean
    return GetDataFromInventory(u).icon[class] == normalpic[class]
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</i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i>
 

Gtam

Lerning how to write and read!! Yeah.
Reaction score
164
post it in jass tags not code tags plz
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top