• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[vJASS] Spell Optimization

Status
Not open for further replies.
Level 9
Joined
Apr 23, 2011
Messages
460
Hey, this spell appears to work fine, doesn't seem to leak, and has no overall noticeable problems. But are there any underlying coding errors that I should look for?

JASS:
library EnergyPass initializer init uses RegisterPlayerUnitEvent
    globals 
        private constant string EYECANDY = ""
        private constant real TRANS = .2
        private constant integer SPELL_ID = 'EngP'
        private constant string ERROR = "|cffffcc00Your target is at max mana.|r"
    endglobals
    
    scope EnergyPass
        private function spell takes nothing returns nothing
            local unit caster = GetSpellAbilityUnit()
            local unit target = GetSpellTargetUnit()
            local real casterMana = GetUnitState(caster, UNIT_STATE_MANA)
            local real targetMana = GetUnitState(target, UNIT_STATE_MANA)
            local real manaTransfer = (casterMana * TRANS)
            call DestroyEffect(AddSpecialEffectTarget(EYECANDY, target, "origin"))
            call DestroyEffect(AddSpecialEffectTarget(EYECANDY, caster, "origin"))
            if targetMana != GetUnitState(target, UNIT_STATE_MAX_MANA) then
                call SetUnitState(caster, UNIT_STATE_MANA, casterMana - manaTransfer)
                call SetUnitState(target, UNIT_STATE_MANA, GetUnitState(target, UNIT_STATE_MANA) + manaTransfer)
            else
                call DisplayTimedTextToPlayer(GetOwningPlayer(caster), 0, 0, 8.5, ERROR)
            endif
            set caster = null
            set target = null
        endfunction
        
        function cast takes nothing returns nothing
            if GetSpellAbilityId() == SPELL_ID and   IsUnitAlly(GetSpellAbilityUnit(), GetOwningPlayer(GetSpellTargetUnit())) then
                call spell()
            endif
        endfunction
    endscope
    
    private function init takes nothing returns nothing
        call RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_SPELL_CAST, function cast)
    endfunction
endlibrary
 
Last edited:
Status
Not open for further replies.
Top