• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

sell item with an ability

Status
Not open for further replies.
Level 9
Joined
Jul 10, 2011
Messages
562
hey all :D

i wanna add a spell to my heroes so they can sell items they own directly and without running to shops but i have no idea how to get the gold costs without setting every items gold costs in a hash and calling them from there.

anyone has a way to get the gold costs directly?


thanks in advance

greetz clapto
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
I just checked out Nestharus' system and based on that idea, created this (does not require JNGP):

JASS:
function GetItemCost takes item i, string s returns integer
    local integer itemId = GetItemTypeId(i)
    
    call SetPlayerState( Player(14), PLAYER_STATE_RESOURCE_GOLD, 1000000 )
    call SetPlayerState( Player(14), PLAYER_STATE_RESOURCE_LUMBER, 1000000 )
    
    call AddItemToStock( udg_dummyItemCost, itemId, 1, 1 )
    call IssueNeutralImmediateOrderById( Player(14), udg_dummyItemCost, itemId )
    call RemoveItemFromStock( udg_dummyItemCost, itemId )
    
    if s == "gold" then
        return 1000000 - GetPlayerState( Player(14), PLAYER_STATE_RESOURCE_GOLD )
    elseif s == "lumber" or s == "wood" then
        return 1000000 - GetPlayerState( Player(14), PLAYER_STATE_RESOURCE_LUMBER )
    else
        call BJDebugMsg( "Invalid input: GetItemCost( item, " + s + " )" )
        return 0
    endif
endfunction

It gets the cost of all items you want with the use of a singly dummy.
You can call it like this:
JASS:
set GoldCost = GetItemCost( item, "gold" )
set WoodCost = GetItemCost( item, "lumber" ) // or set i = GetItemCost( item, "wood" )

Add the script to the header, copy/paste the dummy and you're all set (I hope :D).
Test-map attached
 

Attachments

  • GetItemCost.w3x
    13.9 KB · Views: 29
Status
Not open for further replies.
Top