Chaosy
Tutorial Reviewer
- Joined
- Jun 9, 2011
- Messages
- 13,242
I was toying with the idea of having a module with onCast and onLoop functions in order to bootstrap a spell as quickly as possible without the standard repetitive boring steps.
My result had some undesirable lines of code which sadly are required, but overall I am pretty pleased with the result.
My question is if there is something similar already created? I checked the spell section quickly and did not find anything other than one of GUI. Does not have to be in wurst, I would be keenly interested in seeing how others have done it in vjass.
My result had some undesirable lines of code which sadly are required, but overall I am pretty pleased with the result.
My question is if there is something similar already created? I checked the spell section quickly and did not find anything other than one of GUI. Does not have to be in wurst, I would be keenly interested in seeing how others have done it in vjass.
Wurst:
package Hello
import SpellTemplate
class myCoolSpell extends Spell
real counter = 0
real interval = 1
real intervalCounter = 1
real totalTicks = 3
real dmg = 10
unit u
static integer id = 'AHfs'
construct(unit magician)
print(caster.getName() + " casting " + GetAbilityName(id))
u = magician
override function onLoop()
counter += 0.03
print(counter.toString())
if(counter >= interval * intervalCounter)
u.damageTarget(u, dmg)
if(intervalCounter == totalTicks)
destroy this
else
intervalCounter++
function onCast()
new myCoolSpell(myCoolSpell.caster)
init
setupSpell(myCoolSpell.id, Condition(function onCast))
// Testing MUI
for u in GetUnitsInRectAll(GetPlayableMapRect())
u.issuePointOrder("flamestrike", vec2(0, 0))
Wurst:
package Hello
import SpellTemplate
/*
Template spell, deals 10 damage every 1 second for 3 seconds.
Instructions:
1. import SpellTemplate
2. Make class which extends Spell
3. onCast(), onLoop() and getAbilityId() returns integer with the keyword override are required
4. the onCast function needs to create a new instance of your class. Make sure to use newInstance(yourInstance) afterwards
Otherwise your new instance wont have onLoop called.
5. on init make an instance of your class.
The first instance will merely make a trigger which executes when your specified spell is cast.
The following variables can be used in the onCast function
unit caster
vec2 targetPos
unit targetUnit
item targetItem
destructable targetDestructable
*/
class myCoolSpell extends Spell
real counter = 0
real interval = 1
real intervalCounter = 1
real totalTicks = 3
real dmg = 10
unit u
static integer id = 'AHfs'
override function getAbilityId() returns integer
return id
override function onCast()
thistype instance = newInstance(new myCoolSpell()) castTo thistype
print(GetUnitName(caster) + " casting " + GetAbilityName(id))
instance.u = caster
override function onLoop()
counter += 0.03
print(counter.toString())
if(counter >= interval * intervalCounter)
u.damageTarget(u, dmg)
if(intervalCounter == totalTicks)
destroy this
else
intervalCounter++
init
new myCoolSpell()
// Testing MUI
for u in GetUnitsInRectAll(GetPlayableMapRect())
u.issuePointOrder("flamestrike", vec2(0, 0))
Last edited: