GHI Item Tutorials » Chapters » Random is as Random does

  • Random is as Random does

    Posted by Fethas Soulthorn February 18 - 55 views - 4 comments - 1 like

    So, this morning I the GHI Goddess Fairy got inspired by a goblin and his cola, while you are limited by the basic simple random expression action you can enchance it with a script action. Heres what you do:

     

    On your item put a script action on it, Edit it and now we're going into the word of scripting

     

    the key to this is the 'math.random' Lua function

     

    http://wowprogramming.com/docs/api/random

     

    so say we want an item with about 10 random things it would be set ups as thus

     

     

    local rand = math.random(1,10)

     

    if rand == 1 then

     

    elseif rand ==2 then

    ..and so on

     

    end

     

    Basic, now to address the Cola problem as a full on example?

     

    local randidea = math.random(1,10)

     

    if randidea == 1 then

      GHI_DoSay("Text you want",deley)

    elseif randidea == 2 then

    GHI_DoSay(text,delay)

    elseif randidea == 3 then

    GHI_DoSay(text,delay)

     

    elseif randidea == 4 then

    GHI_DoSay(text,delay)

     

    elseif randidea == 5 then

    GHI_DoSay(text,delay)

     

    elseif randidea == 6 then

    GHI_DoSay(text,delay)

     

    elseif randidea == 7 then

    GHI_DoSay(text,delay)

     

    elseif randidea == 8 then

    GHI_DoSay(text,delay)

     

    elseif randidea == 9 then

    GHI_DoSay(text,delay)

     

    elseif randidea == 10 then

    GHI_DoSay(text,delay)

    end

     

    but gee what is text and delay? Replace text with what ever text you want in quotes, delay is a delay in seconds before the say/emote fires. don't want it set it to 0

     

    now this also applies if you want to do an Emote just use GHI_DoEmote or simply Emote("emote")

     

    its just shortcuts for http://wowprogramming.com/docs/api/SendChatMessage

     

    you can also use delays to put a say and emote in the same randon choice

     

    elseif randidea == 10 then

    GHI_DoEmote("drinks thier cola.",0)

    GHI_DoSay("IDEAS!",2)

    end

     

    this will make the say fire 2 secs after the emote.

     

     

     EDIT: Thanks to Jinxil theres also another way to do it..with tables!

     

    IE Set up a table by

     

    local ideas = { "idea1","idea2",}

     

    GHI_DoSay(idea[random(4)], 0)

     

    it also works with emotes again just

     

    GHI_DoEmote("Drinks thier cola.", 0)

    GHI_DoSay(idea[random(4)], 2)