• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[vJASS] Just a piece of code

Status
Not open for further replies.
Level 7
Joined
Apr 5, 2011
Messages
245
It's a piece of code that performs Magina's Mana Void. It works well but how does it look at all and do you see leaks I have not seen?

Updated:
JASS:
library SpellManaVoid requires Assist

//=== Settings ===
globals
    private constant integer ABILCODE = 'X003'
    private constant string SFX = "Abilities\\Spells\\Human\\DispelMagic\\DispelMagicTarget.mdl"
//----------------
    private constant real RADIUS = 150
endglobals
    struct SpellManaVoid extends array
        private static real array DAMAGE_KOEF
        private static method onInit takes nothing returns nothing
            set DAMAGE_KOEF[1] = 0.6
            set DAMAGE_KOEF[2] = 0.85
            set DAMAGE_KOEF[3] = 1.1
        endmethod
//----------------
        private static method dealDamage takes nothing returns boolean
            set Assist.workUnit = GetFilterUnit()
            if IsUnitEnemy(Assist.workUnit, Event.triggerPlayer) and not IsUnitType(Assist.workUnit, UNIT_TYPE_MECHANICAL) and not IsUnitType(Assist.workUnit, UNIT_TYPE_MAGIC_IMMUNE) then
                call vGDC.dealDamage(Event.triggerUnit, Assist.workUnit, Assist.workReal, MAGIC)
            endif
            return false
        endmethod
    
        static method checkEffect takes nothing returns nothing
            local real x
            local real y
            if Event.abilcode == ABILCODE then
                set x = GetWidgetX(Event.targetUnit)
                set y = GetWidgetY(Event.targetUnit)
                call DestroyEffect(AddSpecialEffect(SFX, x, y))
                set Assist.workReal = (GetUnitState(Event.targetUnit, UNIT_STATE_MAX_MANA) - GetUnitState(Event.targetUnit, UNIT_STATE_MANA)) * DAMAGE_KOEF[GetUnitAbilityLevel(Event.triggerUnit, ABILCODE)]
                call GroupEnumUnitsInRange(Assist.workGroup, x, y, RADIUS, Condition(function thistype.dealDamage))
            endif
        endmethod
    endstruct
endlibrary
Old:
JASS:
library SpellManaVoid

//=== Settings ===
globals
    private constant integer ABILCODE = 'X003'
    private constant real RADIUS = 150
    private constant string SFX = "Abilities\\Spells\\Human\\DispelMagic\\DispelMagicTarget.mdl"
endglobals
    struct SpellManaVoid
        private static real array DAMAGE_KOEF
        private static method onInit takes nothing returns nothing
            set DAMAGE_KOEF[1] = 0.6
            set DAMAGE_KOEF[2] = 0.85
            set DAMAGE_KOEF[3] = 1.1
        endmethod
//----------------
        private static real damage
        private static group g = CreateGroup()

        private static method dealDamage takes nothing returns boolean
            local unit u = GetFilterUnit()
            if IsUnitEnemy(u, p) and not IsUnitType(u, UNIT_TYPE_MECHANICAL) and not IsUnitType(u, UNIT_TYPE_MAGIC_IMMUNE) then
                call vGDC.dealDamage(Event.triggerUnit, u, damage, MAGIC)
            endif
            set u = null
            return false
        endmethod
    
        static method checkEffect takes nothing returns nothing
            local real x
            local real y
            if Event.abilcode == ABILCODE then
                set x = GetWidgetX(Event.targetUnit)
                set y = GetWidgetY(Event.targetUnit)
                call DestroyEffect(AddSpecialEffect(SFX, x, y))
                set damage = (GetUnitState(Event.targetUnit, UNIT_STATE_MAX_MANA) - GetUnitState(Event.targetUnit, UNIT_STATE_MANA)) * DAMAGE_KOEF[GetUnitAbilityLevel(Event.triggerUnit, ABILCODE)]
                call ClearGroup(g)
                call GroupEnumUnitsInRange(g, x, y, RADIUS, Condition(function thistype.dealDamage))
                call DestroyGroup(g)
                set g = null
            endif
        endmethod
    endstruct
endlibrary
 
Last edited:
:)

  • You should just use one global group. See this tutorial for the reason why and how to fix it.
  • When you do set p = GetOwningPlayer(Event.triggerUnit), you can actually just use set p = GetTriggerPlayer() (I assume the event is a unit starts the effect of an ability) It is a useful little tip.
  • Finally, since you aren't actually using the struct features of allocation/deallocation, you can make it extend array:
    JASS:
    struct SpellManaVoid extends array
    This is very useful when you know you won't use any allocation/deallocation, because then it will remove a bunch of extra, unnecessary code. :)

Overall, good job. No real glaring errors.

P.S. Usually we indent anything within a library block. (like your globals block) This really doesn't matter, because it depends on whether or not it is your style. Just mentioning it hehe.
 
Status
Not open for further replies.
Top