- Joined
- Aug 26, 2016
- Messages
- 139
Here is a small piece of code with a button and a function to click on the button to purchase an item, how? You can make an array of about 15 items so as not to create a click function for each button with the issuance of a pre-prepared item.
JASS:
private function click takes nothing returns nothing
if GetPlayerState(GetOwningPlayer(udg_UnitBody[GetConvertedPlayerId(GetTriggerPlayer())]), PLAYER_STATE_RESOURCE_GOLD) >= 80 then
call SetPlayerStateBJ( GetOwningPlayer(udg_UnitBody[GetConvertedPlayerId(GetTriggerPlayer())]), PLAYER_STATE_RESOURCE_GOLD, ( GetPlayerState(GetOwningPlayer(udg_UnitBody[GetConvertedPlayerId(GetTriggerPlayer())]), PLAYER_STATE_RESOURCE_GOLD) - 80 ) )
call UnitAddItemByIdSwapped(udg_Items[1],udg_UnitBody[GetConvertedPlayerId(GetTriggerPlayer())] )
else
call DisplayTextToForce( GetForceOfPlayer(GetOwningPlayer(udg_UnitBody[GetConvertedPlayerId(GetTriggerPlayer())])), "Нету деняг!!" )
endif
endfunction
private function initSs takes integer id returns nothing
local trigger Click = CreateTrigger()
local trigger Click2 = CreateTrigger()
local player p = GetOwningPlayer(GetTriggerUnit())
set gameUIS = BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0)
set butS[1] = BlzCreateSimpleFrame("Pistol", gameUIS, 0)
call BlzFrameSetAbsPoint(butS[1], FRAMEPOINT_CENTER, 0.1, 0.5)
call BlzTriggerRegisterFrameEvent(Click, butS[1], FRAMEEVENT_CONTROL_CLICK)
call TriggerAddAction(Click, function click)
set text1[1] = BlzCreateFrame("PistolText1", gameUIS, 0, 0)
call BlzFrameSetAbsPoint(text1[1], FRAMEPOINT_CENTER, 0.1, 0.47)
set text2[1] = BlzCreateFrame("PistolText2", gameUIS, 0, 0)
call BlzFrameSetAbsPoint(text2[1], FRAMEPOINT_CENTER, 0.1, 0.46)
call BlzFrameSetVisible(butS[1], false)
call BlzFrameSetVisible(text1[1], false)
call BlzFrameSetVisible(text2[1], false)
if GetLocalPlayer() == p then
call BlzFrameSetVisible(butS[1], false)
call BlzFrameSetVisible(text1[1], false)
call BlzFrameSetVisible(text2[1], false)
endif
set Click = null
set Click2 = null
set p = null
endfunction