MMOCoin

Likes Likes:  0
Results 1 to 3 of 3

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Scout

    Join Date
    Jul 2009
    Posts
    20
    Post Thanks / Like
    Rep Power
    17
    Reputation
    40

    [Lua] Math.random Guide

    Math.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)
    now all we have to do is this

    Code:
    if (spruch == 1) then
    pUnit:SendChatMessage(14, 0, "So do you kind of understand it")
    if you actually pay get explained how to use this command its pretty easy and very useful
    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")



  2. Related Threads - Scroll Down after related threads if you are only interested to view replies for above post/thread

  3. #2
    Beginner

    Join Date
    Jul 2009
    Posts
    8
    Post Thanks / Like
    Rep Power
    17
    Reputation
    1
    nice!

  4. #3
    Scout

    Join Date
    Mar 2009
    Posts
    14
    Post Thanks / Like
    Rep Power
    17
    Reputation
    17
    Lua is case sensitive. It has to be called like so:
    Code:
    rand = math.random(5)
    or
    Code:
    rand = math.random(1, 5)

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •