Thread: [Guide] How to use local LUA function!

1. [Guide] How to use local LUA function!

Ok guys well this is my first guide ive made so don;t Flame to hard on it.

I wrote the whole guide in LUA so if anything copy and past it into either BLUA or a notepad....I wrote it in BLUA but ther's the guide hope you like it.

Code:
-- Ok in this guide im gonig to demonstrate 2 things.
-- 1 Im Going to show how to use to Define a couple of things
-- that i use myself to help make Phases in LUA Scripting
-- they don't always work but that's just because well its LUA
-- OK well let's get started.

-- Let's Start by showing you how to use the math.random function
-- but it doesn't hurt to have another one so let's get started on it

-- Ok math.random is used in a local formation. So you would do
-- local <name> = math.random(1,<amount you want to random between>)
-- So Let's demonstrate this in a CastSpell Function
function Guide_Random(pUnit)
local guide = math.random(1,2)
if(guide == 1) then
pUnit:CastSpellOnTarget(5)
end
-- Notice how you have to end each if function you create
if(guide == 2) then
pUnit:CastSpellOnTarget(10)
end
end
-- After ending the if function be sure to end the entire function as well
-- i always forget that part lol.
-- well thats math.random. Easy huh

-- ok now i will show you how to Make phases using Health Pct
-- this is just like math.random well kinda lol
-- well the format for this would be
-- local <name> = pUnit:GetHealthPct()
-- then the if function following it would be
-- if(<name> <= 90) then
-- the <= part mean Less than or equal to 90 pct
-- Now let's put this in a function
function Guide_Pct(pUnit)
local hp = pUnit:GetHealthPct()
if(hp <= 90) then
pUnit:CastSpellOnTarget(5)
end
-- Notice once again end the if function first
end

-- Now im going to show you a way thats more accurate for the
-- mob to use a spell on a target instead of skipping it
-- because it didnt select a target. Well here's how you would use
-- this function
-- ok once again it's a local function and you GetClosestPlayer
-- so the function would be local <name> = pUnit:GetClosestPlayer()
-- this one doesnt have an if function for it. I will show you
-- how to use this one in the function its self.
-- Also before we go on I will also like to show you how to get a
-- Random player instead of Closest Player
-- Lets start the function
function Guide_Closest(pUnit)
local plr = pUnit:GetClosestPlayer()
pUnit:CastSpellOnTarget(5, plr)
end
-- Notice i put the function name plr after the spell id.
-- That's how you tell it to use that local function in the cast

-- Now lets demonstrate Random one
function Guide_Random(pUnit)
local plr = pUnit:GetRandomPlayer(0)
-- Notice how you put a 0 in the () on this one
pUnit:CastSpellOnTarget(5, plr)
end
-- Same as Closest you put the Local name after the spell id

-- *******************************************************
-- *  Now I will put the whole script together for you   *
-- *               to refer to if you need               *
-- *******************************************************

function Dartignan_Spell(pUnit)
local hp = pUnit:GetHealthPct()
local plr = pUnit:GetClosestPlayer()
local spell = math.random(1,2)
if(hp <= 90) then
if(spell == 1) then
pUnit:CastSpellOnTarget(5, plr)
end
if(spell == 2) then
pUnit:CastSpellOnTarget(10, plr)
end
end
end

function Dartignan_OnCombat(pUnit)
pUnit:RegisterEvent("Dartignan_Spell", 10000, 0)
end
-- This function im using to register a function in a function
-- i do this to put time between each time it cast the spell
-- now when you RegisterUnitEvent you only register the
-- Dartignan_ OnCombat so just likee this

RegisterUnitEvent(55555, 1, "Dartignan_OnCombat")