System Attributes

trb92

Throwing science at the wall to see what sticks
Reaction score
142
Attributes

Purpose: To enable easy addition of stats on level up

Why I made this: The only other attribute addition system I found was by emjlr3, and it only worked for one hero per player. That doesn't work for my map, so I made this one. His also uses items to do the addition, whereas mine uses abilities contained within a spellbook.

Pros
Coded in JASS
Fully MUI
Leakless(As far as I know)

Cons
Adds a spellbook, so you need to have one ability slot free for it to go in

Requires
JassNewGen Pack

Importing instructions
  1. Copy over the four abilities, the three to increase stats and the spellbook containing them
  2. Copy this trigger to a trigger named "Attributes"
  3. Change the globals to suit your map

If you find any bugs or areas to improve, please tell me.

The code:
JASS:
library Attributes initializer Init
//Attributes system
//Made by The_Rper@Lordaeron(USWest)
//[email protected]
//=======================================================
//Purpose: To enable easy addition of stats on level up
//=======================================================
//Pros
//Coded in JASS
//Fully MUI
//Leakless(As far as I know)
//=======================================================
//Cons
//Adds a spellbook, so you need to have one ability slot free for it to go in
//=======================================================
//Requires
//JassNewGen Pack
//=======================================================
//Importing instructions
//1. Copy over the four abilities, the three to increase stats and the spellbook containing them
//2. Copy this trigger to a trigger named "Attributes"
//3. Change the globals to suit your map

globals
private constant integer STRID = 'A000' 
//Rawcode of ability that adds strength

private constant integer INTID = 'A001' 
//Rawcode of ability that adds agility

private constant integer AGIID = 'A002' 
//Rawcode of ability that adds intelligence

private constant integer BOOKID = 'A003'
//Rawcode of the spellbook containing the other three spells

private constant integer POINTS_PER_LEVEL = 4 
//How many times you can increase attributes per level

private constant string LEVEL_UP_STRING = "You have leveled up. Use the three abilities you've gained to increase your stats."
//A string to display to the player when their hero levels up

private constant boolean DISPLAY_POINTS_REMAINING = true
//Wether to display how many points a unit has remaining when it uses a point

private constant boolean DISPLAY_LEVEL_UP_STRING = true
//Wether to display a string upon level up.

//Don't change these globals, they are needed
private integer array PointsLeft
private trigger IncreaseStats = CreateTrigger()
private group IgnoredUnits = CreateGroup()
endglobals

private function H2I takes handle h returns integer//Required for keeping track of how many points a unit has left to use
    return h
    return 0
endfunction

//Returns how many points a unit has left to use
function GetAttributePointsRemaining takes unit u returns integer 
    return PointsLeft[H2I(u)-0x100000]
endfunction

 //Causes the system to ignore a specific unit, it affects all heroes other then the ones passed to this function
public function IgnoreUnit takes unit u returns nothing
    call GroupAddUnit(IgnoredUnits,u)
endfunction

private function AddStat takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local integer i = H2I(u)-0x100000
    if GetSpellAbilityId() == AGIID then
        call SetHeroAgi(u,GetHeroAgi(u,true) + 1,true)
    elseif GetSpellAbilityId() == INTID then
        call SetHeroInt(u,GetHeroInt(u,true) + 1,true)
    elseif GetSpellAbilityId() == STRID then
        call SetHeroStr(u,GetHeroStr(u,true) + 1,true)
    endif
    set PointsLeft<i> = PointsLeft<i> - 1
    if PointsLeft<i> == 0 then
        call UnitRemoveAbility(u,BOOKID)
    endif
    if DISPLAY_POINTS_REMAINING then
        call DisplayTextToPlayer(GetOwningPlayer(u),0.,0.,&quot;You have &quot; + I2S(GetAttributePointsRemaining(u)) + &quot; attribute points left to spend.&quot;)
    endif
    set u = null
endfunction

private function LevelUp takes nothing returns nothing
    local unit u = GetTriggerUnit()
    call UnitAddAbility(u,BOOKID)
    if DISPLAY_LEVEL_UP_STRING then
        call DisplayTextToPlayer(GetOwningPlayer(u),0.,0.,LEVEL_UP_STRING)
    endif
    set PointsLeft[H2I(u)-0x100000] = PointsLeft[H2I(u)-0x100000] + POINTS_PER_LEVEL
    set u = null
endfunction

private function Conditions takes nothing returns boolean
    return GetSpellAbilityId() == AGIID or GetSpellAbilityId() == INTID or GetSpellAbilityId() == STRID
endfunction

private function Ignore takes nothing returns boolean
    return IsUnitInGroup(GetTriggerUnit(),IgnoredUnits) == false
endfunction

private function True takes nothing returns boolean
    return true
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    local trigger t = CreateTrigger(  )
    local integer i = 0
    loop
        exitwhen i &gt; 12
        call TriggerRegisterPlayerUnitEvent(t,Player(i),EVENT_PLAYER_HERO_LEVEL,Condition(function True))
        call TriggerRegisterPlayerUnitEvent(IncreaseStats,Player(i),EVENT_PLAYER_UNIT_SPELL_EFFECT,Condition(function True))
        set i = i + 1
    endloop
    call TriggerAddCondition(t,Condition(function Ignore))
    call TriggerAddCondition(IncreaseStats,Condition(function Conditions))
    call TriggerAddAction(t, function LevelUp )
    call TriggerAddAction(IncreaseStats,function AddStat)
    set t = null
endfunction

endlibrary</i></i></i>
 

Attachments

  • Attribute Increase System v1.0.w3x
    21 KB · Views: 160

Romek

Super Moderator
Reaction score
963
Interesting, and very useful.

JASS:
private function True takes nothing returns boolean
    return true
endfunction


You can get rid of that and use "null" as the argument where it is needed.
 

Larcenist

REP: Respect, Envy, Prosperity?
Reaction score
211
Passing null as a boolexpr results in a leak.

JASS:
private constant integer POINTS_PER_LEVEL = 4 
//How many times you can increase attributes per level

private constant string LEVEL_UP_STRING = &quot;You have leveled up. Use the three abilities you&#039;ve gained to increase your stats.&quot;


POINTS_PER_LEVEL is 4 while the text says three? ^^
 

trb92

Throwing science at the wall to see what sticks
Reaction score
142
>You can get rid of that and use "null" as the argument where it is needed.

Yeah, I could do that if I want to leak a boolexpr. However, then I couldn't call this system "leakless".
So I'm not going to.

>POINTS_PER_LEVEL is 4 while the text says three? ^^
Three different abilities is what it means. One to increase str, one to increase int, one for agi. Three abilities.
 

Tukki

is Skeleton Pirate.
Reaction score
29
>You can get rid of that and use "null" as the argument where it is needed.

Will not leak. It doesn't even leak in group functions -- it only grabs memory (and returns it after some time) which is why people think it's a leak.

Else the system looks nice :)
 

trb92

Throwing science at the wall to see what sticks
Reaction score
142
Will not leak. It doesn't even leak in group functions -- it only grabs memory (and returns it after some time) which is why people think it's a leak.

Else the system looks nice :)

Meh. I'm leaving it with the True function, as I've seen alot of posts that disagree with you.

Thanks to the people that said this looks good.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top