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

Attribute Purchase system

Status
Not open for further replies.
Level 9
Joined
Apr 23, 2011
Messages
460
I was wondering how people make a script to deduct gold continuously if you type a string in, like in X Hero Siege. Whenever you typed "-bt" if you have multiple amounts of the gold needed to buy the item, it would keep subtracting. how do you do this (in Jass)
 
Level 9
Joined
Apr 23, 2011
Messages
460
Here are the scripts that I made, for each Attribute, with a comment on how to modify them.

JASS:
function Trig_Buy_Strength_Actions takes nothing returns nothing
local integer gold //This is for subtracting and keeping track of the user's gold
local integer str // This is for modifying the attribute.
loop
exitwhen GetPlayerState(GetTriggerPlayer(), PLAYER_STATE_RESOURCE_GOLD) < 250 //You can change 250 to whatever you want each charge to cost.
set gold = GetPlayerState(GetTriggerPlayer(), PLAYER_STATE_RESOURCE_GOLD) //Leave this line alone. Sets gold to their gold
call SetPlayerState(GetTriggerPlayer(), PLAYER_STATE_RESOURCE_GOLD, (gold - 250)) //Change the 250 to what you changed the other 250 to. This will subtract the gold
set str = (GetHeroStr(udg_Hero[GetPlayerId(GetTriggerPlayer())], false) + 10) // This line needs some editing. Change "udg_Hero" hero to whatever your hero variable in your map is (You need one). Change + 10 to whatever increment you want each purchase to be.
call SetHeroStr(udg_Hero[GetPlayerId(GetTriggerPlayer())], str, true) // Leave this line alone. It sets their attribute to what it should be after purchase.
endloop
endfunction

//===========================================================================
function InitTrig_Buy_Strength takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterPlayerChatEvent( t, Player(0), "-bs", true)
    call TriggerAddAction( t, function Trig_Buy_Strength_Actions )
    set t = null
endfunction
JASS:
function Trig_Buy_Agility_Actions takes nothing returns nothing
local integer gold //This is for subtracting and keeping track of the user's gold
local integer agi // This is for modifying the attribute.
loop
exitwhen GetPlayerState(GetTriggerPlayer(), PLAYER_STATE_RESOURCE_GOLD) < 250 //You can change 250 to whatever you want each charge to cost.
set gold = GetPlayerState(GetTriggerPlayer(), PLAYER_STATE_RESOURCE_GOLD) //Leave this line alone. Sets gold to their gold
call SetPlayerState(GetTriggerPlayer(), PLAYER_STATE_RESOURCE_GOLD, (gold - 250)) //Change the 250 to what you changed the other 250 to. This will subtract the gold
set agi = (GetHeroAgi(udg_Hero[GetPlayerId(GetTriggerPlayer())], false) + 10) // This line needs some editing. Change "udg_Hero" hero to whatever your hero variable in your map is (You need one). Change + 10 to whatever increment you want each purchase to be.
call SetHeroAgi(udg_Hero[GetPlayerId(GetTriggerPlayer())], agi, true) // Leave this line alone. It sets their attribute to what it should be after purchase.
endloop
endfunction

//===========================================================================
function InitTrig_Buy_Agility takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterPlayerChatEvent( t, Player(0), "-ba", true)
    call TriggerAddAction( t, function Trig_Buy_Agility_Actions )
    set t = null
endfunction
JASS:
function Trig_Buy_Intellect_Actions takes nothing returns nothing
local integer gold //This is for subtracting and keeping track of the user's gold
local integer int // This is for modifying the attribute.
loop
exitwhen GetPlayerState(GetTriggerPlayer(), PLAYER_STATE_RESOURCE_GOLD) < 250 //You can change 250 to whatever you want each charge to cost.
set gold = GetPlayerState(GetTriggerPlayer(), PLAYER_STATE_RESOURCE_GOLD) //Leave this line alone. Sets gold to their gold
call SetPlayerState(GetTriggerPlayer(), PLAYER_STATE_RESOURCE_GOLD, (gold - 250)) //Change the 250 to what you changed the other 250 to. This will subtract the gold
set int = (GetHeroInt(udg_Hero[GetPlayerId(GetTriggerPlayer())], false) + 10) // This line needs some editing. Change "udg_Hero" hero to whatever your hero variable in your map is (You need one). Change + 10 to whatever increment you want each purchase to be.
call SetHeroInt(udg_Hero[GetPlayerId(GetTriggerPlayer())], int, true) // Leave this line alone. It sets their attribute to what it should be after purchase. 
endloop
endfunction

//===========================================================================
function InitTrig_Buy_Intellect takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterPlayerChatEvent( t, Player(0), "-bi", true)
    call TriggerAddAction( t, function Trig_Buy_Intellect_Actions )
    set t = null
endfunction
 
Status
Not open for further replies.
Top