• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[vJASS] Spell doesn't work

Status
Not open for further replies.
Level 16
Joined
May 1, 2008
Messages
1,605
Moin moin =)

Cool we have a vJass Prefix now =D
Anyway I have a little problem with the following spell. You see in the create method,
that it should create a dummy, but it doesn't and I wondering why. After the "CreateUnit" part, you see that when casted, it should drain some life from the caster, but this works.
Also I checked the dummy, looks everything correct. Hope someone knows what to do and gives a little feedback^^

JASS:
library MeatBash initializer Init requires TimerUtils

    globals
        private constant integer SPELL_ID = 'A008'
        private constant integer DUMMY_SPELL_ID = 'A009'
        private constant integer DUMMY_ID = 'dumX'
        private constant integer MEATBASH_DUMMY = 'dum6'
        
        private constant attacktype A_TYPE = ATTACK_TYPE_NORMAL
        private constant damagetype D_TYPE = DAMAGE_TYPE_NORMAL
        private constant weapontype W_TYPE = WEAPON_TYPE_WHOKNOWS
        
        private constant string SFX = "Objects\\Spawnmodels\\Human\\HumanLargeDeathExplode\\HumanLargeDeathExplode.mdl" 
        private constant real PICK_RANGE = 125.
        private constant real MEAT_SPEED = 10.
        
        //
        
        private constant real LOOP_TIME = 0.04
        private constant group CONTAINER = CreateGroup()
        private          real  MIN_X
        private          real  MAX_X
        private          real  MIN_Y
        private          real  MAX_Y
    endglobals
    
    private function MBCost takes integer level returns real
        return 70. + 15. * level
    endfunction
    
    private function MBDamage takes integer level returns real
        return 80. * level
    endfunction
    
    private function MBRange takes integer level returns real
        return 615. + 35. * level
    endfunction
    
    //Configuration ends here
    
    private struct MeatBash
        unit    caster      = null
        real    c           = 0. //cost
        real    d           = 0. //damage
        real    r           = 0. //range
        real    f           = 0. //facing
        unit    m           = null
        real    x           = 0.
        real    y           = 0.
        
        private static method MBFilter takes nothing returns boolean
            local thistype this
            local unit u = GetFilterUnit()
            local unit uu
            
            if u != null and GetWidgetLife(u) >= 0.405 and IsUnitEnemy(u,GetOwningPlayer(.caster)) and IsUnitType(u,UNIT_TYPE_STRUCTURE) == false and IsUnitType(u,UNIT_TYPE_MAGIC_IMMUNE) == false then
                call DestroyEffect(AddSpecialEffect(SFX,GetUnitX(u),GetUnitY(u)))
                set uu = CreateUnit(GetOwningPlayer(.caster),DUMMY_ID,GetUnitX(u),GetUnitY(u),0.)
                call UnitAddAbility(uu,DUMMY_SPELL_ID)
                call IssueTargetOrder(uu,"slow",u)
                call UnitApplyTimedLife(uu,'BTFL',2.)
                call RemoveUnit(.m)
            endif
            return false
        endmethod
        
        private static method MBLoop takes nothing returns nothing
            local timer t = GetExpiredTimer()
            local thistype this = GetTimerData(t)
            local real x
            local real y
            local real dx = GetUnitX(.m) - .x
            local real dy = GetUnitY(.m) - .y
            local real cos = Cos(.f)
            local real sin = Sin(.f)
            
            if SquareRoot(dx*dx+dy*dy) <= .d and .m != null then
                set x = GetUnitX(.m) + MEAT_SPEED * cos
                set y = GetUnitY(.m) + MEAT_SPEED * sin
                call SetUnitX(.m,x)
                call SetUnitY(.m,y)
                call GroupEnumUnitsInRange(CONTAINER,GetUnitX(.m),GetUnitY(.m),PICK_RANGE,Condition(function MeatBash.MBFilter))
           elseif SquareRoot(dx*dx+dy*dy) > .d or .m == null or GetUnitX(.m) < MIN_X or GetUnitX(.m) > MAX_X or GetUnitY(.m) < MIN_Y or GetUnitY(.m) > MAX_Y then
                call RemoveUnit(.m)
                call .destroy()
                call ReleaseTimer(t)
            endif
        endmethod
        
        static method MBCreate takes unit caster returns thistype
            local thistype this = .allocate()
            local timer t = NewTimer()
            
            set .caster = caster
            set .c = MBCost(GetUnitAbilityLevel(.caster,SPELL_ID))
            set .d = MBDamage(GetUnitAbilityLevel(.caster,SPELL_ID))
            set .r = MBRange(GetUnitAbilityLevel(.caster,SPELL_ID))
            set .f = GetUnitFacing(.caster)
            set .m = CreateUnit(GetOwningPlayer(.caster),MEATBASH_DUMMY,GetUnitX(.caster),GetUnitX(.caster),f)
            set .x = GetUnitX(.caster)
            set .y = GetUnitY(.caster)
            if GetWidgetLife(.caster) > .c then
                call SetWidgetLife(.caster,GetWidgetLife(.caster) - .c)
            elseif GetWidgetLife(.caster) <= .c then
                call SetWidgetLife(.caster,1.)
            endif
            call SetTimerData(t,this)
            call TimerStart(t,LOOP_TIME,true,function MeatBash.MBLoop)
            return this
        endmethod
    endstruct
    
    private function MBCast takes nothing returns boolean
        if GetSpellAbilityId() == SPELL_ID then
            call MeatBash.MBCreate(GetTriggerUnit())
        endif
        return false
    endfunction

    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger()
        local integer i = 0
                
        loop
            exitwhen i == bj_MAX_PLAYER_SLOTS
            call TriggerRegisterPlayerUnitEvent(t,Player(i),EVENT_PLAYER_UNIT_SPELL_EFFECT,null)
            set i = i + 1
        endloop
        call TriggerAddCondition(t,Condition(function MBCast))
        set MIN_X = GetRectMinX(bj_mapInitialPlayableArea)
        set MAX_X = GetRectMaxX(bj_mapInitialPlayableArea)
        set MIN_Y = GetRectMinY(bj_mapInitialPlayableArea)
        set MAX_Y = GetRectMaxY(bj_mapInitialPlayableArea)

        call Preload(SFX)
        set t = null
    endfunction
endlibrary

Greetings and Peace
Dr. Boom
 
Status
Not open for further replies.
Top