[Lua] Problem with spell

Status
Not open for further replies.
Level 25
Joined
Jun 11, 2017
Messages
760
Hey guys, I have next spell that does alot of things depending on targets global group (animals, humans, etc).
But right now I don't know why it doesn't work - my spell simply doesn't call and I don't know why.
I tried different approaches but currently I don't found the answer.
  • Init 10 Spells
  • Events
    • Time - Elapsed game time is 0.55 seconds
  • Conditions
  • Actions
    • Custom script: RodOfDiscordEffect()
Lua:
function RodOfDiscordEffect()
    local function AbilityId(id)
        return id:byte(1) * 0x1000000 + id:byte(2) * 0x10000 + id:byte(3) * 0x100 + id:byte(4)
    end
   
    --SFX Settings:
    local ABILITY_ID = AbilityId('A00V')
    local ExplosionEffect = 'Abilities\\Spells\\Orc\\WarStomp\\WarStompCaster.mdl'
    local UnitAshesEffect = 'Abilities\\Spells\\Human\\FlameStrike\\FlameStrike1.mdl'
    local TransformationEffect = 'Abilities\\Spells\\Orc\\FeralSpirit\\feralspiritdone.mdl'
    local LightningEffect = 'Abilities\\Spells\\Other\\Monsoon\\MonsoonBoltTarget.mdl'
   
    -- Event & Trigger Creation
    local TT = CreateTrigger()
    for i = 0, bj_MAX_PLAYER_SLOTS, 1 do
        TriggerRegisterPlayerUnitEvent(TT, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT)
    end
    TriggerAddCondition(TT, Condition(function()
        return GetSpellAbilityID() == ABILITY_ID
    end))
    TriggerAddAction(TT, function()
        local TargetUnit = GetSpellTargetUnit()
        local UnitX = GetUnitX(TargetUnit)
        local UnitY = GetUnitY(TargetUnit)
        local UnitOwner = GetOwningPlayer(TargetUnit)
   
        if IsUnitInGroup(TargetUnit, udg_DiscordAnimal) then
            SetUnitFacingToFaceUnitTimed(TargetUnit, GetTriggerUnit(), 0.0)
            local randomizeEffect = GetRandomInt(1, 7)
            if randomizeEffect == 1 then
                local scaleUnit = 100;
                for i = 1, 15, 2 do
                    SetUnitScale(TargetUnit, scaleUnit + i, scaleUnit + i, scaleUnit + i)
                    BlzSetUnitMaxHP(TargetUnit, BlzGetUnitMaxHP(TargetUnit) + i * 10)
                end
                SetUnitExploded(TargetUnit, true)
                DestroyEffect(AddSpecialEffect(ExplosionEffect, UnitX, UnitY))
                KillUnit(TargetUnit)
            elseif randomizeEffect == 2 then
                local scaleUnit = 100
                for i = 1, 25, 3 do
                    SetUnitScale(TargetUnit, scaleUnit - i, scaleUnit - i, scaleUnit - i)
                    BlzSetUnitMaxHP(TargetUnit, BlzGetUnitMaxHP(TargetUnit) - i * 2)
                end
                SetUnitExploded(TargetUnit, true)
                KillUnit(TargetUnit)
                AddSpecialEffect(UnitAshesEffect, UnitX, UnitY)
            elseif randomizeEffect == 3 then
                local heroType = GetUnitTypeId(FourCC(GetTriggerUnit()))
                DestroyEffect(AddSpecialEffect(TransformationEffect, UnitX, UnitY))
                ReplaceUnitBJ(TargetUnit, heroType, 3)
                GroupRemoveUnit(udg_DiscordAnimal)
                RemoveUnit(TargetUnit)
            elseif randomizeEffect == 4 then
                local elfReplaceUnit = 'n00M'
                DestroyEffect(AddSpecialEffect(TransformationEffect, UnitX, UnitY))
                ReplaceUnitBJ(TargetUnit, elfReplaceUnit, 3)
                GroupRemoveUnit(udg_DiscordAnimal)
                SetUnitExploded(TargetUnit, true)
                DestroyEffect(AddSpecialEffect(ExplosionEffect, UnitX, UnitY))
                KillUnit(TargetUnit)
            elseif randomizeEffect == 5 then
            elseif randomizeEffect == 6 then
                local dummy = CreateUnit(Player(1), 'u001', UnitX, UnitY, 0)
                UnitAddAbility(dummy, FourCC('A00T'))
                UnitShareVision(TargetUnit, GetLocalPlayer(), true)
                IssueTargetOrderById(dummy, 852074, TargetUnit)
                UnitShareVision(TargetUnit, GetLocalPlayer(), false)
            else
                DestroyEffect(AddSpecialEffect(LightningEffect, UnitX, UnitY))
                UnitAddAbility(TargetUnit, FourCC('A00U'))
            end
        end
        if IsUnitInGroup(TargetUnit, udg_DiscordUndead) then
            SetUnitFacingToFaceUnitTimed(TargetUnit, GetTriggerUnit(), 0.0)
            local randomizeEffect = GetRandomInt(1, 4)
            if randomizeEffect == 1 then
                SetUnitExploded(TargetUnit, true)
                DestroyEffect(AddSpecialEffect(UnitAshesEffect, UnitX, UnitY))
                KillUnit(TargetUnit)
            elseif randomizeEffect == 2 then
                local unitType = GetUnitTypeId(FourCC('n00P'))
                DestroyEffect(AddSpecialEffect(TransformationEffect, UnitX, UnitY))
                local MorphedUnit = ReplaceUnitBJ(TargetUnit, unitType, 3)
                SetUnitExploded(MorphedUnit, true)
                DestroyEffect(AddSpecialEffect(ExplosionEffect, UnitX, UnitY))
                KillUnit(MorphedUnit)
            end
        end
    end)
end
 

Uncle

Warcraft Moderator
Level 69
Joined
Aug 10, 2018
Messages
7,195
Is this actually necessary?
Lua:
    local function AbilityId(id)
        return id:byte(1) * 0x1000000 + id:byte(2) * 0x10000 + id:byte(3) * 0x100 + id:byte(4)
    end

I think you need to be using FourCC:
Lua:
local ABILITY_ID = FourCC("A00V")

And I'm pretty sure you want to replace all instances of single quotation marks ' ' with double quotation marks " ".
Also, you need FourCC() when referencing Id's.

I'm no Lua expert though so I could be wrong.
 
Last edited:
Level 25
Joined
Jun 11, 2017
Messages
760
Is this actually necessary?
Lua:
    local function AbilityId(id)
        return id:byte(1) * 0x1000000 + id:byte(2) * 0x10000 + id:byte(3) * 0x100 + id:byte(4)
    end

I think you need to be using FourCC:
Lua:
local ABILITY_ID = FourCC("A00V")

And I'm pretty sure you want to replace all instances of single quotation marks ' ' with double quotation marks " ".
Also, you need FourCC() when referencing Id's.

I'm no Lua expert though so I could be wrong.

This local function is from old things, I'll remove it;

You can just add some print statements to understand which parts aren't working

You need to narrow down the problem more
I tried to use print() in different cases: before first if statement, in first statement…
So I figured out that spell really doesn't initializate - it doesn't do anything.
And I started to think that I should re-work it by using [Lua] Global Initialization...
 
Level 25
Joined
Jun 11, 2017
Messages
760
Hurray, it works!
I decided to use tips from [Lua] Global Initialization and changed my spell into something like these:
Lua:
do
    --Settings:
    local Ability = FourCC("ARod")
    local ExplosionEffect = "Abilities\\Spells\\Orc\\WarStomp\\WarStompCaster.mdl"
    local UnitAshesEffect = "Abilities\\Spells\\Human\\FlameStrike\\FlameStrike1.mdl"
    local TransformationEffect = "Abilities\\Spells\\Orc\\FeralSpirit\\feralspiritdone.mdl"
    local LightningEffect = "Abilities\\Spells\\Other\\Monsoon\\MonsoonBoltTarget.mdl"
    onInit(function()
        RegisterSpellEffectEvent(Ability, function()         
            -- Event & Trigger Creation
            local TargetUnit = GetSpellTargetUnit()
            local UnitX = GetUnitX(TargetUnit)
            local UnitY = GetUnitY(TargetUnit)
            local UnitOwner = GetOwningPlayer(TargetUnit)
            print("Test")
        
            if IsUnitInGroup(TargetUnit, udg_DiscordAnimal) == true then
                print("YES!")
                SetUnitFacingToFaceUnitTimed(TargetUnit, GetTriggerUnit(), 0.0)
                local randomizeEffect = GetRandomInt(1, 7)
                if randomizeEffect == 1 then
                    local scaleUnit = 100;
                    for i = 1, 15, 2 do
                        SetUnitScale(TargetUnit, scaleUnit + i, scaleUnit + i, scaleUnit + i)
                        BlzSetUnitMaxHP(TargetUnit, BlzGetUnitMaxHP(TargetUnit) + i * 10)
                    end
                    SetUnitExploded(TargetUnit, true)
                    DestroyEffect(AddSpecialEffect(ExplosionEffect, UnitX, UnitY))
                    KillUnit(TargetUnit)
                elseif randomizeEffect == 2 then
                    local scaleUnit = 100
                    for i = 1, 25, 3 do
                        SetUnitScale(TargetUnit, scaleUnit - i, scaleUnit - i, scaleUnit - i)
                        BlzSetUnitMaxHP(TargetUnit, BlzGetUnitMaxHP(TargetUnit) - i * 2)
                    end
                    SetUnitExploded(TargetUnit, true)
                    KillUnit(TargetUnit)
                    AddSpecialEffect(UnitAshesEffect, UnitX, UnitY)
                elseif randomizeEffect == 3 then
                    local heroType = GetUnitTypeId(FourCC(GetTriggerUnit()))
                    DestroyEffect(AddSpecialEffect(TransformationEffect, UnitX, UnitY))
                    ReplaceUnitBJ(TargetUnit, heroType, 3)
                    GroupRemoveUnit(udg_DiscordAnimal)
                    RemoveUnit(TargetUnit)
                elseif randomizeEffect == 4 then
                    local elfReplaceUnit = FourCC("n00M")
                    DestroyEffect(AddSpecialEffect(TransformationEffect, UnitX, UnitY))
                    local MorphedUnit = ReplaceUnitBJ(TargetUnit, elfReplaceUnit, 3)
                    GroupRemoveUnit(udg_DiscordAnimal)
                    SetUnitExploded(MorphedUnit, true)
                    DestroyEffect(AddSpecialEffect(ExplosionEffect, UnitX, UnitY))
                    KillUnit(MorphedUnit)
                elseif randomizeEffect == 5 then
                elseif randomizeEffect == 6 then
                    local dummy = CreateUnit(Player(1), "u001", UnitX, UnitY, 0)
                    UnitAddAbility(dummy, FourCC("A00T"))
                    UnitShareVision(TargetUnit, GetLocalPlayer(), true)
                    IssueTargetOrderById(dummy, 852074, TargetUnit)
                    UnitShareVision(TargetUnit, GetLocalPlayer(), false)
                else
                    DestroyEffect(AddSpecialEffect(LightningEffect, UnitX, UnitY))
                    UnitAddAbility(TargetUnit, FourCC("A00U"))
                end
            end
            if IsUnitInGroup(TargetUnit, udg_DiscordUndead) then
                SetUnitFacingToFaceUnitTimed(TargetUnit, GetTriggerUnit(), 0.0)
                local randomizeEffect = GetRandomInt(1, 4)
                if randomizeEffect == 1 then
                    SetUnitExploded(TargetUnit, true)
                    DestroyEffect(AddSpecialEffect(UnitAshesEffect, UnitX, UnitY))
                    KillUnit(TargetUnit)
                elseif randomizeEffect == 2 then
                    local unitType = GetUnitTypeId(FourCC("n00P"))
                    DestroyEffect(AddSpecialEffect(TransformationEffect, UnitX, UnitY))
                    local MorphedUnit = ReplaceUnitBJ(TargetUnit, unitType, 3)
                    SetUnitExploded(MorphedUnit, true)
                    DestroyEffect(AddSpecialEffect(ExplosionEffect, UnitX, UnitY))
                    KillUnit(MorphedUnit)
                end
            end
        end)
    end)
end
There are options to optimize and rework, but I recieved at least working prototype.
 
Status
Not open for further replies.
Top