Problems with JASS

Status
Not open for further replies.
Level 7
Joined
Mar 10, 2005
Messages
55
hey,
I've heard, that Jass can read an items gold value. Is it true?
and if yes, how is it done?

JavaScript:
function Trig_Paladin_Xtra_Spelldamage_Copy_Copy_Actions takes nothing returns nothing
local integer i = 2

    loop
        exitwhen i> 6
        if GetItemLifeBJ(UnitItemInSlotBJ(GetSpellAbilityUnit(), i)) == 10.00 then
        set udg_Paladin_Xtra_Spelldamage_Int = GetItemValue('ratc'(UnitItemInSlotBJ(GetSpellAbilityUnit(), i))
        endif
        set i= i+ 1
    endloop
endfunction

im not sure about the GetItemValue nor the rest of the line.
I just want to get the gold value of the item with 10 life.

greetings Mc
 
Level 45
Joined
Feb 27, 2007
Messages
5,578
GetItemValue is not a JASS function, it was a custom function written by Blade.dk. See this thread (which it looks like you already did based on the 'ratc' I see); honestly it would probably be easier to just make a hashtable that stores all the item values like DSG suggested. Anyway... put the code below into a new trigger and change the constants to be the shops in your map. I made 2 functions so it's easier to call it on an item-type or a specific item:
JASS:
library ItemValue
globals
    private constant integer SHOP_ID = 'ngme'  //raw code of the unit that sells
    private constant integer BUYER_ID = 'Hpal'  //raw code of the unit that buys
    private constant real X = 0.00 //where to create the units
    private constant real Y = 0.00
    private constant player WHO = Player(20) //which player owns them
endglobals

function GetItemTypeValue takes integer rawcode returns integer
    local unit u1  = CreateUnit(WHO, SHOP_ID, X, Y, 0)
    local unit u2  = CreateUnit(WHO, BUYER_ID, X, X-100, 90)
    local item i   = UnitAddItemById(u2, rawcode)
    local integer g1 = GetPlayerState(WHO, PLAYER_STATE_RESOURCE_GOLD)
    local integer g2

    call UnitDropItemTarget(u2, i, u1)
    set g2 = GetPlayerState(WHO, PLAYER_STATE_RESOURCE_GOLD) - g1
    call SetPlayerState(WHO, PLAYER_STATE_RESOURCE_GOLD, g1)
  
    call RemoveUnit(u1)
    call RemoveUnit(u2)
    set u1 = null
    set u2 = null
    set a  = null
    return g2
endfunction

function GetItemValue takes item i returns integer
    return GetItemTypeValue(GetItemTypeId(i))
endfunction
endlibrary
Then you can use it with custom scripts in GUI:
  • For each (Integer A) from 1 to 6 do (Actions)
    • Loop - Actions
      • Set ItemVar = (Item carried by UNIT in slot (Integer A))
      • If (All conditions are true) then do (Then actions) else do (Else actions)
        • If - Conditions
          • (Life of ItemVar) equal to 10.00
        • Then - Actions
          • Custom script: set udg_IntegerVar = GetItemValue(udg_ItemVar)
        • Else - Actions
 
Status
Not open for further replies.
Top