Alvanaar
28-08-09, 02:17 AM
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:
- 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:
MessageInRangePlayers(Unit, 3, "Hello, everyone!", 55)
That sends a broadcast and areatrigger message to every player in a 55 yard radius of the Unit.
Mount(target, mountdisplayid)
This function mounts the "target" with "mountdisplayid".
"target" can be unit or player.
Example:
Mount(Player, 25511)
This mounts the Player as a frostwyrm.
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:
Dismount(Player)
This dismounts the Player.
Equip(unit, slot1weapon, slot2weapon, slot3weapon
This function equips weapons to the unit. The arguments "unit" and "slot1weapon" are required. The rest are optional.
Example:
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.
reload(scriptdirectory)
This useful function reloads the Lua script ("scriptdirectory")
Example:
reload("scripts/MyCustomBoss.lua")
That reloads the Lua script "MyCustomBoss.lua".
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.
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:
local plr_x = Coords(Player)[3]
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:
-- 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!")
More functions, etc. coming soon!
Note: This script requires the file: 'DefinedVariables.lua'.
Enjoy!
Alvanaar
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:
- 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:
MessageInRangePlayers(Unit, 3, "Hello, everyone!", 55)
That sends a broadcast and areatrigger message to every player in a 55 yard radius of the Unit.
Mount(target, mountdisplayid)
This function mounts the "target" with "mountdisplayid".
"target" can be unit or player.
Example:
Mount(Player, 25511)
This mounts the Player as a frostwyrm.
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:
Dismount(Player)
This dismounts the Player.
Equip(unit, slot1weapon, slot2weapon, slot3weapon
This function equips weapons to the unit. The arguments "unit" and "slot1weapon" are required. The rest are optional.
Example:
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.
reload(scriptdirectory)
This useful function reloads the Lua script ("scriptdirectory")
Example:
reload("scripts/MyCustomBoss.lua")
That reloads the Lua script "MyCustomBoss.lua".
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.
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:
local plr_x = Coords(Player)[3]
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:
-- 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!")
More functions, etc. coming soon!
Note: This script requires the file: 'DefinedVariables.lua'.
Enjoy!
Alvanaar