Cokemonkey11
Spell Reviewer
- Joined
- May 9, 2006
- Messages
- 3,575
TemporaryHeroAttribute
Preface:
I don't know if any system exists which does this, but if there is a public one, I doubt it's this simple/efficient.
I've created this to aid the creation of a spell which I'm helping create for a fellow hive user. If anyone has a request/bug report, I'd be happy to update it.
Pre-requisites:
The script requires no other libraries to function, but as it is written in vJass, it DOES require JassHelper (Though I recommend just compiling with JNGP).
API:
These constants are word representations of ascii integers, 'A', 'S', and 'I', that correspond to the three stat types in warcraft 3. Strictly speaking, they let the client use the stat types within the system (including in the 'add' function) if they prefer to avoid this ascii codes.
This is a constant that controls how often a global timer refreshes to update any outstanding stat modifications. This can be as accurate or blunt as you like it, but generally I suggest values in the range [1./60. , 1./2.]
This is the only function in the snippet. Use it to temporarily modify a hero stat. Put simply, it will receive <value> <attribute> for <duration> seconds. The ASCII codes 'A', 'S', and 'I' are interchangeable with "tempoaryHeroAttribute_AGILITY" as well as the same with strength and intelligence.
The script:
Change Log:
2012.06.09 The script no longer creates an instance if a non-attribute is specified.
2012.06.01 #2 Updated the duration check to <= just because.
2012.06.01 Updated CamelCase and fixed a decrement bug.
2012.05.31 Changed one line "debug else". Very minor edit.
2012.05.30 #2 - First update: Changed the name slightly and made the script also work with ASCII representations ('A', 'S', and 'I'). Additionally, debug messages use the debug keyword.
2012.05.30 - Initial submission to Hive: Jass Resources: Submissions
Special Thanks:
Author's Notes:
I understand this is a simple system, but it should anyway be very useful, if not as a snippet, at least for a learning resource. This is an excellent introduction to a linear stack if you're at "that stage" of learning vJass.
Pastebin Mirror (Newest First):
http://pastebin.com/6BfRedJy
http://pastebin.com/GZ8QQ0tV
http://pastebin.com/iWB2kLAy
http://pastebin.com/gU5qTu2L
http://pastebin.com/XebbjbQG
http://pastebin.com/7sVTsvWS
Preface:
I don't know if any system exists which does this, but if there is a public one, I doubt it's this simple/efficient.
I've created this to aid the creation of a spell which I'm helping create for a fellow hive user. If anyone has a request/bug report, I'd be happy to update it.
Pre-requisites:
The script requires no other libraries to function, but as it is written in vJass, it DOES require JassHelper (Though I recommend just compiling with JNGP).
API:
JASS:
integer AGILITY
integer STRENGTH
integer INTELLIGENCE
JASS:
TemporaryHeroAttribute_AGILITY
TemporaryHeroAttribute_STRENGTH
TemporaryHeroAttribute_INTELLIGENCE
real TIMER_FIDELITY
This is a constant that controls how often a global timer refreshes to update any outstanding stat modifications. This can be as accurate or blunt as you like it, but generally I suggest values in the range [1./60. , 1./2.]
function add takes unit hero, integer attribute, integer value, real duration returns nothing
TemporaryHeroAttribute_add(<hero>,('A' | 'S' | 'I'),<positve or negative stat modifier>,<real positive duration>)
This is the only function in the snippet. Use it to temporarily modify a hero stat. Put simply, it will receive <value> <attribute> for <duration> seconds. The ASCII codes 'A', 'S', and 'I' are interchangeable with "tempoaryHeroAttribute_AGILITY" as well as the same with strength and intelligence.
The script:
JASS:
library TemporaryHeroAttribute
private struct attribDat
integer attribute
integer value
real duration
unit hero
endstruct
globals
public constant integer AGILITY='A'
public constant integer STRENGTH='S'
public constant integer INTELLIGENCE='I'
private constant real TIMER_FIDELITY=1./10.
private attribDat array attribDB
private integer dbIndex=-1
private timer time=CreateTimer()
endglobals
private function p takes nothing returns nothing
local attribDat tempDat
local integer index=0
loop
exitwhen index>dbIndex
set tempDat=attribDB[index]
set tempDat.duration=tempDat.duration-TIMER_FIDELITY
if tempDat.duration<=0. then
if tempDat.attribute==AGILITY then
call SetHeroAgi(tempDat.hero,GetHeroAgi(tempDat.hero,false)-tempDat.value,true)
elseif tempDat.attribute==STRENGTH then
call SetHeroStr(tempDat.hero,GetHeroStr(tempDat.hero,false)-tempDat.value,true)
elseif tempDat.attribute==INTELLIGENCE then
call SetHeroInt(tempDat.hero,GetHeroInt(tempDat.hero,false)-tempDat.value,true)
endif
call tempDat.destroy()
set attribDB[index]=attribDB[dbIndex]
set dbIndex=dbIndex-1
set index=index-1
if dbIndex==-1 then
call PauseTimer(time)
endif
endif
set index=index+1
endloop
endfunction
public function add takes unit hero, integer attribute, integer value, real duration returns nothing
local attribDat tempDat
if attribute==AGILITY then
call SetHeroAgi(hero,GetHeroAgi(hero,false)+value,true)
elseif attribute==STRENGTH then
call SetHeroStr(hero,GetHeroStr(hero,false)+value,true)
elseif attribute==INTELLIGENCE then
call SetHeroInt(hero,GetHeroInt(hero,false)+value,true)
else
debug call BJDebugMsg("|cff990000tempModifyHeroAttrib:|r Unrecognized attribute integer!")
return
endif
set tempDat=attribDat.create()
set tempDat.attribute=attribute
set tempDat.value=value
set tempDat.duration=duration
set tempDat.hero=hero
set dbIndex=dbIndex+1
set attribDB[dbIndex]=tempDat
if dbIndex==0 then
call TimerStart(time,TIMER_FIDELITY,true,function p)
endif
endfunction
endlibrary
Change Log:
2012.06.09 The script no longer creates an instance if a non-attribute is specified.
2012.06.01 #2 Updated the duration check to <= just because.
2012.06.01 Updated CamelCase and fixed a decrement bug.
2012.05.31 Changed one line "debug else". Very minor edit.
2012.05.30 #2 - First update: Changed the name slightly and made the script also work with ASCII representations ('A', 'S', and 'I'). Additionally, debug messages use the debug keyword.
2012.05.30 - Initial submission to Hive: Jass Resources: Submissions
Special Thanks:
- Bribe for suggesting the use of ASCII conversion.
- Magtheridon96 for pointing out a decrement bug in my stack logic.
- -Kobas- for creating a map submission template, which turned out useful for system submissions as well.
- Vexorian for developing JassHelper. Without vJass, I almost certainly would not still be scripting for wc3.
- The various developers of JNGP including PitzerMike and MindworX. Integrating JassHelper and TESH is a godsend.
Author's Notes:
I understand this is a simple system, but it should anyway be very useful, if not as a snippet, at least for a learning resource. This is an excellent introduction to a linear stack if you're at "that stage" of learning vJass.
Pastebin Mirror (Newest First):
http://pastebin.com/6BfRedJy
http://pastebin.com/GZ8QQ0tV
http://pastebin.com/iWB2kLAy
http://pastebin.com/gU5qTu2L
http://pastebin.com/XebbjbQG
http://pastebin.com/7sVTsvWS
Last edited: