Likes: 0
Results 1 to 3 of 3
Thread: [Lua] Math.random Guide
-
07-07-09, 02:35 AM #1
[Lua] Math.random Guide
Register to remove this adMath.Random Command Guide
by mager1794
Ok now i know alot of people havn't even heard of this command so here i am to explain it
using the math.random will stop you from having to make 4 functions for 2 spells...you
will have only 3 functions... but it sounds alot better if you do alot of them say you
want it to have a chance to cast fire ball frostbolt or absolutley nothing would be hard
unless you use math.random
The Function
the function for math.random is pretty simple
A & B = numbers to randomize between
ex.
A=1
B=3
it gets a random number between 1 and 3 (includes 1 and 3 in the between)
Math.Random(A,B)
its pretty simple heres a small example o fit
pUnit:Math.Random(1,2)
that will enable me to to make a random of 2 spells or chat message or both
but it would be annoying to use if (Math.Random(1,2) == 1) for every command
so we declare it as something else like this
Code:local spruch = Math.Random(1,2)
Code:if (spruch == 1) then pUnit:SendChatMessage(14, 0, "So do you kind of understand it")
now when scripting a mob you wont be all like should i cast this every 6 secs or 4 secs or
is that to OP ....Wait ill Randomize it at 5 seconds GENIUS!!!!
An Example Script
Code:function Arthas_Speak(pUnit, event) local spruch = Math.Random(1,2) if (spruch == 1) then pUnit:SendChatMessage(12, 0, "Hi") end if (spruch == 2) then pUnit:SendChatMessage(14, 0, "Hi") end end function Arthas_OnEnterCombat(pUnit, event) pUnit:SendChatMessage(12, 0, "Lets Get Randomized") pUnit:RegisterEvent("Arthas_Speak",10000, 0) end RegisterUnitEvent(NPCID, 1, "Arthas_OnEnterCombat")
› See More: [Lua] Math.random Guide
-
07-07-09, 11:12 AM #2
-
31-08-09, 08:06 AM #3
Register to remove this adLua is case sensitive. It has to be called like so:
Code:rand = math.random(5)
Code:rand = math.random(1, 5)