• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] GetItemCost & GetItemValue

Status
Not open for further replies.
Level 9
Joined
Jul 3, 2008
Messages
495
Hallo Hive.

This is a script I wroted so you can get:
ItemGoldCost, ItemLumberCost, ItemGoldValue, ItemLumberValue, that blizzard did not implent in natives.

So I did a little work arround, and it works perfectly for me. But before im
releasing it in the jass section, I want you to test it.

Installation
1. Create a new blank map
2. Copy this script to the map header
JASS:
//===========================================================================================================================================
//  Name:       GetItemValueSystem                                                                                                        =
//  Author:     MeKC                                                                                                                        =
//  Version:    v.1.0                                                                                                                       =
//===========================================================================================================================================

//=========================================================================================================================
//  Global Variables                                                                                                      
//=========================================================================================================================
    globals
    real                udg_givsPOSX            = 0
    real                udg_givsPOSY            = 0
    integer             udg_givsITEM            = 0    
    integer             udg_givsSHOP            = 'hvlt'
    integer             udg_givsHERO            = 'Hpal'
    player              udg_givsPLAYER          = Player(12)
    endglobals
//=========================================================================================================================
//  GetItemCost                                                                                                           
//=========================================================================================================================
    function EnumItemCost takes nothing returns nothing
        if GetItemTypeId(GetEnumItem()) == udg_givsITEM then
            call RemoveItem(GetEnumItem())
        endif
    endfunction
    
    function GetItemGoldCost takes integer i returns integer
        local integer cost  = 0        
        local integer gold  = GetPlayerState(udg_givsPLAYER,PLAYER_STATE_RESOURCE_GOLD)
        local integer wood  = GetPlayerState(udg_givsPLAYER,PLAYER_STATE_RESOURCE_LUMBER)
        local rect    point = Rect(udg_givsPOSX-700,udg_givsPOSY-700,udg_givsPOSX+700,udg_givsPOSY+700)
        local unit    shop  = CreateUnit(udg_givsPLAYER,udg_givsSHOP,udg_givsPOSX,udg_givsPOSY,90)
        call SetPlayerState(udg_givsPLAYER,PLAYER_STATE_RESOURCE_GOLD,1000000)
        call SetPlayerState(udg_givsPLAYER,PLAYER_STATE_RESOURCE_LUMBER,1000000)        
        
        call UnitAddAbility(shop,'Asid')
        call AddItemToStock(shop,i,1,1)        
        call IssueImmediateOrderById(shop,i)        
        set cost = 1000000 - GetPlayerState(udg_givsPLAYER,PLAYER_STATE_RESOURCE_GOLD)
        call SetPlayerState(udg_givsPLAYER,PLAYER_STATE_RESOURCE_GOLD,gold)
        call SetPlayerState(udg_givsPLAYER,PLAYER_STATE_RESOURCE_LUMBER,wood)        
        
        set udg_givsITEM = i
        call EnumItemsInRect(point,null,function EnumItemCost)
        call RemoveRect(point)
        call RemoveUnit(shop)
        set shop = null
        set point = null

        return cost
    endfunction
    
    function GetItemLumberCost takes integer i returns integer
        local integer cost  = 0        
        local integer gold  = GetPlayerState(udg_givsPLAYER,PLAYER_STATE_RESOURCE_GOLD)
        local integer wood  = GetPlayerState(udg_givsPLAYER,PLAYER_STATE_RESOURCE_LUMBER)
        local rect    point = Rect(udg_givsPOSX-700,udg_givsPOSY-700,udg_givsPOSX+700,udg_givsPOSY+700)
        local unit    shop  = CreateUnit(udg_givsPLAYER,udg_givsSHOP,udg_givsPOSX,udg_givsPOSY,90)
        call SetPlayerState(udg_givsPLAYER,PLAYER_STATE_RESOURCE_GOLD,1000000)
        call SetPlayerState(udg_givsPLAYER,PLAYER_STATE_RESOURCE_LUMBER,1000000)        
        
        call UnitAddAbility(shop,'Asid')
        call AddItemToStock(shop,i,1,1)        
        call IssueImmediateOrderById(shop,i)        
        set cost = 1000000 - GetPlayerState(udg_givsPLAYER,PLAYER_STATE_RESOURCE_LUMBER)
        call SetPlayerState(udg_givsPLAYER,PLAYER_STATE_RESOURCE_GOLD,gold)
        call SetPlayerState(udg_givsPLAYER,PLAYER_STATE_RESOURCE_LUMBER,wood)        
        
        set udg_givsITEM = i
        call EnumItemsInRect(point,null,function EnumItemCost)
        call RemoveRect(point)
        call RemoveUnit(shop)
        set shop = null
        set point = null

        return cost
    endfunction

    function GetItemGoldValue takes integer i returns integer                                                
        local integer value = 0
        local integer gold  = GetPlayerState(udg_givsPLAYER,PLAYER_STATE_RESOURCE_GOLD)
        local integer wood  = GetPlayerState(udg_givsPLAYER,PLAYER_STATE_RESOURCE_LUMBER)        
        local unit    hero  = CreateUnit(udg_givsPLAYER,udg_givsHERO,udg_givsPOSX+128,udg_givsPOSY-97,90)
        local unit    shop  = CreateUnit(udg_givsPLAYER,udg_givsSHOP,udg_givsPOSX,udg_givsPOSY,90)
        local item    sell  = UnitAddItemByIdSwapped(i,hero)

        call UnitDropItemTarget(hero,sell,shop)
        set value = GetPlayerState(udg_givsPLAYER,PLAYER_STATE_RESOURCE_GOLD) - gold
        call SetPlayerState(udg_givsPLAYER,PLAYER_STATE_RESOURCE_GOLD,gold)
        call SetPlayerState(udg_givsPLAYER,PLAYER_STATE_RESOURCE_LUMBER,wood) 
        
        call RemoveUnit(hero)
        call RemoveUnit(shop)
        call RemoveItem(sell)
        set hero = null
        set shop = null
        set sell = null
        
        return value
    endfunction
    
    function GetItemLumberValue takes integer i returns integer                                                
        local integer value = 0
        local integer gold  = GetPlayerState(udg_givsPLAYER,PLAYER_STATE_RESOURCE_GOLD)
        local integer wood  = GetPlayerState(udg_givsPLAYER,PLAYER_STATE_RESOURCE_LUMBER)        
        local unit    hero  = CreateUnit(udg_givsPLAYER,udg_givsHERO,udg_givsPOSX+128,udg_givsPOSY-97,90)
        local unit    shop  = CreateUnit(udg_givsPLAYER,udg_givsSHOP,udg_givsPOSX,udg_givsPOSY,90)
        local item    sell  = UnitAddItemByIdSwapped(i,hero)

        call UnitDropItemTarget(hero,sell,shop)
        set value = GetPlayerState(udg_givsPLAYER,PLAYER_STATE_RESOURCE_LUMBER) - wood
        call SetPlayerState(udg_givsPLAYER,PLAYER_STATE_RESOURCE_GOLD,gold)
        call SetPlayerState(udg_givsPLAYER,PLAYER_STATE_RESOURCE_LUMBER,wood) 
        
        call RemoveUnit(hero)
        call RemoveUnit(shop)
        call RemoveItem(sell)
        set hero = null
        set shop = null
        set sell = null
        
        return value
    endfunction

//=========================================================================================================================
//                                                                                                         
//=========================================================================================================================
3. Use for example to write down the cost & and values into variables.
JASS:
local integer a = GetItemGoldCost('ratc')
local integer b = GetItemLumberCost('ratc')
local integer c = GetItemGoldValue('ratc')
local integer d = GetItemLumberValue('ratc')

Thank you for your time
 
Level 9
Joined
Jul 3, 2008
Messages
495
It dosen't matter if I add/remove the shop. I think you are talking about vJass, and I dont use that.

And I dont really understand your last question. I work with gold/lumber
because I want to return the gold/lumber cost/value
 
Level 9
Joined
Apr 5, 2008
Messages
529
MeKC said:
It dosen't matter if I add/remove the shop. I think you are talking about vJass, and I dont use that.

Nah, what I meant was to create a shop on map init and just hide/show it when you need it, instead of creating a shop everytime the function is called.

MeKC said:
And I dont really understand your last question. I work with gold/lumber
because I want to return the gold/lumber cost/value

Forget about this, I was acting dumb.
 
Level 9
Joined
Jul 3, 2008
Messages
495
Lol is the global variables vJASS? didn't knew that. What do you mean by scope my script as library?

This is the header:
 

Attachments

  • Untitled-1.jpg
    Untitled-1.jpg
    32.5 KB · Views: 96
Level 9
Joined
Apr 5, 2008
Messages
529
Lol is the global variables vJASS? didn't knew that. What do you mean by scope my script as library?

JASS:
library
...
<your code>
..
endlibrary

All code inside a library will be moved above the maps header. Doing this you can basically put this code inside any trigger and it will work fine, it's much more organized than having 30k lines in the header.
 
Level 13
Joined
May 11, 2008
Messages
1,198
ok, that's interesting, but i still don't understand what a map header is or a library. are they almost the same thing? or entirely different? maybe i should ask about it after i've recoded all my triggers...or maybe it will just make me rewrite them all over again. so it might be good for me to know now. is there a good basic library tutorial i should be reading? because any about that which i've read so far have made no sense to me.
 
Status
Not open for further replies.
Top