• 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.

saving item handle to a hashtable

Status
Not open for further replies.
Level 12
Joined
Sep 11, 2011
Messages
1,176
hello everybody. i have a problem saving an item handle to a hashtable.

this is what i do

  • Set ItemType[1] = Claws of Attack +15
  • Item - Create ItemType[1] at tempPoint
  • Hashtable - Save Handle Of(Last created item) as 1 of 1 in hash
this work as intended and i can load it, but since it created an item at tempPoint, so i added this

  • Item - Remove (Last created item)
then it become unable to be loaded.

anybody know how to counter this ? should i hide these item instead of removing them ?
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
Hiding items is always a better option. By removing items, you could potentially mess up some things.
An example: you've got a staff (permanent item) that also has 2 charges, each charge creates a huge fire-nova.
If you use up all charges and then destroy/recreate it you will either have 2 charges (initial value), or infinite charges (set it to 0 by triggers = infinite).

So yeah, hide them instead :)
 
Level 12
Joined
Sep 11, 2011
Messages
1,176
thanks, i hope hiding them won't do anything bad :D
and this trigger is on map initialization.
I want to load the item when a unit is finished a dungeon.

realizing that i couldn't save Item-Type to a hashtable, so i do things like that.

210329-albums5809-picture63076.gif
for you.
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
realizing that i couldn't save Item-Type to a hashtable, so i do things like that.
Item-types (as well as unit-types and abilities) are just integers.
Of course, GUI doesn't really know that, so you'll have to use JASS to save those things.
JASS:
call SaveInteger( udg_hashtable, key, value, GetItemTypeId( item ) )
call SaveInteger( udg_hashtable, key, value, GetUnitTypeId( unit ) )
call SaveInteger( udg_hashtable, key, value, GetSpellAbilityId() )
This saves those things
 
Level 17
Joined
Nov 13, 2006
Messages
1,814
hello everybody. i have a problem saving an item handle to a hashtable.

this is what i do for save/load from hash the item refine level, refine value, how many gems was inserted into item and how much the socket value

  • Set ItemType[1] = Claws of Attack +15
  • Item - Create ItemType[1] at tempPoint
  • Hashtable - Save Handle Of(Last created item) as 1 of 1 in hash
this work as intended and i can load it, but since it created an item at tempPoint, so i added this

  • Item - Remove (Last created item)
then it become unable to be loaded.

anybody know how to counter this ? should i hide these item instead of removing them ?

depend what do u want...
for equipment system u can add data to equiped items table and remove from item table
example

JASS:
function AddCustomItem takes item itm, integer ref, integer refv, integer socket, integer socketv returns nothing
    local integer Id = GetHandleId(itm)
    set udg_CIIndex = udg_CIIndex + 1
    set udg_CItemId[udg_CIIndex] = Id
    set udg_CItem[udg_CIIndex] = itm
    call SaveInteger(udg_CItem_Table, Id, 100, udg_CIIndex)
    call SaveInteger(udg_CItem_Table, Id, 0, ref)
    call SaveInteger(udg_CItem_Table, Id, 1, refv)
    call SaveInteger(udg_CItem_Table, Id, 2, socket)
    call SaveInteger(udg_CItem_Table, Id, 3, socketv)
    if udg_CIIndex == 1 then
        call EnableTrigger( gg_trg_Checking_Custom_Items )
    endif
endfunction

JASS:
function Trig_Checking_Custom_Items_Actions takes nothing returns nothing
local integer i = 1
loop
exitwhen i > udg_CIIndex
  if udg_CItem[i] == null then
    call DisplayTextToForce( GetPlayersAll(), "Remove custom item from array, index is "+I2S(i)+ " and item id "+I2S(udg_CItemId[i])+"  "+ GetItemName(udg_CItem[i]) )
    call RemoveCustomItem (i)
    set i = i + 1
  endif
set i = i + 1
endloop
endfunction

//===========================================================================
function InitTrig_Checking_Custom_Items takes nothing returns nothing
    set gg_trg_Checking_Custom_Items = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Checking_Custom_Items, 10.00 )
    call TriggerAddAction( gg_trg_Checking_Custom_Items, function Trig_Checking_Custom_Items_Actions )
endfunction

when i equip then useall i remove the item but before it i read out the data

JASS:
            set itm = UnitItemInSlot(u, slot)
            set ilv = GetItemLevel(itm)
            set itmId = GetHandleId(itm)
            set b1 = LoadInteger(udg_CItem_Table, itmId, 0)
            set b2 = LoadInteger(udg_CItem_Table, itmId, 1)
            set b3 = LoadInteger(udg_CItem_Table, itmId, 2)
            set b4 = LoadInteger(udg_CItem_Table, itmId, 3)

if i unequip then i save the data to item table
JASS:
        set itm = UnitItemInSlot(u, slot)
        call AddCustomItem(itm, b1, b2, b3, b4)

in this case i prefer the remove the item from item table if item not exist (sold/equiped[then move data to diff table]/destroyed)

about hide item, sometimes better to remove if it is dont needed anymore
 
Level 12
Joined
Sep 11, 2011
Messages
1,176
Item-types (as well as unit-types and abilities) are just integers.
Of course, GUI doesn't really know that, so you'll have to use JASS to save those things.
JASS:
call SaveInteger( udg_hashtable, key, value, GetItemTypeId( item ) )
call SaveInteger( udg_hashtable, key, value, GetUnitTypeId( unit ) )
call SaveInteger( udg_hashtable, key, value, GetSpellAbilityId() )
This saves those things

thanks for the information, i will use that in the future.

though in this one, i won't use that because the requester might get confused.

@shadowvzs

i want to save item-type to a hashtable and then retrieve them from the hashtable after the player finished a dungeon.

  • Item - Create (Item-type of (Load (Random integer number between 1 and 3) of Variable in hash)) at LootRoom[i]
the requester wants the loot to be random, but the loot should be related to the hero.

e.g Paladin won't get Staff, Archmage won't get Hammer, and so on.

anyway, this problem is [SOLVED]
 
Status
Not open for further replies.
Top