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

[vJASS] array value?

Status
Not open for further replies.

ABM

ABM

Level 7
Joined
Jul 13, 2005
Messages
279
array goes from 0 to 8192....

but i think you can put any number inside the array, for example:
integer array item['I012'] =

this is not possible right
so is there a way to use the itemID ascii code as a array value of an integer array...?
i cannot use hashtable, so with normal array is there a way to do this...
use the item id value to retrieve an integer or a boolean, or a string?

i need to attach to every item type in the most simple way a value wich determine if a hero can pick or not the item.
the check need to be used from a id and give 4 hero type the value true (carriable) false (un carriable)
i though of using something like item[id]=1121
1 mean uncarriable, 2 mean carriable (each digit = a hero type)
or use a string item[id] = nnyn the proble is that id might be too big to be accepted as a value.

any ideas?
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
why not hashtable

if you are going to use vJass anyways, use Bribe's new Table, it will allow you to do exactly this but if you want to get something different from the table then integer you must do table.$type$[index], so for instance for string it would be table.string[index]
 
Level 37
Joined
Mar 6, 2006
Messages
9,243
array goes from 0 to 8192....

integer array item['I012'] =
this is not possible right

Correct.

so is there a way to use the itemID ascii code as a array value of an integer array...?

No.

Item types are something like 1023344343. You could subtract 10000000 from every id and use that as an index, so each id becomes less than 8192. But his might have overlapping ids. The big numbers are just examples.

any ideas?

You could use item level or item classification.
 

ABM

ABM

Level 7
Joined
Jul 13, 2005
Messages
279
why not hashtable

if you are going to use vJass anyways, use Bribe's new Table, it will allow you to do exactly this but if you want to get something different from the table then integer you must do table.$type$[index], so for instance for string it would be table.string[index]

well because the map is linked with WEU, and until i remove all link and programs and bugs...
it will be impossible to use hashtable.

hum, item lvl is already used, charge too, gold and lumber value too...
they also use custom value.
maybe i will try with life, it is big enough for me to try 1111 and 2222.
but a few item (1-2) use life, so i will try to figure out.

maybe when i completly removed WEU i will try bribe table.

the last solution i see is putting all items in array, and then loop through all
having two array 1 for item id and 1 for value
loop A to itemmax
if item[A]='I010' then
set i = A
if herotype1= false then
order hero to drop item
endif
 
is the hero buying these items from a shop or do creeps drop them ?

i recently made an item system for my map were i put all items in array and then looped through them and used a second array to put a value for buy able / not buy able. u could try something like tht for ur map. then when item is bought it checks for the value of buy able / not buy able if not it adds the lumber back to the player. (i only used lumber, but it would be easy to modify for gold as well.)
 

ABM

ABM

Level 7
Joined
Jul 13, 2005
Messages
279
well no,
the items come from random spawn on the map...
wood, tinder, stone, flint...
from killing animals or cutting tree, bush...
raw meat, animal hide, bones, venom sac, wood, tinder, feather, etc...
from crafting
many,many, etc..

so basically, i can create a big array (300 items).
set each id to a array number 0 to 300
the set value into another array from 0 to 300
basically it is a home made hashtable, made of many variables array.

but for the item enable/disable to carry depending on unit class, i used the lumber value from item type.
WEU has a script for this but i don't know if it is good or not.

[Jass=]
function GetNextItemBJ takes nothing returns nothing
if DistanceBetweenPoints(GetItemLoc(GetEnumItem()),udg_zz_CheckLocation) < udg_zz_ClosestDistance then
set udg_zz_ClosestItem = GetEnumItem()
set udg_zz_ClosestDistance = DistanceBetweenPoints(GetItemLoc(GetEnumItem()),udg_zz_CheckLocation)
endif
endfunction

//FindNextItem checks for items in range - used for itemlimits
function FindNextItem takes location L returns item

set udg_zz_ClosestDistance = 1000000
set udg_zz_CheckLocation = L

call EnumItemsInRect(GetEntireMapRect(),null,function GetNextItemBJ)

return udg_zz_ClosestItem
endfunction

//GetItemWoodCostById checks itemcosts - used for itemlimits
function GetItemWoodCostById takes integer Uid returns integer

local integer Val = GetPlayerState(Player(15),PLAYER_STATE_RESOURCE_GOLD)
local integer ValB = GetPlayerState(Player(15),PLAYER_STATE_RESOURCE_LUMBER)
local integer Diff
local unit U = CreateUnitAtLoc(Player(15),'nshe',GetRectCenter(GetPlayableMapRect()),bj_UNIT_FACING)

call AdjustPlayerStateBJ(50000,Player(15),PLAYER_STATE_RESOURCE_GOLD)
call AdjustPlayerStateBJ(50000,Player(15),PLAYER_STATE_RESOURCE_LUMBER)
call UnitAddAbilityBJ('Asid',U)

set Diff = GetPlayerState(Player(15),PLAYER_STATE_RESOURCE_LUMBER)

call AddItemToStockBJ(Uid,U,1,1)
call IssueTrainOrderByIdBJ(U,Uid)

set Diff = Diff - GetPlayerState(Player(15),PLAYER_STATE_RESOURCE_LUMBER)

call SetPlayerState(Player(15),PLAYER_STATE_RESOURCE_GOLD,Val)
call SetPlayerState(Player(15),PLAYER_STATE_RESOURCE_LUMBER,ValB)
call RemoveItem(FindNextItem(GetUnitLoc(U)))
call RemoveUnit(U)

return Diff
endfunction
[/code]
when the function GetItemWoodCostById(itemId) is called it return the wood value for the checked item id...
 
Level 4
Joined
Jan 27, 2010
Messages
133
This is a hash-table all written in vJass. Should cover your needs.

JASS:
library ItemHash

// call ItemHash_Set('I00A', false)
// call ItemHash_Get('I00A') -> (returns false)

globals
    private integer array keys
    private boolean array values
    private constant integer HASH_PROBE = 353 // Prime number
    private constant boolean DEFAULT_VALUE = true // Always allow pickup from uninitialized
endglobals

private function GetId takes integer itemid returns integer
    debug local integer safe=0
    local integer id = ModuloInteger( itemid*2654435761 , 8190 )
    loop
        exitwhen keys[id]==0 or keys[id]==itemid
        set id = ModuloInteger( id+HASH_PROBE , 8190 )

        debug set safe=safe+1
        debug if safe>5 then
            debug call BJDebugMsg("Hash probe-error.")
            debug return -1
        debug endif
    endloop
    return id
endfunction

public function Set takes integer itemid, boolean bool returns nothing
    local integer id = GetId(itemid)
    if id!=(-1) then
        set keys[id]=itemid
        set values[id]=bool
    endif
endfunction

public function Get takes integer itemid returns boolean
    local integer id = GetId(itemid)
    if id==(-1) or keys[id]==0 then
        return DEFAULT_VALUE // If an item would be forgotten, always allow.
    endif
    return values[id]
endfunction

endlibrary
 
Last edited:
Status
Not open for further replies.
Top