View Full Version : [Reference] Xenobot Lua Documentation
Chuitox
08-06-2014, 08:00 PM
TABLE OF CONTENTS
Constants
Direction type (http://forums.xenobot.net/showthread.php?28585-Xenobot-Lua-Documentation&p=353373&viewfull=1#post353373)
Speak type (http://forums.xenobot.net/showthread.php?28585-Xenobot-Lua-Documentation&p=353374&viewfull=1#post353374)
Skull type (http://forums.xenobot.net/showthread.php?28585-Xenobot-Lua-Documentation&p=353375&viewfull=1#post353375)
Party type (http://forums.xenobot.net/showthread.php?28585-Xenobot-Lua-Documentation&p=353376&viewfull=1#post353376)
PVP icon type (http://forums.xenobot.net/showthread.php?28585-Xenobot-Lua-Documentation&p=353377&viewfull=1#post353377)
Slot type (http://forums.xenobot.net/showthread.php?28585-Xenobot-Lua-Documentation&p=353378&viewfull=1#post353378)
Channel
New (Constructor) (http://forums.xenobot.net/showthread.php?28585-Xenobot-Lua-Documentation&p=353379&viewfull=1#post353379)
ID (http://forums.xenobot.net/showthread.php?28585-Xenobot-Lua-Documentation&p=353380&viewfull=1#post353380)
Close (http://forums.xenobot.net/showthread.php?28585-Xenobot-Lua-Documentation&p=353383&viewfull=1#post353383)
SendOrangeMessage (http://forums.xenobot.net/showthread.php?28585-Xenobot-Lua-Documentation&p=353385&viewfull=1#post353385)
SendYellowMessage (http://forums.xenobot.net/showthread.php?28585-Xenobot-Lua-Documentation&p=358603&viewfull=1#post358603)
Client
HideEquipment (http://forums.xenobot.net/showthread.php?28585-Xenobot-Lua-Documentation&p=364951&viewfull=1#post364951)
ShowEquipment (http://forums.xenobot.net/showthread.php?28585-Xenobot-Lua-Documentation&p=364952&viewfull=1#post364952)
Container
New (Constructor) (http://forums.xenobot.net/showthread.php?28585-Xenobot-Lua-Documentation&p=364964&viewfull=1#post364964)
GetFreeSlot (http://forums.xenobot.net/showthread.php?28585-Xenobot-Lua-Documentation&p=364968&viewfull=1#post364968)
GetFirst ("]iContainers[/URL]
GetAll ("]GetLast
GetNext ("]GetNextOpen
ID ("]Index
ItemCount ("]Name
isOpen ("]ItemCapacity
isFull ("]isEmpty
Close ("]EmptySlots
OpenChildren ("]Minimize
GetItemData ("]CountItemsOfID
UseItem ("]iItems
UseItemWithGround ("]UseItemWithContainerItem
MoveItemToEquipment ("]UseItemWithCreature
MoveItemToContainer ("]MoveItemToGround
[URL=")
Chuitox
08-06-2014, 08:00 PM
Note: Do not confuse with DIRECTIONS table
NORTH = 0
EAST = 1
SOUTH = 2
WEST = 3
SOUTHWEST = 4
SOUTHEAST = 5
NORTHWEST = 6
NORTHEAST = 7
Examples
Example 1: Turning character
Self.Turn(NORTH)
Example 2: Printing the direction our character looks
local dir = Self.LookDirection()
if (dir == NORTH) then
print("North")
elseif (dir == SOUTH) then
print("South")
elseif (dir == EAST) then
print("East")
elseif (dir == WEST) then
print("West")
end
Chuitox
08-06-2014, 08:00 PM
SPEAK_SAY = 0
SPEAK_YELL = 2
SPEAK_WHISPER = 3
SPEAK_NPC = 4
Examples
Example 1: Whispering a message
Self.Speak("This is a whispered message", SPEAK_WHISPER, 65, 7)
Example 2: Selling flasks
Self.Speak("hi", SPEAK_NPC)
wait(200, 600)
Self.Speak("flasks", SPEAK_NPC)
wait(200, 800)
Self.Speak("yes", SPEAK_NPC)
Chuitox
08-06-2014, 08:01 PM
SKULL_NONE = 0
SKULL_WHITE = 1
SKULL_RED = 4
SKULL_ORANGE = 2
SKULL_YELLOW = 3
SKULL_BLACK = 5
Examples
Example 1: Close client when character has black skull
if (Self.Skull() == SKULL_BLACK) then
os.exit()
end
Example 2: Play alarm if a player in screen has red skull
for name, creature in Creature.iPlayers() do
if (creature:Skull() == SKULL_RED) then
alert()
end
end
Chuitox
08-06-2014, 08:01 PM
PARTY_YELLOW = 1
PARTY_YELLOW_SHAREDEXP = 2
PARTY_YELLOW_NOSHAREDEXP_BLINK = 3
PARTY_YELLOW_NOSHAREDEXP = 4
PARTY_BLUE = 1
PARTY_BLUE_SHAREDEXP = 2
PARTY_BLUE_NOSHAREDEXP_BLINK = 3
PARTY_BLUE_NOSHAREDEXP = 4
PARTY_WHITEBLUE = 5
PARTY_WHITEYELLOW = 6
Examples
Example 1: Check if party member is sharing experience
for name, creature in Creature.iPlayers() do
if (creature:PartyStatus() == PARTY_BLUE_SHAREDEXP or
creature:PartyStatus() == PARTY_YELLOW_SHAREDEXP) then
print(name..' is sharing experience.')
end
end
Chuitox
08-06-2014, 08:01 PM
WAR_ALLY = 1
WAR_ENEMY = 2
WAR_INWAR = 3
PVP_ALLY = WAR_ALLY
PVP_ENEMY = WAR_ENEMY
PVP_INWAR = WAR_INWAR
PVP_GUILDMATE = 4
PVP_HASGUILD = 5
Examples
Example 1: Play alarm if a player in screen is war enemy
for name, creature in Creature.iPlayers() do
if (creature:PvPIcon() == PVP_ENEMY) then
alert()
end
end
Chuitox
08-06-2014, 08:02 PM
Note: Not to be confused with EQUIPMENT_SLOTS table
SLOT_HEAD = 0
SLOT_AMULET = 1
SLOT_BACKPACK = 2
SLOT_ARMOR = 3
SLOT_SHIELD = 4
SLOT_WEAPON = 5
SLOT_LEGS = 6
SLOT_FEET = 7
SLOT_RING = 8
SLOT_AMMO = 9
Examples
Example 1: Open Main Backpack
slotUseItem(SLOT_BACKPACK)
Example 2: Use party hat every 2 seconds
Module("XenobotLuaDocumentation:PartyHat", function(mod)
slotUseItem(SLOT_HEAD)
mod:Delay(2000)
end)
Chuitox
08-06-2014, 08:02 PM
Functionality: Creates a new custom channel
Note: All object constructors can be used without the word New. See below for more details.
-- (string) name: Name of the channel
-- (callback) speakCallback: Function to trigger on user input
-- (callback) closeCallback: Function to trigger when the user closes the channel
-- (object) returns Channel
Channel.New(name, speakCallback, closeCallback)
-- Possible alternatives:
Channel(name, speakCallback, closeCallback)
Examples
Example 1: Creating a custom channel
function mySpeakCallback(channel, text)
channel:SendYellowMessage(Self.Name(), text)
end
function myCloseCallback(channel)
print(channel .. " was closed.")
end
local myCustomChannel = Channel.New("Custom Channel", mySpeakCallback, myCloseCallback)
Example 2: Display general information in custom channel
function mySpeakCallback(channel, text)
channel:SendYellowMessage(Self.Name(), text)
if (text:lower() == "display") then
channel:SendOrangeMessage("XBLuaDoc", "General information\nName: "..Self.Name()..
"\nHealth: "..Self.Health().."/"..Self.MaxHealth()..
"\nMana: "..Self.Mana().."/"..Self.MaxMana()..
"\nLevel: "..Self.Level()..
"\nPing: "..Self.Ping())
end
end
function myCloseCallback(channel)
print(channel:Name().." was closed.")
end
local myCustomChannel = Channel("Custom Channel", mySpeakCallback, myCloseCallback)
myCustomChannel:SendOrangeMessage("XBLuaDoc", "Welcome to Custom Channel. Type 'display' to show general information.")
Output
https://www.dropbox.com/s/g9vqdpe2ebfxva4/customchannel.jpg?dl=1
Chuitox
08-06-2014, 08:03 PM
Functionality: Returns the ID number of a custom channel
-- Functional programming
-- (number) returns Channel ID
Channel.ID(channel)
-- Object oriented programming
-- (number) returns Channel ID
Channel:ID()
Examples
Example 1: Sending channel ID to channel (functional programming)
function mySpeakCallback(channel, text)
channel:SendYellowMessage(Self.Name(), text)
end
function myCloseCallback(channel)
print(channel:Name() .. " was closed.")
end
local myCustomChannel = Channel.New("Custom Channel", mySpeakCallback, myCloseCallback)
-- Channel ID using functional programming
myCustomChannel:SendOrangeMessage("XBLuaDoc", "The ID of this channel is " .. Channel.ID(myCustomChannel))
Example 2: Sending channel ID to channel (object oriented programming)
function mySpeakCallback(channel, text)
channel:SendYellowMessage(Self.Name(), text)
end
function myCloseCallback(channel)
print(channel:Name() .. " was closed.")
end
local myCustomChannel = Channel.New("Custom Channel", mySpeakCallback, myCloseCallback)
-- Channel ID using objected oriented programming
myCustomChannel:SendOrangeMessage("XBLuaDoc", "The ID of this channel is " .. myCustomChannel:ID())
Chuitox
08-06-2014, 08:03 PM
Functionality: Closes a custom channel
-- Functional programming
-- (void) No value returned
Channel.Close(channel)
-- Object oriented programming
-- (void) No value returned
Channel:Close()
Examples
Example 1: Closing channel (functional programming)
function mySpeakCallback(channel, text)
channel:SendYellowMessage(Self.Name(), text)
end
function myCloseCallback(channel)
print(channel:Name() .. " was closed.")
end
local myCustomChannel = Channel.New("Custom Channel", mySpeakCallback, myCloseCallback)
-- Closing channel using functional programming
Channel.Close(myCustomChannel)
Example 2: Closing channel (object oriented programming)
function mySpeakCallback(channel, text)
channel:SendYellowMessage(Self.Name(), text)
end
function myCloseCallback(channel)
print(channel:Name() .. " was closed.")
end
local myCustomChannel = Channel.New("Custom Channel", mySpeakCallback, myCloseCallback)
-- Closing channel using object oriented programming
myCustomChannel:Close()
Chuitox
08-06-2014, 08:04 PM
Functionality: Sends an orange message to a custom channel
-- Functional programming
-- (string) sender: Name to show where character's names are displayed
-- (string text: Message to display
-- (void) No value returned
Channel.SendOrangeMessage(channel, sender, text)
-- Object oriented programming
-- (string) sender: Name to show where character's names are displayed
-- (string text: Message to display
-- (void) No value returned
Channel:SendOrangeMessage(sender, text)
Examples
Example 1: Sending welcome message to custom channel (functional programming)
function mySpeakCallback(channel, text)
channel:SendYellowMessage(Self.Name(), text)
end
function myCloseCallback(channel)
print(channel:Name() .. " was closed.")
end
local myCustomChannel = Channel.New("Custom Channel", mySpeakCallback, myCloseCallback)
Channel.SendOrangeMessage(myCustomChannel, "XBLuaDoc", "Welcome to the custom channel.")
Example 2: Sending welcome message to custom channel (object oriented programming)
function mySpeakCallback(channel, text)
channel:SendYellowMessage(Self.Name(), text)
end
function myCloseCallback(channel)
print(channel:Name() .. " was closed.")
end
local myCustomChannel = Channel.New("Custom Channel", mySpeakCallback, myCloseCallback)
myCustomChannel:SendOrangeMessage("XBLuaDoc", "Welcome to the custom channel.")
Daniel-Sp
08-06-2014, 08:06 PM
Curious of whats comming :)
For now, I wish you a ban for 11 placeholders.
GL with this :)
Perfections
08-07-2014, 03:13 PM
Good luck with this mate! :)
ppgab
08-07-2014, 03:16 PM
If you want help with this let me know, i had started on a lua tutorial for xenobot and wanting to make a better documentation too.
Katwreck
08-07-2014, 07:48 PM
This will be awesome, atleast for me who is not so good at Lua, thank you!
Katwreck
08-11-2014, 07:16 PM
How is it coming along?
Chuitox
08-11-2014, 09:13 PM
How is it coming along?
Little time this week but hopefully I get there soon
Katwreck
08-20-2014, 11:00 AM
Looking good! :)
Chuitox
08-20-2014, 12:19 PM
Functionality: Sends a yellow message to a custom channel. Similar to Channel:SendOrangeMessage() (http://forums.xenobot.net/showthread.php?28585-Xenobot-Lua-Documentation&p=353385&viewfull=1#post353385)
-- Functional programming
-- (string) sender: Name to show where character's names are displayed
-- (string text: Message to display
-- (void) No value returned
Channel.SendYellowMessage(channel, sender, text)
-- Object oriented programming
-- (string) sender: Name to show where character's names are displayed
-- (string text: Message to display
-- (void) No value returned
Channel:SendYellowMessage(sender, text)
Examples
Example 1: Sending welcome message to custom channel (functional programming)
function mySpeakCallback(channel, text)
channel:SendYellowMessage(Self.Name(), text)
end
function myCloseCallback(channel)
print(channel:Name() .. " was closed.")
end
local myCustomChannel = Channel.New("Custom Channel", mySpeakCallback, myCloseCallback)
Channel.SendYellowMessage(myCustomChannel, "XBLuaDoc", "Welcome to the custom channel.")
Example 2: Sending welcome message to custom channel (object oriented programming)
function mySpeakCallback(channel, text)
channel:SendYellowMessage(Self.Name(), text)
end
function myCloseCallback(channel)
print(channel:Name() .. " was closed.")
end
local myCustomChannel = Channel.New("Custom Channel", mySpeakCallback, myCloseCallback)
myCustomChannel:SendYellowMessage("XBLuaDoc", "Welcome to the custom channel.")
Chuitox
09-08-2014, 07:35 AM
Functionality: Minimizes the equipment window. See also: Client.ShowEquipment() (http://forums.xenobot.net/showthread.php?28585-Xenobot-Lua-Documentation&p=364952&viewfull=1#post364952)
CAUTION: Dialog windows must be closed
-- (void) No value returned
Client.HideEquipment()
Examples
Example 1: Minimize equipment after opening main backpack
Self.OpenMainBackpack()
wait(200)
Client.HideEquipment()
Chuitox
09-08-2014, 07:40 AM
Functionality: Maximizes the equipment window. See also: Client.HideEquipment() (http://forums.xenobot.net/showthread.php?28585-Xenobot-Lua-Documentation&p=364951&viewfull=1#post364951)
CAUTION: Dialog windows must be closed
-- (void) No value returned
Client.ShowEquipment()
Examples
Example 1: Maximize equipment after closing all containers
Self.CloseContainers()
wait(200)
Client.ShowEquipment()
Chuitox
09-08-2014, 08:58 AM
Functionality: Creates a container from name, item ID or index
Note: All object constructors can be used without the word New. See below for more details.
-- (string) value: Name, item ID or index of the container
-- (object) returns Container
Container.New(value)
-- Possible alternatives:
Container(value)
Examples
Example 1: Referencing main backpack by index. (Container must be open)
Self.CloseContainers()
wait(200)
Self.OpenMainBackpack()
wait(200)
local myMainBackpack = Container.New(0)
Example 2: Referencing container by name. (Container must be open)
Self.CloseContainers()
wait(200)
Self.OpenMainBackpack()
wait(200)
local myJewelledBackpack = Container("jewelled backpack")
Example 3: Referencing container by item ID. (Container must be open)
Self.CloseContainers()
wait(200)
Self.OpenMainBackpack()
wait(200)
local myBackpackOfHolding = Container(3253) -- Item.GetID("backpack of holding")
Chuitox
09-08-2014, 09:12 AM
Functionality: Gets the index for a new container
Note: Not compatible with Open Tibia Servers
-- (number) returns index of available slot between 0 and 15. Returns -1 if index was not found
Container.GetFreeSlot()
Examples
Example 1: Attempt to open all containers inside main backpack
Self.CloseContainers()
wait(200 + Self.Ping())
local mainBackpack = Self.OpenMainBackpack()
local freeSlot = Container.GetFreeSlot()
wait(200 + Self.Ping())
while(freeSlot ~= -1) do
for slot, item in mainBackpack:iItems() do
if Item.isContainer(item.id) then
mainBackpack:UseItem(slot, false)
wait(500 + Self.Ping())
Container(freeSlot):Minimize()
wait(100 + Self.Ping())
end
end
freeSlot = Container.GetFreeSlot()
end
dezaodoido
01-21-2015, 06:06 PM
Hi, the skull type numbers are not correct.
Don't know the rest.
Thank you
None = 0
Green = 2
White = 3
Red = ?
Orange = ?
Yellow = ?
Black = ?
rafek1241
02-16-2015, 07:29 PM
More lua explanation please! :)
maroxy
02-22-2015, 11:28 AM
More lua explanation please! :)
That's a lua documentation (XenoBot functions).
Read at lua.org to learn lua :P
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.