PDA

View Full Version : How Local Choice=Math.random Works



BrantX
27-07-08, 01:27 AM
This guide was made by Me!

First lets view a LUA Peice from LUA++'s SVN. Brutallus for instance is a Local Choice=Math.random Boss.

Here is a peice of it.


function Brut_OnKilledTarget (pUnit, Event)
local Choice=math.random(1, 3)
if Choice==1 then
pUnit:SendChatMessage(14, 0, "Perish, insect!")
pUnit:PlaySoundToSet(12464)
elseif Choice==2 then
pUnit:SendChatMessage(14, 0, "You are meat!")
pUnit:PlaySoundToSet(12465)
elseif Choice==3 then
pUnit:SendChatMessage(14, 0, "Too easy!")
pUnit:PlaySoundToSet(12466)
end
endAlright, so now you just need to re-write that on Notepad from scrath alot to get the feel of it. So now we have the script and feel of it. Lets continue to add and decrease options"elseif choice's".

Alright this is what makes the script have as many options.


local Choice=math.random(1, 3) <--
You cannot change the 1 or it will not load all the others.
You can change the 3 to make as many adds as possible.
Example



function Test_OnEnterCombat(pUnit, Event)
local Choice=math.random(1, 6)
if Choice==1 then
pUnit:SendChatMessage(14, 0, "WHY AM I YELLING?")
elseif Choice==2 then
pUnit:SendChatMessage(12, 0, "I would like to talk now.")
elseif Choice==3 then
pUnit:SendChatMessage(14, 0, "TALKING IS FOR LOSERS!!!")
elseif Choice==4 then
pUnit:SendChatMessage(14, 0, "TALKING IS FOR LOSERS!!!")
elseif Choice==5 then
pUnit:SendChatMessage(14, 0, "TALKING IS FOR LOSERS!!!")
elseif Choice==6 then
pUnit:SendChatMessage(14, 0, "TALKING IS FOR LOSERS!!!")
end
endAll you need to change is


elseif Choice==3 thenand

local Choice=math.random(1, 6)As high as you want.

Hope this helps!

- BrantX

Apple
27-07-08, 01:29 AM
nice one blua founder , keep it up & thanks for sharing :)

Chmun
28-07-08, 12:46 PM
This is the MOST IMPORTANT thing while scripting LUA :D ... i learned this by reading other's Arcemu LUA files, Thats how i learn scripting :D

BrantX
28-07-08, 08:59 PM
Glad you like it :P

Boxxy
04-08-08, 02:18 AM
nice i learned this from a script my friend sent me its very epic for big raids +reps

BrantX
08-08-08, 01:22 PM
Yay? I make good guide? :P