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
- Copy over the four abilities, the three to increase stats and the spellbook containing them
- Copy this trigger to a trigger named "Attributes"
- 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 = 039;A000039;
//Rawcode of ability that adds strength
private constant integer INTID = 039;A001039;
//Rawcode of ability that adds agility
private constant integer AGIID = 039;A002039;
//Rawcode of ability that adds intelligence
private constant integer BOOKID = 039;A003039;
//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 you039;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.,"You have " + I2S(GetAttributePointsRemaining(u)) + " attribute points left to spend.")
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 > 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>