Hello & Welcome to our community. Is this your first visit? Register
Follow us on
Follow us on Facebook Follow us on Twitter Watch us on YouTube


MMOCoin

Likes Likes:  0
Results 1 to 3 of 3
  1. #1
    Scout

    Join Date
    Mar 2009
    Posts
    14
    Post Thanks / Like
    Rep Power
    16
    Reputation
    17

    [Lua] Useful Extra Lua Functions!


    Register to remove this ad
    Hey, all.

    This is a script/library of extra functions you can use in your Lua scripts.
    This file is designed for ArcEmu/Aspire.
    The functions included are:

    Code:
    - MessageInRangePlayers(Unit, type, message, maxrange)

    If you have "type" set to 1, this function sends a broadcast message to all in range players of the unit.
    If you have "type" set to 2, it sends an areatrigger type message to all in range players of the unit.
    If you have "type" set to 3, it sends both an areatrigger and broadcast type message to all in range players of the unit.
    "maxrange" is optional. If it is included, it only sends the message to players in the max range radius.

    Example:

    Code:
    MessageInRangePlayers(Unit, 3, "Hello, everyone!", 55)

    That sends a broadcast and areatrigger message to every player in a 55 yard radius of the Unit.



    Code:
    Mount(target, mountdisplayid)

    This function mounts the "target" with "mountdisplayid".
    "target" can be unit or player.

    Example:

    Code:
    Mount(Player, 25511)

    This mounts the Player as a frostwyrm.



    Code:
    Dismount(target)

    This function dismounts the "target" (which can be unit or player).
    Note: Currently this function removes all auras from the player (to remove the mount aura). I will change this later on.


    Example:

    Code:
    Dismount(Player)

    This dismounts the Player.



    Code:
    Equip(unit, slot1weapon, slot2weapon, slot3weapon
    This function equips weapons to the unit. The arguments "unit" and "slot1weapon" are required. The rest are optional.

    Example:

    Code:
    Equip(Unit, 32837, 32838)

    The above code equips the Unit with the Twin Warglaives of Azzinoth. Note: Weapons must be entered with entryID - not displayID.



    Code:
    reload(scriptdirectory)

    This useful function reloads the Lua script ("scriptdirectory")

    Example:

    Code:
    reload("scripts/MyCustomBoss.lua")

    That reloads the Lua script "MyCustomBoss.lua".



    Code:
    ShowErrors()

    This function prints all the errors that have occured with the functions to arcemu_world.exe. This is useful for fixing bugs in your scripts.



    Code:
    Coords(target)[field]

    Put "target" as either, Player, Unit, or pMisc.
    This function returns a Lua "table" set out like so:
    {target's_map_id, target's_zone_id, target's_x_coord, target's_y_coord, target's_z_coord, target's_orientation}

    An example is this:



    Code:
    local plr_x = Coords(Player)[3]
    Code:
    Player:SendBroadcastMessage("Your X coordinate is "..plr_x.."")



    Basically, what this example does is this:

    Coords(Player)[3] returns the player's X coordinate (becase the x coordinate is number 3 in the table the function returns).

    It broadcasts a message to the player "Your X coordinate is [whatever the player's X coordinate is]".









    There are a few more slightly more advanced functions in the library, but if you want to know what they are, you might as well find them out yourself.

    Here is the script:




    Code:
    --   Alvanaar's Extended Lua Library   --
    --   http://www.ac-web.org/         --
    --   [ Requires 'DefinedVariables.lua' ]   --
    -- To load the library use the following function:
    -- [[   dofile(AELL_DIRECTORY)   ]] --
    --
    AELL_DIRECTORY = "scripts/ExtendedLuaLibrary" -- change to this file's file directory in relation to your arcemu_world.exe/aspire_world.exe file.
    Record_Errors = true -- set this to true if you want AELL to record errors and vice versa.
    --
    AELL_ERRORS = {}
    --
    function Coords(targ)
       if (targ == nil) then
          errorlog_write("[Function: Coords(targ)] Function was called with no arguments - it requires one (1) argument.")
       else
          local map, zone, x, y, z, o = targ:GetMapId(), targ:GetZoneId(), targ:GetX(), targ:GetY(), targ:GetZ(), targ:GetO()
          return {map, zone, x, y, z, o}
       end
    end
    function MessageInRangePlayers(unit, typ, msg, maxrng)
       if (unit == nil) then
          errorlog_write("[Function: MessageInRangePlayers(unit, typ, msg, maxrng)] Function was called with no arguments - it requires three (3) arguments.")
       elseif (unit ~= nil) and (typ == nil) then
          errorlog_write("[Function: MessageInRangePlayers(unit, typ, msg, maxrng)] Function was called with one (1) argument - it requires three (3) arguments.")
       elseif (typ ~= nil) and (msg == nil) then
          errorlog_write("[Function: MessageInRangePlayers(unit, typ, msg, maxrng)] Function was called with two (2) arguments - it requires three (3) arguments.")
       elseif (msg ~= nil) and (maxrng == nil) then
          local plrs = unit:GetInRangePlayers()
          local msged = {}
          for i=1, #plrs do
             if (tablefind(msged, plrs[i]:GetName() == false) then
                if (typ == 1) then
                   plrs[i]:SendBroadcastMessage(msg)
                   table.insert(msged, plrs[i]:GetName())
                elseif (typ == 2) then
                   plrs[i]:SendAreaTriggerMessage(msg)
                   table.insert(msged, plrs[i]:GetName())
                elseif (typ == 3) then
                   plrs[i]:SendBroadcastMessage(msg)
                   plrs[i]:SendAreaTriggerMessage(msg)
                   table.insert(msged, plrs[i]:GetName())
                end
             end
          end
       elseif (msg ~= nil) and (maxrng ~= nil) then
          for i=1, #plrs do
             if (tablefind(msged, plrs[i]:GetName() == false) then
                if (unit:GetDistance(plrs[i]) < maxrng) then
                   if (typ == 1) then
                      plrs[i]:SendBroadcastMessage(msg)
                   elseif (typ == 2) then
                      plrs[i]:SendAreaTriggerMessage(msg)
                   elseif (typ == 3) then
                      plrs[i]:SendBroadcastMessage(msg)
                      plrs[i]:SendAreaTriggerMessage(msg)
                   end
                end
             end
          end
       end
    end
    
    function Mount(targ, mountid)
       if (targ == nil) then
          errorlog_write("[Function: Mount(targ, mountid)] Function was called with no arguments - it requires two (2) arguments.")
       elseif (targ ~= nil) and (mountid == nil) then
          errorlog_write("[Function: Mount(targ, mountid)] Function was called with no arguments - it requires two (2) arguments.")
       else
          targ:SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID, mountid)
       end
    end
    function Dismount(targ)
       if (targ == nil) then
          errorlog_write("[Function: Dismount(targ)] Function was called with no arguments - it requires one (1) argument.")
       end
       if (targ:IsPlayer() == true) then
          targ:SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID, 0)
          targ:RemoveAllAuras() -- temporary
       else
          targ:SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID, 0)
       end
    end
    function Equip(unit, slot1, slot2, slot3)
       if (unit == nil) then
          errorlog_write("[Function: Equip(unit, slot1, slot2, slot3)] Function was called with no arguments - it requires two (2) arguments.")
       elseif (unit ~= nil) and (slot1 == nil) then
          errorlog_write("[Function: Equip(unit, slot1, slot2, slot3)] Function was called with one (1) argument - it requires two (2) arguments.")
       elseif (slot2 ~= nil) and (slot2 == nil) then
          unit:SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_ID, slot1)
       elseif (slot2 ~= nil) and (slot3 == nil) then
          unit:SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_ID, slot1)
          unit:SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_ID_1, slot2)
       elseif (slot3 ~= nil) then
          unit:SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_ID, slot1)
          unit:SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_ID_1, slot2)
          unit:SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_ID_2, slot3)
       end
    end
    function reload(directory)
       if (directory == nil) then
          errorlog_write("[Function: reload(directory)] Function was called with no arguments - it requires one (1) argument.")
       else
          dofile(directory)
       end
    end
    function Notify(prefix, txt)
       if (txt == nil) then
          print(prefix)
       elseif (prefix == nil) then
          return
       elseif (prefix ~= nil) and (txt ~= nil) then
          print("["..prefix.."] "..txt)
       end
    end
    function ShowErrors()
       for k, v in pairs(AELL_ERRORS) do
          Notify("[AELL Error]", v)
       end
    end
    function tablefind(tab, val)
       if (type(tab) == "table") and val then
          for k, v in pairs(tab) do
             if (v == val) then
                return true
             end
          end
       end
       return false
    end
    function errorlog_write(err)
       if (err == nil) then
          return false
       else
          table.insert(AELL_ERRORS, err)
       end
    end
    print("Alvanaar's Extended Lua Library\nLoaded!")
    Code:
    
    





    More functions, etc. coming soon!



    Note: This script requires the file: 'DefinedVariables.lua'.






    Enjoy!



    Alvanaar










    › See More: [Lua] Useful Extra Lua Functions!
    Last edited by Alvanaar; 28-08-09 at 02:26 AM.



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

  3. #2
    Founder
    Apple's Avatar
    Join Date
    Jul 2008
    Location
    HeaveN
    Posts
    15,916
    Post Thanks / Like
    Rep Power
    10
    Reputation
    295
    nice one





  4. #3
    Scout

    Join Date
    Mar 2009
    Posts
    14
    Post Thanks / Like
    Rep Power
    16
    Reputation
    17

    Register to remove this ad
    Thanks.

    Bump.

 

 

Visitors found this page by searching for:

lua useful functions

Lua broadcast message

world of warcraft lua useful functions

changing UNIT_FIELD_MOUNTDISPLAYID

lua useful scripts

extra lua functions

useful functions lua

SEO Blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -5. The time now is 05:25 AM.
Powered by vBulletin® Copyright ©2000-2024, Jelsoft Enterprises Ltd.
See More links by ForumSetup.net. Feedback Buttons provided by Advanced Post Thanks / Like (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
vBulletin Licensed to: MMOPro.org