Turn Item raw code into item ID

Accname

2D-Graphics enthusiast
Reaction score
1,462
as the title says, can i somehow turn an items raw code (for example pghe for greater healing potion) into an items ID (IDs are like 1227894832)?

i got plenty of items in one of my maps and to make it easier to test the game i want to create the items via triggers. the trigger looks somewhat like this:
Code:
Create Item
    Events
        Player - Player 1 (Red) types a chat message containing <Empty String> as A substring
    Conditions
        (Substring((Entered chat string), 1, 1)) Equal to -
    Actions
        Set TmpGrp = (Units currently selected by (Triggering player))
        Set TmpPnt = (Position of (Random unit from TmpGrp))
        Custom script: call CreateItemLoc( S2I([COLOR="Red"]SubStringBJ(GetEventPlayerChatString(), 2, StringLength(GetEventPlayerChatString()))[/COLOR]), udg_TmpPnt )
        Custom script: call RemoveLocation (udg_TmpPnt)
        Custom script: call DestroyGroup (udg_TmpGrp)
the problem with this system is that the item IDs are very long and hard to memorize, however the item rawcode is much easier and it would be great if i could just enter the raw code instead of a 10 digit number.

thanks in advanced. accname.
 

GetTriggerUnit-

DogEntrepreneur
Reaction score
129
Couldn't you do like
A player types a message like "Ring of armor"
Then create one item-type of (entered chat string)
 

Accname

2D-Graphics enthusiast
Reaction score
1,462
i dont know if it is possible to convert an items name into its ID but i guess its not...
 

cleeezzz

The Undead Ranger.
Reaction score
268
actually it doesn't need return bug, just confusing math.

JASS:
private function Char2Id takes string c returns integer
    local integer i = 0
    local string abc = &quot;0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz&quot;
    local string t

    loop
        set t = SubString(abc,i,i + 1)
        exitwhen t == null or t == c
        set i = i + 1
    endloop
    if i &lt; 10 then
        return i + 48
    elseif i &lt; 36 then
        return i + 65 - 10
    endif
    return i + 97 - 36
endfunction

private function String2Id takes string s returns integer
    return ((Char2Id(SubString(s,0,1)) * 256 + Char2Id(SubString(s,1,2))) * 256 + Char2Id(SubString(s,2,3))) * 256 + Char2Id(SubString(s,3,4))
endfunction

private function Id2Char takes integer i returns string
    local string abc = &quot;0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz&quot;

    if i &gt;= 97 then
        return SubString(abc,i - 97 + 36,i - 96 + 36)
    elseif i &gt;= 65 then
        return SubString(abc,i - 65 + 10,i - 64 + 10)
    endif
    return SubString(abc,i - 48,i - 47)
endfunction

private function Id2String takes integer id1 returns string
    local integer t = id1 / 256
    local string r = Id2Char(id1 - 256 * t)
    set id1 = t / 256
    set r = Id2Char(t - 256 * id1) + r
    set t = id1 / 256
    return Id2Char(t) + Id2Char(id1 - 256 * t) + r
endfunction


Example of usage, this trigger when you type -item 'I00Y' will create that item.

JASS:
scope ItemCreate initializer Init

globals
    private integer id2 = 0
endglobals

private function Char2Id takes string c returns integer
    local integer i = 0
    local string abc = &quot;0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz&quot;
    local string t

    loop
        set t = SubString(abc,i,i + 1)
        exitwhen t == null or t == c
        set i = i + 1
    endloop
    if i &lt; 10 then
        return i + 48
    elseif i &lt; 36 then
        return i + 65 - 10
    endif
    return i + 97 - 36
endfunction

private function String2Id takes string s returns integer
    return ((Char2Id(SubString(s,0,1)) * 256 + Char2Id(SubString(s,1,2))) * 256 + Char2Id(SubString(s,2,3))) * 256 + Char2Id(SubString(s,3,4))
endfunction

private function Id2Char takes integer i returns string
    local string abc = &quot;0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz&quot;

    if i &gt;= 97 then
        return SubString(abc,i - 97 + 36,i - 96 + 36)
    elseif i &gt;= 65 then
        return SubString(abc,i - 65 + 10,i - 64 + 10)
    endif
    return SubString(abc,i - 48,i - 47)
endfunction

private function Id2String takes integer id1 returns string
    local integer t = id1 / 256
    local string r = Id2Char(id1 - 256 * t)
    set id1 = t / 256
    set r = Id2Char(t - 256 * id1) + r
    set t = id1 / 256
    return Id2Char(t) + Id2Char(id1 - 256 * t) + r
endfunction

private function PrivateFilter takes nothing returns boolean 
    return IsUnitType(GetFilterUnit(), UNIT_TYPE_HERO)
endfunction

private function CB takes nothing returns nothing
    call UnitAddItemById(GetEnumUnit(), id2)
endfunction

private function Actions takes nothing returns nothing
    local group g
    local string s
    set s = SubString(GetEventPlayerChatString(), 7, StringLength(GetEventPlayerChatString()))
    set id2 = String2Id(s)
    if id2 != 0 then
        set g = CreateGroup()
        call GroupEnumUnitsOfPlayer(g, GetTriggerPlayer(), Condition(function PrivateFilter))
        call ForGroup(g, function CB)
        call DestroyGroup(g)
        set g = null
    endif
endfunction

private function Conditions takes nothing returns boolean
    return SubString( GetEventPlayerChatString(), 0, 6) == &quot;-item &quot;
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    local trigger trig = CreateTrigger(  )
    local integer i = 0
    loop
        exitwhen i == 12
        call TriggerRegisterPlayerChatEvent( trig, Player(i), &quot;-item &quot;, false )
        set i = i + 1
    endloop
    call TriggerAddCondition(trig, Condition(function Conditions))
    call TriggerAddAction( trig, function Actions )
endfunction

endscope


(the math is converting bases i believe)
 

Accname

2D-Graphics enthusiast
Reaction score
1,462
looks awsome but can you try to explain a littlebit?
can this be done by gui?

what about these lines:
JASS:
 if i &lt; 10 then
        return i + 48
    elseif i &lt; 36 then
        return i + 65 - 10 &lt;- looks weird
    endif
    return i + 97 - 36 &lt;-confusing too cause i has already been set above and is now overwritten?

are quite confusing but maybe it makes sense after a little explanation.
thanks anyhow.
 

Zurtrogx

Active Member
Reaction score
24
The raw code to ID conversion used by Warcraft 3 involves ASCII.
For example, A = 65, B = 66, a = 97, etc.

In order to convert it into the ID, the first character is the series is multiplied by 256^3, the second character is mulitplied by 256^2, the third by 256, and the last by 1.

So, let's say you've got a code of pghe:
p = 112
g = 103
h = 104
e = 101

Therefore, the ID will be:
(112 * 256^3) + (103 * 256^2) + (104 * 256^1) + (101 * 256^0)
=2091537900

I've attached a map as well so you can see how the triggers work.
The same is applied for adding/removing abilities, which is what the map was initially used for. I quickly changed a few things around so it creates items instead.

Oh, and it's GUI. :thup:
 

Attachments

  • Raw Code to ID by Zurtrogx.w3x
    142.6 KB · Views: 422
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top