• This is a read only backup of the old Emudevs forum. If you want to have anything removed, please message me on Discord: KittyKaev

[SOLVED] Need help with cast spell Eluna Lua

Status
Not open for further replies.

Tok124

Respected Member
Hello. I really don't know anything about Lua but i am making a Druid boss. and the boss should cast spell Starfire. Starfire requires mana and i think that's why the creature wont cast the spell. I have added mana to the creature but it didnt help.

Here is the cast spell function
Code:
local function spell_2(eventId, delay, calls, creature)
    creature:CastSpell(creature, 48463, true) -- Starfire
end

And here is the phase
Code:
local function Phase2(event, delay, pCall, creature)
    if (creature:GetHealthPct() <= 80) then
	    creature:RemoveEvents()
		creature:SetDisplayId(15374)
		creature:RegisterEvent(spell_2, 1000, 0)
		creature:RegisterEvent(Phase3, 1000, 0)
    end
end
 

azamaqtlol

Enthusiast
it's better to use your boss name, to register function, instead of Evenit (my personal taste). btw, I created a random boss here, only to show to you the exemple(working aswell).

Code:
[COLOR="#00FF00"]function LadyVashj.Starfall(event, delay, pCall, creature)
    CastIfCan(creature, creature:GetVictim(), 53201)
end[/COLOR]

also, on the phases, It's always better to set the first phase on event combat, like this

Code:
[COLOR="#00FF00"]local LadyVashj = {}
local phase1 = 80[/COLOR]

and then, name it on the main combat function

Code:
[COLOR="#00FF00"]function LadyVashj.EnterCombat(event, creature, target)
    creature:RegisterEvent(LadyVashj.Starfall, 9000, 0)
	creature:RegisterEvent(function(...) LadyVashj.Phase(1, ...) end, 5000, 0)
end[/COLOR]

and to call the function you should use this:

Code:
[COLOR="#00FF00"]function LadyVashj.Phase(phaseid, event, delay, pCall, creature)
    -- If phase is 1 and health below required, move to phase 2
    if  phaseid == 1 and creature:GetHealthPct() <= Phase1 then
	creature:SetDisplayId(15374)
	creature:RegisterEvent(LadyVashj.Starfall, 9000, 0)
	creature:RegisterEvent(function(...)LadyVashj.Phase(2, ...) end, 5000, 0) -- note the phase 2 here
    end[/COLOR]

here's a personal advice, put this before the Combat function, at the begin

Code:
[COLOR="#00FF00"] local function CastIfCan(caster, target, spell)
    if (caster and target and not caster:GetCurrentSpell(1)) then
        caster:CastSpell(target, spell)
        return true
    end
    return false
end[/COLOR]

If you don't understand yet, poste the full code here, so I can help you better.
 

Tok124

Respected Member
Well. That looks way better than my script. But my Lua Skills is really bad haha. I dont understand much. I dont know how i could use it for my script so i guess i post my full script

Code:
--NPC Entry--

local NPC_ID = 50001

--Spells--

local function spell_1(eventId, delay, calls, creature)
    creature:CastSpell(creature, 75159, true)
end

local function spell_2(eventId, delay, calls, creature)
    creature:CastSpell(creature, 48463, false) -- Starfire
end

local function spell_3(eventId, delay, calls, creature)
    creature:CastSpell(creature, 17233, true) -- Lay on Hands
end

-- Phases --

local function TOT(event, delay, pCall, creature, player, killed)
    if (creature:GetHealthPct() <= 0) then
		creature:SendUnitYell("Congratz, You have defeated me!", 1)
		creature:RemoveEvents()
	   end
end

local function reset(event, delay, pCall, creature, player, killed)
    if (creature:GetHealthPct() >= 95) then
		creature:RemoveEvents()
		creature:SendUnitYell("Feels good to be back alive", 1)
		creature:RegisterEvent(spell_1, 1000, 0)
		creature:RegisterEvent(Phase2, 1000, 0)
	   end
end


local function PhaseEnd(event, delay, pCall, creature, player, killed)
    if (creature:GetHealthPct() <= 10) then
        creature:RemoveEvents()
		creature:SendUnitYell("How is this even possible !!!", 1)
		creature:RegisterEvent(spell_3, 500, 1)	 
		creature:RegisterEvent(reset, 1000, 0)
	   end
end

local function Phase6(event, delay, pCall, creature)
    if (creature:GetHealthPct() <= 15) then
        creature:RemoveEvents()
		creature:SetDisplayId(2281)
		creature:RegisterEvent(spell_2, 5500, 0)
		creature:RegisterEvent(PhaseEnd, 1000, 0)
	   end
end

local function Phase5(event, delay, pCall, creature)
    if (creature:GetHealthPct() <= 30) then
        creature:RemoveEvents()
        creature:SetDisplayId(892)
		creature:RegisterEvent(spell_1, 1000, 0)
		creature:RegisterEvent(Phase6, 1000, 0)
	   end
end


local function Phase4(event, delay, pCall, creature)
    if (creature:GetHealthPct() <= 50) then
        creature:RemoveEvents()
		creature:SetDisplayId(15374)
		creature:RegisterEvent(spell_2, 5500, 0)
		creature:RegisterEvent(Phase5, 1000, 0)
	   end
end

local function Phase3(event, delay, pCall, creature)
    if (creature:GetHealthPct() <= 60) then
        creature:RemoveEvents()
		creature:SetDisplayId(892)
		creature:RegisterEvent(spell_1, 1000, 0)
		creature:RegisterEvent(Phase4, 1000, 0)
	   end
end

local function Phase2(event, delay, pCall, creature)
    if (creature:GetHealthPct() <= 80) then
	    creature:RemoveEvents()
		creature:SetDisplayId(15374)
		creature:RegisterEvent(spell_2, 2000, 1)
		creature:RegisterEvent(Phase3, 1000, 0)
    end
end


local function Phase1(event, delay, pCall, creature, player)
    if (creature:GetHealthPct() <= 100) then
        creature:RemoveEvents()
		creature:SetDisplayId(892)
		creature:RegisterEvent(spell_1, 1000, 0)
		creature:RegisterEvent(Phase2, 1000, 0)
    end
end

local function OnEnterCombat(event, creature, target, player)
    creature:SendUnitYell("Are you serious? Are you really gonna try kill me? LEAVE NOW OR DIE !!!", 0) 
    creature:RegisterEvent(Phase1, 1000, 0)
	
end

RegisterCreatureEvent(NPC_ID, 1, OnEnterCombat)

- - - Updated - - -

Oh btw. Sorry i said "My Script" this was not coded by me from start. I just edited another script that i found
 

Tok124

Respected Member
I managed to figure it out. I had to add GetVictim() i can't believe i didnt think about that haha :p
 

azamaqtlol

Enthusiast
take this, it will help you to organize a bit more your script, btw I removed the phase 10, and Lay on hands, on the combat-function(since I think It's not a good idea) but you can add by yourself, doing what I did here.

Code:
[COLOR="#00FF00"]local local Testboss = {}
local phase1 = 80
local phase2 = 60
local phase3 = 50
local phase4 = 30
local phase5 = 15

local function CastIfCan(caster, target, spell)
    if (caster and target and not caster:GetCurrentSpell(1)) then
        caster:CastSpell(target, spell)
        return true
    end
    return false
end

function Testboss.EnterCombat(event, creature, target)
    creature:SendUnitYell("Are you serious? Are you really gonna try kill me? LEAVE NOW OR DIE !!!", 0)
	creature:SetDisplayId(892)
	creature:RegisterEvent(Testboss.Claw, 1000, 0)
	creature:RegisterEvent(function(...) Testboss.Phase(1, ...) end, 5000, 0)
end

function Testboss.KilledTarget(event, creature, victim)
    creature:SendUnitYell("Feels good to be back alive", 0)
end
 
function Testboss.LeaveCombat(event, creature)
    creature:RemoveEvents()
	creature:DeMorph();
end
 
function Testboss.Died(event, creature, killer)
    creature:SendUnitYell("Congratz, You have defeated me!", 0)
end

function Testboss.Claw(event, delay, pCall, creature)
    CastIfCan(creature, creature:GetVictim(), 75159)
end

function Testboss.Starfire(event, delay, pCall, creature)
    CastIfCan(creature, creature:GetVictim(), 48463)
end

function Testboss.Phase(phaseid, event, delay, pCall, creature)
    -- If phase is 1 and health below required, move to phase 2
	if  phaseid == 1 and creature:GetHealthPct() <= Phase1 then
        creature:RemoveEvents()
		creature:SetDisplayId(15374)
		creature:RegisterEvent(Testboss.Starfire, 4000, 1)
		creature:RegisterEvent(function(...) Testboss.Phase(2, ...) end, 5000, 0) -- note the phase 2 here
    end
	
	-- If phase is 2 and health below required, move to phase 3
    if  phaseid == 2 and creature:GetHealthPct() <= Phase2 then
        creature:RemoveEvents()
		creature:SetDisplayId(892)
		creature:RegisterEvent(Testboss.Claw, 1000, 0)
		creature:RegisterEvent(function(...) Testboss.Phase(3, ...) end, 5000, 0) -- note the phase 3 here
	end
     
    -- If phase is 3 and health below required, move to phase 4
    if  phaseid == 3 and creature:GetHealthPct() <= Phase2 then
        creature:RemoveEvents()	 
		creature:SetDisplayId(15374)
		creature:RegisterEvent(Testboss.Starfire, 4000, 1)
		creature:RegisterEvent(function(...) Testboss.Phase(4, ...) end, 5000, 0) -- note the phase 4 here
	end
	
	-- If phase is 4 and health below required, move to phase 4
    if  phaseid == 4 and creature:GetHealthPct() <= Phase2 then
	    creature:RemoveEvents()
		creature:SetDisplayId(892)
		creature:RegisterEvent(Testboss.Claw, 1000, 0)
		creature:RegisterEvent(function(...) Testboss.Phase(5, ...) end, 5000, 0) -- note the phase 5 here
	end
	
	-- If phase is 5 and health below required, move to phase 4
    if  phaseid == 5 and creature:GetHealthPct() <= Phase2 then
        creature:RemoveEvents()	 
		creature:SetDisplayId(15374)
		creature:RegisterEvent(Testboss.Starfire, 4000, 1)
	end
end	

RegisterCreatureEvent(50001, 1, Testboss.EnterCombat)
RegisterCreatureEvent(50001, 2, Testboss.LeaveCombat)
RegisterCreatureEvent(50001, 3, Testboss.KilledTarget)
RegisterCreatureEvent(50001, 4, Testboss.Died)[/COLOR]

Also, reply to this post, if it works perfectly, or if it doesn't, because I've not tested it, I just rewrite for you
 

Tok124

Respected Member
Error on line 1
<name> expected near 'local'

- - - Updated - - -

i guess it should be "local function" i tried that and then it says '(' expected near '='
 

azamaqtlol

Enthusiast
Hey, I ask sorry, I wrote to you too hurry, because I had to go out with my wife, to buy something, there had a lot of erros, Fixed all them now, Tested and Fixed, follow the whole code here:

Code:
[COLOR="#00FF00"]local Testboss = {}
local phase1 = 80
local phase2 = 60
local phase3 = 50
local phase4 = 30
local phase5 = 15

local function CastIfCan(caster, target, spell)
    if (caster and target and not caster:GetCurrentSpell(1)) then
        caster:CastSpell(target, spell)
        return true
    end
    return false
end

function Testboss.EnterCombat(event, creature, target)
    creature:SendUnitYell("Are you serious? Are you really gonna try kill me? LEAVE NOW OR DIE !!!", 0)
	creature:SetDisplayId(892)
	creature:RegisterEvent(Testboss.Claw, 1000, 0)
	creature:RegisterEvent(function(...) Testboss.Phase(1, ...) end, 5000, 0)
end

function Testboss.KilledTarget(event, creature, victim)
    creature:SendUnitYell("Feels good to be back alive", 0)
end
 
function Testboss.LeaveCombat(event, creature)
    creature:RemoveEvents()
	creature:DeMorph();
end
 
function Testboss.Died(event, creature, killer)
    creature:SendUnitYell("Congratz, You have defeated me!", 0)
end

function Testboss.Claw(event, delay, pCall, creature)
    creature:SendUnitYell(" Time to shave my nails upon your skin", 0)
    CastIfCan(creature, creature:GetVictim(), 75159)
end

function Testboss.Starfire(event, delay, pCall, creature)
    creature:SendUnitYell("Feel the nature power", 0)
    CastIfCan(creature, creature:GetVictim(), 65854)
end

function Testboss.Phase(phaseid, event, delay, pCall, creature)
    if phaseid == 1 and creature:GetHealthPct() <= phase1 then
        creature:RemoveEvents()
		creature:SendUnitYell("I'm changing my form", 0)
		creature:SetDisplayId(15374)
		creature:RegisterEvent(Testboss.Starfire, 4000, 0)
		creature:RegisterEvent(function(...) Testboss.Phase(2, ...) end, 5000, 0) -- note the phase 2 here
    end
	
	if phaseid == 2 and creature:GetHealthPct() <= phase2 then
        creature:RemoveEvents()
		creature:SetDisplayId(892)
		creature:RegisterEvent(Testboss.Claw, 1000, 0)
		creature:RegisterEvent(function(...) Testboss.Phase(3, ...) end, 5000, 0) -- note the phase 3 here
	end
	
	if phaseid == 3 and creature:GetHealthPct() <= phase3 then
        creature:RemoveEvents()	 
		creature:SetDisplayId(15374)
		creature:RegisterEvent(Testboss.Starfire, 4000, 0)
		creature:RegisterEvent(function(...) Testboss.Phase(4, ...) end, 5000, 0) -- note the phase 4 here
	end
	
	if phaseid == 4 and creature:GetHealthPct() <= phase4 then
	    creature:RemoveEvents()
		creature:SetDisplayId(892)
		creature:RegisterEvent(Testboss.Claw, 1000, 0)
		creature:RegisterEvent(function(...) Testboss.Phase(5, ...) end, 5000, 0) -- note the phase 5 here
	end
	
	if phaseid == 5 and creature:GetHealthPct() <= phase5 then
        creature:RemoveEvents()	 
		creature:SetDisplayId(15374)
		creature:RegisterEvent(Testboss.Starfire, 4000, 0)
	end
end	

RegisterCreatureEvent(50001, 1, Testboss.EnterCombat)
RegisterCreatureEvent(50001, 2, Testboss.LeaveCombat)
RegisterCreatureEvent(50001, 3, Testboss.KilledTarget)[/COLOR]
RegisterCreatureEvent(50001, 4, Testboss.Died)

One more time excuse-me I hate to help someone on rush time, but Glad I fixed it now, and you can use it correct, take care bro, and if something went wrong (guess not cos I tested it) feel free to ask me on skype again, the 'Yells' on Claws and Starfire, is just to show when it procs, just to see if It's working as indeed, you can remove it later if you can, Here's a hint, put a bit more time on each cast, otherwise it will become overpower xD..
 
Last edited:
Status
Not open for further replies.
Top