# Detecting Item price

Status
Not open for further replies.

#### l0git3c

Level 6
Anyone know how to detect item price? For now i just have one solution which is
• Events
• Unit - A unit Acquires an item
• Conditions
• (Item-type of (Item being manipulated)) Equal to (My custom Item)
• Then - Actions
• Set ItemValueVariable = (ItemValueVariable + 1)
• Item - Set the custom value of (Item being manipulated) to ItemValueVariable
• Set ItemPrice[(Custom value of (Item being manipulated))] = 15
this trigger works, but i have many items and it will needs many triggers and takes much times to make

any other solution?

#### MeKC

Level 9
I remember Blade.dk long time ago created a script that could return the item sell value. But it looks
like its not here anymore.

I think it worked like this way:

Create a dummy unit with the item you wanna sell. Create a shop, and force
the unit to sell the item, and check the gold before and after selling the item.

I will take a look on it

#### l0git3c

Level 6
^its enough for me to find good solution

thanks

edit: .... how to force dummy unit to sell an item?

Last edited:

#### MeKC

Level 9
I have now created a script for you that can return the item sell value.

JASS:
``````    function GetUnitShop takes nothing returns integer
return 'ngme'                                                               // This is the raw code for the goblin shop
endfunction

function GetUnitSell takes nothing returns integer
return 'Hpal'                                                               // This is the raw code for the paladin
endfunction

function GetItemValue takes integer i returns integer
local real x   = 0                                                          // This is the x position where we create the dummy units. Dont place it in the water.
local real y   = 0                                                          // This is the y position where we create the dummy units. Dont place it in the water.
local unit u1  = CreateUnit(Player(12),GetUnitShop(),x,y,0)
local unit u2  = CreateUnit(Player(12),GetUnitSell(),x,y-100,90)
local integer g1 = GetPlayerState(Player(12),PLAYER_STATE_RESOURCE_GOLD)
local integer g2 = 0
call UnitDropItemTarget(u2,a,u1)
set g2 = GetPlayerState(Player(12),PLAYER_STATE_RESOURCE_GOLD) - g1
call SetPlayerState(Player(12),PLAYER_STATE_RESOURCE_GOLD,GetPlayerState(Player(12),PLAYER_STATE_RESOURCE_GOLD)-g2)

call RemoveUnit(u1)
call RemoveUnit(u2)
set u1 = null
set u2 = null
set a  = null
return g2
endfunction``````

And use this script to return the value

JASS:
``GetItemValue('ratc') // 'ratc' is the raw code for Claws of Attack + 12``

You can also look at the demo map how it works

#### Attachments

• Return Item Sell Value.w3x
16.7 KB · Views: 127
Last edited:

#### Dr Super Good

Spell Reviewer
Level 64
Script solution one, you pass it an item type and sets a global to the gold cost. of the item.
Script solution two, you make a kind of hashtable or database with items type integers and their cost.

Solution one might cause unexpected events to fire or have a delay.
Solution two will be instantanious but might have problems with too many items and needs all item costs to be set up at map initialization.

#### l0git3c

Level 6
I have now created a script for you that can return the item sell value.

JASS:
``````    function GetUnitShop takes nothing returns integer
return 'ngme'                                                               // This is the raw code for the goblin shop
endfunction

function GetUnitSell takes nothing returns integer
return 'Hpal'                                                               // This is the raw code for the paladin
endfunction

function GetItemValue takes integer i returns integer
local real x   = 0                                                          // This is the x position where we create the dummy units. Dont place it in the water.
local real y   = 0                                                          // This is the y position where we create the dummy units. Dont place it in the water.
local unit u1  = CreateUnit(Player(12),GetUnitShop(),x,y,0)
local unit u2  = CreateUnit(Player(12),GetUnitSell(),x,y-100,90)
local integer g1 = GetPlayerState(Player(12),PLAYER_STATE_RESOURCE_GOLD)
local integer g2 = 0
call UnitDropItemTarget(u2,a,u1)
set g2 = GetPlayerState(Player(12),PLAYER_STATE_RESOURCE_GOLD) - g1
call SetPlayerState(Player(12),PLAYER_STATE_RESOURCE_GOLD,GetPlayerState(Player(12),PLAYER_STATE_RESOURCE_GOLD)-g2)

call RemoveUnit(u1)
call RemoveUnit(u2)
set u1 = null
set u2 = null
set a  = null
return g2
endfunction``````

And use this script to return the value

JASS:
``GetItemValue('ratc') // 'ratc' is the raw code for Claws of Attack + 12``

You can also look at the demo map how it works

im GUI user, and i dont know JASS things

@Dr Super Good
im a bit not understand with your solutions, can you explain it more? but it seems solution two is same with my solution that i posted

#### MeKC

Level 9
Its not that hard... You dont need to understand the script I posted. You just need to add it to your map header.

Lets say you create a global array integer variable and call it ItemValue.
Then you just need this trigger so set it to the item sell value
• Custom script: set udg_ItemValue[1] = GetItemValue('ratc')
'ratc' is the raw code for claws of attack. Open Object Editor and press
Ctrl + D, and you can see raw codes for every items

• Actions
• Custom script: set udg_ItemValue[1] = GetItemValue('ratc')
• Custom script: set udg_ItemValue[2] = GetItemValue('desc')
• Custom script: set udg_ItemValue[3] = GetItemValue('ckng')
• Game - Display to (All players) the text: (Claws of Attack Value = + (String(ItemValue[1])))
• Game - Display to (All players) the text: (Dagger of Escape Value = + (String(ItemValue[2])))
• Game - Display to (All players) the text: (Crown of Kings Value = + (String(ItemValue[3])))

#### Attachments

• Return Item Sell Value GUI.w3x
16.8 KB · Views: 110

#### l0git3c

Level 6
i see, thanks, i`ll try it now

edit: wew, i found easy way to do this....no trigger and works well i think

Last edited:

#### Dr Super Good

Spell Reviewer
Level 64
MeKC, you forgot to correct the values before returning them as selling items only refunds a percentage of the orignal cost. Or does dropping an intem via triggers always refund 100% of orignal cost.
Also could be made more efficent by setting it straight to G1 instead of getting the gold value again and subtracting G2.

#### l0git3c

Level 6
^wiw
btw, im use my new way which is, set all of my items level to (item cost/2)

its pretty simple to use in GUI tho...

#### Meticulous

Level 11
Won't work if you have expensive items, of course.

#### Rui

Level 41
If you're returning always the same values, you could as well make those 2 functions constant. Another important thing to have in mind is that the value can change depending on the refunding, which is 50% by default.
Even though, I don't think you need to go through all the trouble of creating 3 different functions.

Seeing as how the author seems to have found a different solution, I'll set this thread's prefix to [Ignored].

#### l0git3c

Level 6
Won't work if you have expensive items, of course.

works....press shift before clicking when i want to edit item level

#### Dr Super Good

Spell Reviewer
Level 64
All you need to do is create a system whereby you can detect the item cost by selling the item. On map initialization you simply then sell all the items, multiply them to full cost and store them in a hash table. Now axcessing them should be reasonably faster that creating units and does not need to use a field like item level.

#### l0git3c

Level 6
hmm...does item level bad, and causes game slowly?

#### Dr Super Good

Spell Reviewer
Level 64
No, but it clogs up that field.

Status
Not open for further replies.

Replies
0
Views
390
Replies
9
Views
896
Replies
6
Views
1K
Replies
8
Views
1K
Replies
8
Views
388