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

[Trigger] Question about variable item types

Status
Not open for further replies.
Level 1
Joined
Dec 27, 2006
Messages
6
Alright I have a question for those of you who know more than I do about the editor. I am making a map that involves a large number of custom items that vary slightly in stats. I was planning on having a create item line for each of these slightly different items at a variable region that can be set earlier in the trigger. Because this line of code would be copied many times it would be really nice to have a variable item type that changes based on the properties of the item name.

for example

if I had stat1=4 stat2=4 stat3=3 that it would select a specific item (maybe something in the name like "sword 443")

clearly the 443 can be compared to the other variables but I have been unable to find a command that allows you to set an item type variable based on the name.

something like setvariable item = itemwithname("sword 443") sorry if this question is bothersome but I have looked long and hard at the GUI and have been without luck and I figured even if there wasn't a way to do it with the GUI there might be with JASS as I know very little about it.

In summary I would like to know about how to set an item type variable to an item type based on the item type's name if this is at all possible. Thanks
 
Level 11
Joined
Jul 12, 2005
Messages
764
Wow... I read through your post 4 times, but i still don't get what you want. :S
"how to set an item type variable to an item type based on the item type's name" -> An item-type's name?? Items have names..

I don't know. Maybe rename your items, so that they will have their name, and after it a few digit code, like this:
sword 443
sword 176
blade 846
armo 116
And you get the digit with a Substring([Item's name], 7, 9), and set them into an item type variable, it will look like this:
Set ITvar[Substring("Item's name", 7, 9)] = Item
But i don't know what you really want... If this isn't, could you rephrase your question? Or write an other example..
 
Level 1
Joined
Dec 27, 2006
Messages
6
That is exactly the type of code that I want paskovich I want to be able to set an item-type variable to an item-type based on the name of the item-type. The problem is that the GUI does not have this option. The options for setting an item variable are to pick it manually or 3 unhelpful function options. Unlike other variables I do not see a way to set an item-type based on the item-type name. If this can be done please let me know.

I am sorry for the confusion, the first part of the OP was to describe what I was trying to attempt and explain why it is important that I am able to do this. In addition, by allowing you to see what I intend to accomplish I thought someone might see another way around the problem than the one I suggested.
 
Level 11
Joined
Jul 12, 2005
Messages
764
OK!! I've got it. I wrote a JASS code (this cannot be done in GUI), I'm gonna post it here today. I'll tell you how to use it ok?

Ok here it is, (It is scarry I know :)
Code:
function StringContainsString takes string source, string tofind returns boolean
    local integer a = 0
    loop
        exitwhen a > StringLength(source)-StringLength(tofind)
        if SubString(source,a,a+StringLength(tofind)) == tofind then
            return true
        endif
        set a = a + 1
    endloop
    return false
endfunction

function GetItemNameById takes integer itemid returns string
    local item i = CreateItem(itemid,0,0)
    local string name = GetItemName(i)
    call RemoveItem(i)
    set i = null
    return name
endfunction

function GetItemIdByName takes string name, integer level returns integer
    local integer itemid
    local integer a = 0
    loop
        set itemid = ChooseRandomItem(level)
        exitwhen StringContainsString(GetItemNameById(itemid), name) or a > 200
        set a = a + 1
    endloop
    if a <= 200 then
        return itemid
    endif
    return 0
endfunction

Usage:
1. Copy the script into your map's custom text section.
2. In the trigger, where you want to set the variables, use custom scripts to call the main function (it is the GetItemIdByName).
3. Example:
Custom Script: set udg_ITvar = GetItemIdByName("Mask", 10)
Explanation:
The things in brackets are parameters. The first one is a string, that's the part of the item type's name you want to store. The second one is the Level (Unclassified) value of the itemtype. Be sure to add existing values. In your case, they will be the digits that explain the item. Example:
set udg_ITvar = GetItemIdByName("443", [Level])


If you have answers, just ask!
 
Last edited:
Level 1
Joined
Dec 27, 2006
Messages
6
Awesome, thanks for the help. I havn't tried it out since I havn't made all the items yet but it looks like what I want and with any luck it will work like a charm. BTW Thousand Foot Krutch is sweet!
 
Level 1
Joined
Dec 27, 2006
Messages
6
Hey, I couldn't wait so I tried out the code with a single item and I had some success. The code most def works however there is one problem. It couldn't choose custom items. It did exclude items based on name tho. When I tried a very specific name using a variable string, it would not give any items of that level.

My guess is that the inability to pick custom items is a result of blizzard's "ChooseRandomItem(level)" function's settings. If someone could make me another function to put in it's place or point me in the right direction it would be much appreciated. Knowing nearly nothing about JASS I wouldn't even know where to look to find the "ChooseRandomItem(level)" function to use as a template for the new similar function.
 
Level 11
Joined
Jul 12, 2005
Messages
764
Hmm... Did you give the Level (Unclassified!!) value parameter accurately?

As for the function, there is no such function that picks an item. The other one is just an extra one ( ChooseRandomItemEx() ), that needs the item's class. So it picks a random [x] level item from the given class (artifact, permanent, etc...)

I will look at this custom item bug, and post if i've got a solution!

OR, maybe, one thing! I put a random-pick-limit into the code, to avoid lag caused by a never-ending loop. This could happen if you give a nonexisting name to a given item-level. The loop fires 200 times, then ends, and the functions does not return an item. You can try incresing that value...(Change every '200' numbers to a higher num.) But don't forget, if you add non-existing values, the will pause for a few seconds...
 
Level 1
Joined
Dec 27, 2006
Messages
6
Awesome I found the problem. The item field "Stats - Include as Random Choice" was set to false. I was unaware that this field existed. Anyway, I set it to true and the custom script worked magnificently. Thanks alot!
 
Level 1
Joined
Dec 27, 2006
Messages
6
Alright one last thing if anyone cares to handle it. My problem is that I have a database of over 1k items. This makes it impractical to rely entirely in the ChooseRandomItem(level) function. Now, I can use different levels and if/then/elses to narrow the search results into 10 or 11 catagories because of the different "unclassified" levels.

The question is, is it possible to change it so that the unclassified levels field accepts more than 11 values or is there another function that can be used in jass that would make this easier? Maybe systematically going through the items rather than choosing them randomly?
 
Level 11
Joined
Jul 12, 2005
Messages
764
If there was any function like that, i wouldn't use ChooseRandomItem() for sure.
And wow! You didn't write that you have over 1000 items lol!

EDIT
Oh ,how stupid i am, cause i didn't think of it earlier... They key moment here is the custom item's raw codes. They start from 'I000', and increases with 1 for each item. So i rewrote the script, so it searches through the raw codes starting from 'I000'.
I put a top limit into the code, that means the highest raw code value of all the items. If i'm not clear, the loop looks like this:

I000(+ 0)
I000 + 1
I000 + 2
...
I000 + toplimit

To set a variable, just use the custom script:
set udg_ITvar = GetItemIdByName(<name>, <toplimit>)
Set toplimit to a hight value, like 1000, or 1500.

Code:
function StringContainsString takes string source, string tofind returns boolean
    local integer a = 0
    loop
        exitwhen a > StringLength(source)-StringLength(tofind)
        if SubString(source,a,a+StringLength(tofind)) == tofind then
            return true
        endif
        set a = a + 1
    endloop
    return false
endfunction

function GetItemNameById takes integer itemid returns string
    local item i = CreateItem(itemid,0,0)
    local string name = GetItemName(i)
    call RemoveItem(i)
    set i = null
    return name
endfunction

function GetItemIdByName takes string name, integer toplimit returns integer
    local integer itemid
    local integer a = 0
    loop
        set itemid = 'I000' + a
        exitwhen StringContainsString(GetItemNameById(itemid), name) or a > toplimit
        set a = a + 1
    endloop
    if a <= toplimit then
        return itemid
    endif
    return 0
endfunction
 
Last edited:
Status
Not open for further replies.
Top