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
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 = 039;h007039; // 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 = 039;A00G039; // this is the ability to close the inventory
private constant integer openabi = 039;A003039; // 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] = 039;A00D039;
set normalpic[2] = 039;A00E039;
set normalpic[3] = 039;A00A039;
set normalpic[4] = 039;A007039;
set normalpic[5] = 039;A00F039;
set normalpic[6] = 039;A004039;
set normalpic[7] = 039;A00C039;
set normalpic[8] = 039;A00L039;
set normalpic[9] = 039;A00M039;
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(039;I004039;, 039;A002039;, 0, 0, 039;A008039;, 1, false, "Alternate")
//sacred stone
call apply_item.evaluate(039;I000039;, 039;A000039;, 039;A00Y039;, 0, 039;A00K039;, 9, false, "")
//Slizer
call apply_item.evaluate(039;I005039;, 039;A005039;, 0, 0, 039;A00H039;, 1, false, "Alternate")
//Razor
call apply_item.evaluate(039;I006039;, 039;A00I039;, 0, 0, 039;A00J039;, 1, true, "Channel")
//shield
call apply_item.evaluate(039;I001039;, 039;A006039;, 0, 0, 039;A009039;, 2, false, "defend")
//Amulet of darkness
call apply_item.evaluate(039;I00A039;, 039;A00S039;, 0, 0, 039;A00B039;, 3, false, "")
//Golems Skin
call apply_item.evaluate(039;I003039;, 039;A00U039;, 0, 0, 039;A00N039;, 4, false, "")
//Windwalkers
call apply_item.evaluate(039;I002039;, 039;A00X039;, 0, 0, 039;A00O039;, 5, false, "")
//Stonefists
call apply_item.evaluate(039;I007039;, 039;A00W039;, 0, 0, 039;A00P039;, 6, false, "")
//Arthuriel
call apply_item.evaluate(039;I008039;, 039;A00T039;, 0, 0, 039;A00Q039;, 7, false, "")
//Mask of Horror
call apply_item.evaluate(039;I009039;, 039;A00V039;, 0, 0, 039;A00R039;, 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 > 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 > 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 > 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 = 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 = ""
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>