Attribute Purchase System v1.0

This bundle is marked as useful / simple. Simplicity is bliss, low effort and/or may contain minor bugs.
This is a simple JASS system that when input into a map and configured to your specifications, will allow players in your map to purchase specific attributes with the simple ease of typing either "-bs" for strength, "-ba" for agility, or "-bi" for intellect, or whatever you want it to be if you decide to change it. The only thing i require is that if you use this system, please give me credit for it. In the script for all three attributes, it gives you detailed information on how to modify it.

NOTE: In order to use this, you must have a variable that stores all the heroes on your map. If you have a Hero based map, it is assumed you have one already. If you don't however, please review the JASS script Make a Hero in the map provided, or comment below and I will give you a GUI version of the script.

This script is very simple and should work once you modify it to fit into your map. If you have any questions or issues in setup please tell me, I'll try to help you fix it. If you see an optimization, feel free to PM me or comment on this, I'll be sure to check it and update it. Thank you.

JASS:
function GetStrengthCost takes nothing returns integer
    return 250
endfunction

function GetStrengthBonus takes nothing returns integer
    return 10
endfunction

function GetPlayerHeroStr takes integer i returns unit
    return udg_Hero[i]
endfunction

function Trig_Buy_Strength_Actions takes nothing returns nothing
    local player p = GetTriggerPlayer()
    local integer gold = GetPlayerState(p,PLAYER_STATE_RESOURCE_GOLD)
    local integer cost = GetStrengthCost()
    
    call SetHeroStr(GetPlayerHeroStr(GetPlayerId(p)),GetHeroStr(GetPlayerHeroStr(GetPlayerId(p)),false)+GetStrengthBonus()*(gold/cost), true)
    call SetPlayerState(p,PLAYER_STATE_RESOURCE_GOLD,gold-(gold/cost)*cost)
    
    set p = null
endfunction

function InitTrig_Buy_Strength takes nothing returns nothing
    local trigger t = CreateTrigger()
    local integer i = 0
    loop
        exitwhen i>11
        call TriggerRegisterPlayerChatEvent(t,Player(i),"-str",true)
        set i=i+1
    endloop
    call TriggerAddAction(t,function Trig_Buy_Strength_Actions)
    set t = null
endfunction

JASS:
function GetAgilityCost takes nothing returns integer
    return 250
endfunction

function GetAgilityBonus takes nothing returns integer
    return 10
endfunction

function GetPlayerHeroAgi takes integer i returns unit
    return udg_Hero[i]
endfunction

function Trig_Buy_Agility_Actions takes nothing returns nothing
    local player p = GetTriggerPlayer()
    local integer gold = GetPlayerState(p,PLAYER_STATE_RESOURCE_GOLD)
    local integer cost = GetAgilityCost()
    
    call SetHeroAgi(GetPlayerHeroAgi(GetPlayerId(p)),GetHeroAgi(GetPlayerHeroAgi(GetPlayerId(p)),false)+GetAgilityBonus()*(gold/cost), true)
    call SetPlayerState(p,PLAYER_STATE_RESOURCE_GOLD,gold-(gold/cost)*cost)
    
    set p = null
endfunction

function InitTrig_Buy_Agility takes nothing returns nothing
    local trigger t = CreateTrigger()
    local integer i = 0
    loop
        exitwhen i>11
        call TriggerRegisterPlayerChatEvent(t,Player(i),"-agi",true)
        set i=i+1
    endloop
    call TriggerAddAction(t,function Trig_Buy_Agility_Actions)
    set t = null
endfunction

JASS:
function GetIntellectCost takes nothing returns integer
    return 250
endfunction

function GetIntellectBonus takes nothing returns integer
    return 10
endfunction

function GetPlayerHeroInt takes integer i returns unit
    return udg_Hero[i]
endfunction

function Trig_Buy_Intellect_Actions takes nothing returns nothing
    local player p = GetTriggerPlayer()
    local integer gold = GetPlayerState(p,PLAYER_STATE_RESOURCE_GOLD)
    local integer cost = GetStrengthCost()
    
    call SetHeroInt(GetPlayerHeroInt(GetPlayerId(p)),GetHeroInt(GetPlayerHeroInt(GetPlayerId(p)),false)+GetIntellectBonus()*(gold/cost), true)
    call SetPlayerState(p,PLAYER_STATE_RESOURCE_GOLD,gold-(gold/cost)*cost)
    
    set p = null
endfunction

function InitTrig_Buy_Intellect takes nothing returns nothing
    local trigger t = CreateTrigger()
    local integer i = 0
    loop
        exitwhen i>11
        call TriggerRegisterPlayerChatEvent(t,Player(i),"-int",true)
        set i=i+1
    endloop
    call TriggerAddAction(t,function Trig_Buy_Intellect_Actions)
    set t = null
endfunction

This has been fixed and redone with help of Magtheridon96. Thankyou. Also I apologize for the missing MPI. I must have reverted it because I remember setting it but it is fixed now.

Keywords:
Attribute,Hero,System,Purchase, Attribute buying, Buy agility, Buy Strength, Buy Intellect.
Contents

Just another Warcraft III map (Map)

Reviews
12th Dec 2015 IcemanBo: For too long time as NeedsFix. Rejected. 23th Jul 2011 Bribe: Unnacceptable JASS names, these need to be prefixed. This also should not be custom script as there is nothing special about it: function...

Moderator

M

Moderator

12th Dec 2015
IcemanBo: For too long time as NeedsFix. Rejected.

23th Jul 2011
Bribe:

Unnacceptable JASS names, these need to be prefixed.
This also should not be custom script as there is nothing
special about it:

JASS:
function Trig_Make_a_Hero_Actions takes nothing returns nothing
set udg_Hero[0] = CreateUnit(Player(0),'Hpal',GetRectCenterX(gg_rct_Spawn),GetRectCenterY(gg_rct_Spawn), 260.)
call SetPlayerState(Player(0), PLAYER_STATE_RESOURCE_GOLD, 1000)
endfunction

//===========================================================================
function InitTrig_Make_a_Hero takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterTimerEventSingle(t, 0.00)
    call TriggerAddAction( t, function Trig_Make_a_Hero_Actions )
    set t = null
endfunction
 
Can you please post the code? (It's a requirement)

edit
I checked out the code.
You need to learn to align it better :p
I aligned it for you:

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


Tips:
1- You need to make things easily configurable (use globals) or if you want it to stay Jass and not vJass, you could use functions like:
JASS:
function GetStrengthCost takes nothing returns integer
    return 250
endfunction
(This applies to all 3 triggers)
2- You shouldn't repeat function calls. Use local variables instead.
For example, you should create a local player and set him to GetTriggerPlayer(). Then use that variable instead. (This applies to all 3 triggers)
3- Move the exitwhen line below the "set gold = ..." line. That way, you could just use exitwhen gold < GetStrengthCost() (This applies to all 3 triggers)
4- You don't need to do "set int = ...." or "set str = ..." or "set agi = ..." since you're only using that variable once..
5- Instead of constantly setting the player state to be less by 250 and increasing the hero's strength/intelligence/agility by 10, you could divide the players gold by the cost and increase the units strength by the integer you retreived from the previous equation and the bonus per purchase.
6- Your system isn't MPI

Here:
This would be much better:
JASS:
function GetStrengthCost takes nothing returns integer
    return 250
endfunction

function GetStrengthBonus takes nothing returns integer
    return 10
endfunction

function GetPlayerHero takes integer i returns unit
    return udg_Hero[i]
endfunction

function Trig_Buy_Strength_Actions takes nothing returns nothing
    local player p = GetTriggerPlayer()
    local integer gold = GetPlayerState(p,PLAYER_STATE_RESOURCE_GOLD)
    local integer cost = GetStrengthCost()
    
    call SetHeroStr(GetPlayerHero(GetPlayerId(p)),GetHeroStr(GetPlayerHero(GetPlayerId(p)),false)+GetStrengthBonus()*(gold/cost))
    call SetPlayerState(p,PLAYER_STATE_RESOURCE_GOLD,gold-(gold/cost)*cost)
    
    set p = null
endfunction

function InitTrig_Buy_Strength takes nothing returns nothing
    local trigger t = CreateTrigger()
    local integer i = 0
    loop
        exitwhen i>11
        call TriggerRegisterPlayerChatEvent(t,Player(i),"-bs",true)
        set i=i+1
    endloop
    call TriggerAddAction(t,function Trig_Buy_Strength_Actions)
    set t = null
endfunction

You should do something similar for the other triggers too...
 
Last edited:
Level 9
Joined
Apr 23, 2011
Messages
460
Your script is lacking in the fact that it Doesn't get the players current agility and only sets it to the scripts current running of agility. I see how your script is more optimum in the fact that it uses more functions to index variables, and I'll be sure to update it to be like this soon, but for now I'll leave it as it is because I do not have time right now, I have to leave the house for now. Thank you for helping me, I've just started learning jass 3 days ago.
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
You need to update the code in the post to reflect your latest changes.


Also, you should support buying an amount of a stat, for example 300 strength.


You should also make the commands configurable-
bs, ba, and bi aren't typically used. Normally str, agi, and int are used ^)^.


So, if a number is present in the string, buy either that charge or as much as can be bought. If no number is present, buy as much as can be bought.


Also, it wouldn't be too hard to make this MUI. You could buy the stats for the current selected units no? : )


For example, for every hero that's selected, you spread the stats out. If buying 300 and 6 heroes are selected, that's 50 for each hero. I think that's a better approach though I don't think anybody's done that yet =).
 
Level 9
Joined
Apr 23, 2011
Messages
460
I'll definately sit down and make this system for optimum and also more usable, I simply used this for my map and thought it would be useful. Perhaps some customizable script using booleans to disable functions like you were saying Nestharus. I'll definately revise it and make it alot better, but for now i think the current version is good enough to be used and modified as a base, with credit given of course for the base of it.
Edit: I used BA,BS,and BI because I saw it in some map, Idr. It might have been Heaven Vs Hell. Idr.
 
Top