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

Detecting Item price

Status
Not open for further replies.
Level 6
Joined
Jan 27, 2007
Messages
208
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 :sad:

any other solution?
 
Level 9
Joined
Jul 3, 2008
Messages
495
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
 
Level 9
Joined
Jul 3, 2008
Messages
495
I have now created a script for you that can return the item sell value.

Just add this script to the header of your map

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 item a   = UnitAddItemByIdSwapped(i,u2)
        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: 130
Last edited:

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
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.
 
Level 6
Joined
Jan 27, 2007
Messages
208
I have now created a script for you that can return the item sell value.

Just add this script to the header of your map

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 item a   = UnitAddItemByIdSwapped(i,u2)
        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
 
Level 9
Joined
Jul 3, 2008
Messages
495
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])))
Try download the map now, and see if you understand it.
 

Attachments

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

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
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.
 

Rui

Rui

Level 41
Joined
Jan 7, 2005
Messages
7,550
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].
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
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.
 
Status
Not open for further replies.
Top