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: 421
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Varine Varine:
    How can you tell the difference between real traffic and indexing or AI generation bots?
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air
  • The Helper The Helper:
    New dessert added to recipes Southern Pecan Praline Cake https://www.thehelper.net/threads/recipe-southern-pecan-praline-cake.193555/
  • The Helper The Helper:
    Another bot invasion 493 members online most of them bots that do not show up on stats
  • Varine Varine:
    I'm looking at a solid 378 guests, but 3 members. Of which two are me and VSNES. The third is unlisted, which makes me think its a ghost.
    +1
  • The Helper The Helper:
    Some members choose invisibility mode
    +1
  • The Helper The Helper:
    I bitch about Xenforo sometimes but it really is full featured you just have to really know what you are doing to get the most out of it.
  • The Helper The Helper:
    It is just not easy to fix styles and customize but it definitely can be done
  • The Helper The Helper:
    I do know this - xenforo dropped the ball by not keeping the vbulletin reputation comments as a feature. The loss of the Reputation comments data when we switched to Xenforo really was the death knell for the site when it came to all the users that left. I know I missed it so much and I got way less interested in the site when that feature was gone and I run the site.
  • Blackveiled Blackveiled:
    People love rep, lol
    +1
  • The Helper The Helper:
    The recipe today is Sloppy Joe Casserole - one of my faves LOL https://www.thehelper.net/threads/sloppy-joe-casserole-with-manwich.193585/
  • The Helper The Helper:
    Decided to put up a healthier type recipe to mix it up - Honey Garlic Shrimp Stir-Fry https://www.thehelper.net/threads/recipe-honey-garlic-shrimp-stir-fry.193595/

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top