- Joined
- Apr 23, 2011
- Messages
- 460
I'll try to make this one of my last (there will be probably more) posts for just looking over my code to make sure I'm doing things right. Any comments? Suggestions?
JASS:
library ManaStrikes initializer init uses RegisterPlayerUnitEvent
globals
private constant real DAMAGEBONUS = .05
private constant real DRAINAMOUNT = .025
private constant integer PROBPROC = 5
private constant integer SPELL_ID = 'MaSt'
endglobals
scope ManaStrikes
private function damage takes unit caster, unit target, integer mana returns nothing
local real damageDealt = mana * DAMAGEBONUS
local real manaDrained = mana * DRAINAMOUNT
call UnitDamageTarget(caster, target, damageDealt, true, true, ATTACK_TYPE_MAGIC, DAMAGE_TYPE_MAGIC, WEAPON_TYPE_WHOKNOWS)
call SetUnitState(caster, UNIT_STATE_MANA, GetUnitState(caster, UNIT_STATE_MANA) - manaDrained)
endfunction
private function spell takes nothing returns nothing
local unit caster = GetAttacker()
local unit target = GetTriggerUnit()
local integer mana = R2I(GetUnitState(caster, UNIT_STATE_MANA))
local integer probable = GetUnitAbilityLevel(caster, SPELL_ID) * PROBPROC
local integer random = GetRandomInt(1, 100)
if random <= probable then
call damage(caster, target, mana)
endif
set caster = null
set target = null
endfunction
function castMS takes nothing returns nothing
local unit attacker = GetAttacker()
if GetUnitAbilityLevel(attacker, SPELL_ID) >= 1 and not IsUnitAlly(attacker, GetTriggerPlayer()) then
call spell()
endif
set attacker = null
endfunction
endscope
private function init takes nothing returns nothing
call RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_ATTACKED, function castMS)
endfunction
endlibrary
Last edited: