View Full Version : [Discussion] Scripter: Variables, Functions, and Events
jo3bingham
01-03-2012, 09:47 PM
This thread is for the discussion of the scripter's variables, functions, and events. You can find the original thread here: http://forums.xenobot.net/showthread.php?767-Scripter-Variables-Functions-and-Events
Y2Quake
01-04-2012, 12:58 AM
You're doing a nice job with it dude. I hope it has much functions and variables as neobot, but i can expect even more than neo.
keep it.
Hawkeye
01-04-2012, 05:44 AM
Do, what you do best. I'm w8ing for this bot.
Raphael
01-04-2012, 08:08 AM
Seems weird to be using methods instead of properties.
playmate
01-04-2012, 09:07 AM
Don't understand shit right now. But I think you know what you're doing.
Keep it up
Maxwell
01-04-2012, 11:05 AM
=o so will it be possible for the bot to invite a player to party / join a party?
Nice to see that the scripter idea is getting improved.
But it seems to be lill' bit complicate by now like NG was. To realize a couple of functions it would take so much lines of "programming" and it seems to be a LOT limited too i think that a good idea is export some idea from neo libraries and take some functions like "pickupitems" "auto" "dropitemsxyz" "ifattacked" these things.
Btw, gz for nice job.
Att.,
Raphael
01-04-2012, 04:10 PM
.Position returns a table or what? Numeric indexes?
Raphael
01-04-2012, 10:23 PM
Also, what about pre-defined creature objects, such Self, Target, Followed, etc...
sirmate
01-04-2012, 10:35 PM
Also, what about pre-defined creature objects, such Self, Target, Followed, etc...
Make them by yourself... lazy...
local self = Creature.GetByID(getSelfID())
local target = Creature.GetByID(getSelfTargetID())
local followed = Creature.GetByID(getSelfFollowID())
Efren
01-04-2012, 11:16 PM
Make them by yourself... lazy...
local self = Creature.GetByID(getSelfID())
local target = Creature.GetByID(getSelfTargetID())
local followed = Creature.GetByID(getSelfFollowID())
If I'm not mistaken they already exist.
this are the relational properties. (can be found on the Creature.lua or Jo3 post)
Creature:isSelf()
Creature:isTarget()
Creature:isFollowed()
an example of using this variables would be.. (using Jo3 example)
Again if im not mistaken.
local creature = Creature.GetByName("Jo3Bingham")
if (creature:ID() ~= 0) then
if (creature:isTarget() and creature:WarIcon()) then
----use spell or rune
end
end
If everything is fine then Jo3 will die.
sirmate
01-04-2012, 11:33 PM
If I'm not mistaken they already exist.
this are the relational properties. (can be found on the Creature.lua or Jo3 post)
Creature:isSelf()
Creature:isTarget()
Creature:isFollowed()
an example of using this variables would be.. (using Jo3 example)
Again if im not mistaken.
local creature = Creature.GetByName("Jo3Bingham")
if (creature:ID() ~= 0) then
if (creature:isTarget() and Creature:WarIcon()) then
----use spell or rune
end
end
If everything is fine then Jo3 will die.
Nope, you're a little wrong.
By using those functions you currently only check if creature is you itself, your target or creature that you follow.
He had in mind something like $self, $target, $attacked, $followed in neobot. Those variables was returning creature pointers.
Also I want to know if there will be some variable or loop like in neobot that would be returning all creatures (players/monsters/npc's) from screen (all floors)?
Efren
01-05-2012, 12:02 AM
Nope, you're a little wrong.
By using those functions you currently only check if creature is you itself, your target or creature that you follow.
He had in mind something like $self, $target, $attacked, $followed in neobot. Those variables was returning creature pointers.
Also I want to know if there will be some variable or loop like in neobot that would be returning all creatures (players/monsters/npc's) from screen (all floors)?
Atm i think I'm correct.
I'll use the same script but with line comments to point out what's happening. (on my opinion)
local creature = Creature.GetByName("Jo3Bingham") -- creature = Jo3Bingham
-- first If statement is checking the "creature:ID" which means Jo3Bingham ID's, example: Jo3Bingham:ID()
if (creature:ID() ~= 0) then
-- sencond If statement is cheking that , Jo3Bingham:isTarget() and Jo3Bingham:WarIcon()
if (creature:isTarget() and Creature:WarIcon()) then
----use spell or rune
end
end
I personally thing that way, I might be wrong but, for undestranding always a new lengauge I need an script with comment lines that's pointing out what's happening, I have used LUA on Ot's and on Neobot but those " : " are confusing me alot.
sirmate, try to point out what's happening on this script for me to understand your way of viewing this script.
silis
01-05-2012, 12:24 AM
Also I want to know if there will be some variable or loop like in neobot that would be returning all creatures (players/monsters/npc's) from screen (all floors)?
This.
It's really useful to have as much pointers, variables, booleans as possible to expand the possibilities for this bot!
sirmate
01-05-2012, 12:28 AM
...
But while you exp your target changes it's not always the same. If you used NeoBot then you should know how $target pointer works.
Here is my example.
local Target = Creature.GetByID(getSelfTargetID())
if (Target:Name():lower() == 'wyrm' and Target:HealthPercent() >= 10 and Target:isAdjacent()) then
--[[ CAST EXORI ICO ]]--
end
Efren
01-05-2012, 01:35 AM
But while you exp your target changes it's not always the same. If you used NeoBot then you should know how $target pointer works.
Here is my example.
local Target = Creature.GetByID(getSelfTargetID())
if (Target:Name():lower() == 'wyrm' and Target:HealthPercent() >= 10 and Target:isAdjacent()) then
--[[ CAST EXORI ICO ]]--
end
I don't use neo but I did, Was completely GUI-less, Not atractive.
Bot's are my baby bitches, Neo bot was ugly as hell, but was able to move very nice. (you know what I mean)
I don't know who is correct, me or you, or maybe both are, or maybe just you. (But I think Im wrong, for sure lmao xD)
I just can't wait for the scripter!
So I'm making non-sence scripts :)
Raphael
01-05-2012, 04:22 PM
Make them by yourself... lazy...
local self = Creature.GetByID(getSelfID())
local target = Creature.GetByID(getSelfTargetID())
local followed = Creature.GetByID(getSelfFollowID())
There is no fkn GetSelfId() or GetTargetId().
noob
If I'm not mistaken they already exist.
this are the relational properties. (can be found on the Creature.lua or Jo3 post)
Creature:isSelf()
Creature:isTarget()
Creature:isFollowed()
an example of using this variables would be.. (using Jo3 example)
Again if im not mistaken.
local creature = Creature.GetByName("Jo3Bingham")
if (creature:ID() ~= 0) then
if (creature:isTarget() and creature:WarIcon()) then
----use spell or rune
end
end
If everything is fine then Jo3 will die.
No dude, this only checks if the creature pointer you have, is the target or you. If you wanted to find the target's pointer, you'd have to either loop through all creatures and check if isTarget() or have a pre-defined pointer assigned to it, which is what I'm asking for.
jo3bingham
01-05-2012, 06:06 PM
There will be pointers as such (self, target, etc.). The Creature class, and more, just allows you to have more control over your scripts.
Efren
01-06-2012, 09:19 PM
Make them by yourself... lazy...
local self = Creature.GetByID(getSelfID())
local target = Creature.GetByID(getSelfTargetID())
local followed = Creature.GetByID(getSelfFollowID())
There is no fkn GetSelfId() or GetTargetId().
noob
They exist, Check the Creature.lua
---------------------------------------------------
----------- Relational Properties ---------------
---------------------------------------------------
function Creature:isSelf()
return self._id == getSelfID()
end
function Creature:isTarget()
return self._id == getSelfTargetID()
end
function Creature:isFollowed()
return self._id == getSelfFollowID()
end
jo3bingham
01-06-2012, 09:23 PM
They exist, Check the Creature.lua
---------------------------------------------------
----------- Relational Properties ---------------
---------------------------------------------------
function Creature:isSelf()
return self._id == getSelfID()
end
function Creature:isTarget()
return self._id == getSelfTargetID()
end
function Creature:isFollowed()
return self._id == getSelfFollowID()
end
Burn! Ohhh, but seriously, he probably wasn't aware of the Creature.lua file, or unable to read. Which is correct? I'm unsure.
Raphael
01-06-2012, 09:23 PM
They exist, Check the Creature.lua
---------------------------------------------------
----------- Relational Properties ---------------
---------------------------------------------------
function Creature:isSelf()
return self._id == getSelfID()
end
function Creature:isTarget()
return self._id == getSelfTargetID()
end
function Creature:isFollowed()
return self._id == getSelfFollowID()
end
Well, they're not documented.
Efren
01-06-2012, 09:38 PM
Well, they're not documented.
They are, is the same as writing
Creature:isSelf()
Creature:isTarget()
Creature:isFollowed()
or maybe just (correct me if I'm wrong.)
isSelf()
isTarget()
isFollowed()
Raphael
01-06-2012, 09:42 PM
They are, is the same as writing
Creature:isSelf()
Creature:isTarget()
Creature:isFollowed()
or maybe just (correct me if I'm wrong.)
isSelf()
isTarget()
isFollowed()
That's not documentation, that's implementation. This (http://forums.xenobot.net/showthread.php?767-Scripter-Variables-Functions-and-Events) is documentation, and is where the thread starter states that ALL variables and functions would be.
Efren
01-06-2012, 10:02 PM
That's not documentation, that's implementation. This (http://forums.xenobot.net/showthread.php?767-Scripter-Variables-Functions-and-Events) is documentation, and is where the thread starter states that ALL variables and functions would be.
There's no need of writing getSelfID() instead of Creature:isSelf() or isSelf(), both works the same way just that they are written with a "diferent name". and writing EVERY SINGLE "variable" that is used for a variable that already exist would be a pain on the ass.
For example
LookDirection() is the same as writing getCreatureLookDirection(self._id)
Speed() is the same as writing getCreatureSpeed(self._id)
Outfit() is the same as writing getCreatureOutfit(self._id)
HealthPercent() is the same as writing getCreatureHealthPercent(self._id)
There's no need for the users/customers of knowing the "return value" of each variable.
Raphael
01-06-2012, 10:04 PM
There's no need of writing getSelfID() instead of Creature:isSelf() or isSelf(), both works the same way just that they are written with a "diferent name". and writing EVERY SINGLE "variable" that is used for a variable that already exist would be a pain on the ass.
For example
LookDirection() is the same as writing getCreatureLookDirection(self._id)
Speed() is the same as writing getCreatureSpeed(self._id)
Outfit() is the same as writing getCreatureOutfit(self._id)
HealthPercent() is the same as writing getCreatureHealthPercent(self._id)
There's no need for the users/customers of knowing the "return value" of each variable.
No, they are different things.
Efren
01-06-2012, 10:12 PM
No, they are different things.
Is the same thing, all of 'em are the return values of a variable, just look at this code.
-- On this code the variable is "Speed()"
-- and the return value (for the variable to work) is getCreatureSpeed(self._id)
-- So There's no need for the users/customers of knowing the "return value" of each variable.
-- code starts here
function Creature:Speed()
return getCreatureSpeed(self._id)
end
Raphael
01-06-2012, 10:15 PM
Ok then. Tell me how you find the Name of your target only using isTarget().
Efren
01-06-2012, 10:20 PM
Ok then. Tell me how you find the Name of your target only using isTarget().
maybe with getById(isTarget())
--comment, You will never find the name of your target only using the isTarget() the only thing you get is their id, so you need to convert that id to a name, using the getById.
(If I'm not mistaken)
Raphael
01-06-2012, 11:00 PM
maybe with getById(isTarget())
--comment, You will never find the name of your target only using the isTarget() the only thing you get is their id, so you need to convert that id to a name, using the getById.
(If I'm not mistaken)
You don't get the fucking id using isTarget(). That only proves they're different things.
What I meant is, find the name of your target without directly using getTargetId().
Efren
01-07-2012, 01:50 AM
You don't get the fucking id using isTarget(). That only proves they're different things.
You can't lie to the code, an this proves is the same thing...
function Creature:isTarget()
return self._id == getSelfTargetID()
end
What I meant is, find the name of your target WITHOUT directly using getTargetId().
getTargetId() Doesn't exist, Probably you meant to say getSelfTargetID()
As I say before "getById(isTarget())" would be the way to get the name of your current target.
getById() is used to get their name by their id, so writing an id inside the "()" will tell you the name.
isTarget() will return the id of your current target.
This can also be written like the following codes.
GetByID(getSelfTargetID())
--or
getCreatureNameById(getSelfTargetID())
--or
GetByID(isTarget())
--or
getCreatureNameById(isTarget())
an example implemented on a script would be.
(examples taken from sirmate all credits for him)
local target = Creature.GetByID(getSelfTargetID())
--or just the one I made
local targetname = Creature.GetByID(isTarget())
jo3bingham
01-07-2012, 03:55 AM
Stop arguing before I throw infractions out like a blind squirrel! It doesn't matter if I documented it or not, yet. It's in the Creature class so that means it exists, but I haven't documented it. Calm down, both of you! Good grief, you're like a bunch of babies. Get offline, go ween yourself off your mother's teet, then come back when you've grown up...
Efren
01-07-2012, 04:43 AM
Stop arguing before I throw infractions out like a blind squirrel! It doesn't matter if I documented it or not, yet. It's in the Creature class so that means it exists, but I haven't documented it. Calm down, both of you! Good grief, you're like a bunch of babies. Get offline, go ween yourself off your mother's teet, then come back when you've grown up...
It's Done :)
Raphael
01-07-2012, 12:28 PM
You can't lie to the code, an this proves is the same thing...
function Creature:isTarget()
return self._id == getSelfTargetID()
end
getTargetId() Doesn't exist, Probably you meant to say getSelfTargetID()
As I say before "getById(isTarget())" would be the way to get the name of your current target.
getById() is used to get their name by their id, so writing an id inside the "()" will tell you the name.
isTarget() will return the id of your current target.
This can also be written like the following codes.
GetByID(getSelfTargetID())
--or
getCreatureNameById(getSelfTargetID())
--or
GetByID(isTarget())
--or
getCreatureNameById(isTarget())
an example implemented on a script would be.
(examples taken from sirmate all credits for him)
local target = Creature.GetByID(getSelfTargetID())
--or just the one I made
local targetname = Creature.GetByID(isTarget())
No dude, one returns a boolean and the other returns a integer. Creature.GetByID(isTarget()) simply won't work.
@Jo3
Sorry, I can't help it. Plus, I see no bad, seeing as we're arguing without flaming or bad words.
Blequi
01-07-2012, 01:19 PM
really, reading the post http://forums.xenobot.net/showthread.php?767-Scripter-Variables-Functions-and-Events
and the discussion above, we need a "creature loop".
One solution "not good" to find the target is:
function targetid()
local creature
for i = 1, 100000 do
creature = Creature.GetByID(i)
if creature and creature:isTarget() then
return i
end
end
return false
end
function targetname()
local target = targetid()
return (target and Creature.GetByID(target):Name)
end
PS: not tested because i haven't xenobot.
jo3bingham
01-07-2012, 06:46 PM
Efren, Raphael is correct. isTarget() returns a boolean (yes/no), getSelfTargetID() returns the actual ID of your character's target.
Blequi, that's a bad, bad way to get it. Just use getSelfTargetID()
local Target = Creature.GetByID(getSelfTargetID())
----then use Target:Name() to return your target's name
Blequi
01-07-2012, 07:07 PM
i didn't know the existence of getSelfTargetID(), at least you didn't post.
jo3bingham
01-07-2012, 07:13 PM
i didn't know the existence of getSelfTargetID(), at least you didn't post.
It's in the Creature.lua file that comes with XenoBot when you install it. I just haven't gotten around to adding it to the main post. I apologize, I'm just lazy, haha.
Blequi
01-07-2012, 07:18 PM
It's in the Creature.lua file that comes with XenoBot when you install it. I just haven't gotten around to adding it to the main post. I apologize, I'm just lazy, haha.
now, I'm very curious to own and read this file.
jo3bingham
01-07-2012, 07:36 PM
now, I'm very curious to own and read this file.
I'm mistaken. DarkstaR, I think, accidentally included it with a previous version of XenoBot, but you can view it here: http://pastebin.com/3vDpZWL3
Blequi
01-07-2012, 09:00 PM
I read everything that was on the link and noticed that the secret of these functions you posted are "get...()".
would be very useful if you make a list of all "get...()"
Raphael
01-07-2012, 09:26 PM
I read everything that was on the link and noticed that the secret of these functions you posted are "get...()".
would be very useful if you make a list of all "get...()"
They're in the file Jo3Bingham posted, on the last post.
Blequi
01-07-2012, 09:31 PM
They're in the file Jo3Bingham posted, on the last post.
but idk if there are more.
Raphael
01-07-2012, 09:40 PM
but idk if there are more.
No one does.
jo3bingham
01-07-2012, 09:41 PM
I read everything that was on the link and noticed that the secret of these functions you posted are "get...()".
would be very useful if you make a list of all "get...()"
There are more get...() functions, and I'll make a list of all of them when I have access to more. What you see in that link is all that I have access to at this moment. Which is why I haven't documented any other functions yet, even though they're in that class, because I'd like to get as many as I can before documenting.
eachziN
01-16-2012, 11:18 AM
is there any function to open the trade channel? and choose the itemid of potions for example?
malin
01-16-2012, 12:09 PM
Hi,
I want to ask about function to check how many mana vials I have left, is some function similar to SelSelf.Cap() ?
thanks for feedback
best regards
Bushu
01-21-2012, 09:25 AM
Function 'isVisible' does not work for me. Can't do anything with it.
Y2Quake
02-28-2012, 02:07 AM
Will it get updated?
jo3bingham
02-28-2012, 03:14 AM
Sorry, guys. I've been quite busy lately with other things. I promise I'll try to update the list as soon as possible.
Spectrus
02-28-2012, 08:52 PM
In the meantime, here's the contents of XenoLuaLib.lua located in Program Files/Xenobot/Data
EDIT: Woah, that's long. D:
-- UTILITIES
------------
--Numpad math
VK_MULTIPLY = 0x6A
VK_ADD = 0x6B
VK_SUBTRACT = 0x6D
VK_DIVIDE = 0x6F
--FKeys
VK_F1 = 0x70
VK_F2 = 0x71
VK_F3 = 0x72
VK_F4 = 0x73
VK_F5 = 0x74
VK_F6 = 0x75
VK_F7 = 0x76
VK_F8 = 0x77
VK_F9 = 0x78
VK_F10 = 0x79
VK_F11 = 0x7A
VK_F12 = 0x7B
VK_F13 = 0x7C
VK_F14 = 0x7D
VK_F15 = 0x7E
VK_F16 = 0x7F
VK_F17 = 0x80
VK_F18 = 0x81
VK_F19 = 0x82
VK_F20 = 0x83
VK_F21 = 0x84
VK_F22 = 0x85
VK_F23 = 0x86
VK_F24 = 0x87
--Home, insert, etc
VK_PRIOR = 0x21
VK_NEXT = 0x22
VK_INSERT = 0x2D
VK_DELETE = 0x2E
VK_END = 0x23
VK_HOME = 0x24
--Skull types
SKULL_WHITE = 1
SKULL_RED = 4
SKULL_ORANGE = 2
SKULL_YELLOW = 3
SKULL_BLACK = 5
--Party shield types
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
--War shit
WAR_ENEMY = 1
WAR_ALLY = 2
WAR_INWAR = 3
function isPositionAdjacent(pos1, pos2)
return (math.abs(pos1.x - pos2.x) <= 1 and math.abs(pos1.y - pos2.y) <= 1 and pos1.z == pos2.z)
end
function getDistanceBetween(pos1, pos2)
return math.sqrt(math.abs(pos1.x - pos2.x) ^ 2 + math.abs(pos1.y - pos2.y) ^ 2)
end
function wait(a, b)
if not b then sleep(a) else sleep(math.random(a, b)) end
end
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------- CREATURE CLASS ----------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Creature = {}
Creature.__index = Creature
function Creature.GetByName(name)
local c = {}
setmetatable(c, Creature)
c._name = name
c._id = getCreatureID(name)
c._listindex = getCreatureListIndex(c._id)
return c
end
function Creature.GetByID(id)
local c = {}
setmetatable(c, Creature)
c._id = id
c._listindex = getCreatureListIndex(id)
c._name = getCreatureName(c._listindex)
return c
end
function Creature.GetFromIndex(index)
return Creature.GetByID(getCreatureIDFromIndex(index))
end
---------------------------------------------------
------------ Basic Properties -------------------
---------------------------------------------------
function Creature:isValid()
return (self._id > 0 and self._listindex < 1300 and self._listindex > 0)
end
function Creature:Name()
return self._name
end
function Creature:ID()
return self._id
end
function Creature:Index()
return self._listindex
end
function Creature:LookDirection()
return getCreatureLookDirection(self._listindex)
end
function Creature:Speed()
return getCreatureSpeed(self._listindex)
end
function Creature:Outfit()
return getCreatureOutfit(self._listindex)
end
function Creature:HealthPercent()
return getCreatureHealthPercent(self._listindex)
end
---------------------------------------------------
----------- Relational Properties ---------------
---------------------------------------------------
function Creature:isSelf()
return self._id == getSelfID()
end
function Creature:isTarget()
return self._id == getSelfTargetID()
end
function Creature:isFollowed()
return self._id == getSelfFollowID()
end
---------------------------------------------------
------------ Skull Properties ------------------
---------------------------------------------------
function Creature:Skull()
return getCreatureSkull(self._id)
end
function Creature:isWhiteSkull()
return self:Skull() == SKULL_WHITE
end
function Creature:isRedSkull()
return self:Skull() == SKULL_RED
end
function Creature:isOrangeSkull()
return self:Skull() == SKULL_ORANGE
end
function Creature:isYellowSkull()
return self:Skull() == SKULL_YELLOW
end
function Creature:isBlackSkull()
return self:Skull() == SKULL_BLACK
end
---------------------------------------------------
------------ Shield Properties ------------------
---------------------------------------------------
function Creature:PartyStatus()
return getCreaturePartyStatus(self._listindex)
end
function Creature:isPartyLeader()
return (self:PartyStatus() == PARTY_YELLOW or
self:PartyStatus() == PARTY_YELLOW_SHAREDEXP or
self:PartyStatus() == PARTY_YELLOW_NOSHAREDEXP_BLINK or
self:PartyStatus() == PARTY_YELLOW_NOSHAREDEXP)
end
function Creature:isPartyMember()
return (Creature:isPartyLeader() or
self:PartyStatus() == PARTY_BLUE or
self:PartyStatus() == PARTY_BLUE_SHAREDEXP or
self:PartyStatus() == PARTY_BLUE_NOSHAREDEXP_BLINK or
self:PartyStatus() == PARTY_BLUE_NOSHAREDEXP)
end
function Creature:isInvitedToParty()
return self:PartyStatus() == PARTY_WHITEBLUE
end
function Creature:isInvitingToParty()
return self:PartyStatus() == PARTY_WHITEYELLOW
end
function Creature:isSharingExp()
return (self:PartyStatus() == PARTY_BLUE_SHAREDEXP or
self:PartyStatus() == PARTY_YELLOW_SHAREDEXP)
end
---------------------------------------------------
------------ War Properties ------------------
---------------------------------------------------
function Creature:WarIcon()
return getCreatureWarIcon(self._listindex)
end
function Creature:isWarEnemy()
return self:WarIcon() == WAR_ENEMY
end
function Creature:isWarAlly()
return self:WarIcon() == WAR_ALLY
end
function Creature:isInWar()
return (self:WarIcon() == WAR_INWAR or self:isWarAlly() or self:isWarEnemy())
end
---------------------------------------------------
---------- Location Properties ---------------
---------------------------------------------------
function Creature:Position()
return getCreaturePosition(self._listindex)
end
function Creature:isReachable()
return "Not implemented"-- isPathFound(self:Position())
end
function Creature:isAdjacent()
return isPositionAdjacent(self:Position(), getSelfPosition())
end
function Creature:isOnScreen()
local selfloc = getSelfPosition()
local thisloc = self:Position()
return (math.abs(selfloc.x - thisloc.x) <= 7 and
math.abs(selfloc.y - thisloc.y) <= 5
and selfloc.z == thisloc.z)
end
function Creature:isAlive()
return getCreatureHealthPercent(self._listindex) > 0
end
function Creature:isVisible()
return getCreatureVisible(self._listindex)
end
function Creature:DistanceFromSelf()
return getDistanceBetween(self:Position(), getSelfPosition())
end
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------- Container CLASS ----------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Container = {}
Container.__index = Container
function Container.GetFirst()
return Container.GetNextOpen(-1)
end
function Container.GetNextOpen(index)
local found = false
while (found == false and index < 16) do
index = index + 1
found = getContainerOpen(index)
end
if (found == false) then
index = -1
end
return Container.GetFromIndex(index)
end
function Container.GetByName(name)
local index = -1
while (index < 16) do
index = index + 1
if (getContainerOpen(index)) then
if (getContainerName(index) == name) then
return Container.GetFromIndex(index)
end
end
end
return Container.GetFromIndex(-1)
end
function Container.GetFromIndex(index)
local c = {}
setmetatable(c, Container)
if (getContainerOpen(index)) then
c._index = index
else
c._index = -1
end
return c
end
---------------------------------------------------
------------ Basic Functions -------------------
---------------------------------------------------
function Container:GetNext()
return Container.GetNextOpen(self._index)
end
function Container:Index()
return self._index
end
function Container:ID()
return getContainerID(self._index)
end
function Container:Name()
return getContainerName(self._index)
end
function Container:ItemCount()
return getContainerItemCount(self._index)
end
function Container:ItemCapacity()
return getContainerItemCapacity(self._index)
end
function Container:isOpen()
return getContainerOpen(self._index)
end
---------------------------------------------------
------------ Working With Items ---------------
---------------------------------------------------
function Container:CountItemsOfID(id)
local count = 0
for spot = 0, self:ItemCount() do
local item = self:GetItemData(spot)
if (item.id == id) then
count = count + item.count
end
end
return count
end
function Container:GetItemData(spot)
return getContainerSpotData(self._index, spot)
end
function Container:UseItem(spot)
return containerUseItem(self._index, spot)
end
function Container:UseItemWithGround(spot, x, y, z)
return containerUseItemWithGround(self._index, spot, x, y, z)
end
function Container:UseItemWithCreature(spot, id)
return containerUseItemWithCreature(self._index, spot, id)
end
function Container:MoveItemToEquipment(spot, slot)
return containerMoveItemToSlot(self._index, spot, slot)
end
function Container:MoveItemToGround(spot, x, y, z)
return containerMoveItemToGround(self._index, spot, x, y, z)
end
function Container:MoveItemToContainer(spotfrom, containerto, spotto)
return containerMoveItemToContainer(self._index, spotfrom, containerto, spotto)
end
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------- SELF CLASS ----------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Self = {}
Self.Say = selfSay
Self.Yell = selfYell
Self.Whisper = selfWhisper
Self.SayToNpc = selfNpcSay
Self.ID = getSelfID
Self.TargetID = getSelfTargetID
Self.FollowID = getSelfFollowID
Self.Position = getSelfPosition
Self.LookDirection = getSelfLookDirection
Self.Speed = getSelfSpeed
Self.Outfit = getSelfOutfit
Self.Skull = getSelfSkull
Self.PartyStatus = getSelfPartyStatus
Self.WarIcon = getSelfWarIcon
Self.MaxHealth = getSelfMaxHealth
Self.Health = getSelfHealth
Self.MaxMana = getSelfMaxMana
Self.Mana = getSelfMana
Self.Experience = getSelfExperience
Self.Level = getSelfLevel
Self.Cap = getSelfCap
Self.UseItem = selfUseItem
Self.UseItemFromGround = selfUseItemFromGround
Self.UseItemWithGround = selfUseItemWithGround
Self.UseItemWithCreature = selfUseItemWithCreature
Self.UseItemFromMyPosition = function ()
return Self.UseItemFromGround(Self.Position().x, Self.Position().y, Self.Position().z)
end
Self.UseItemWithMyPosition = function (id)
return Self.UseItemWithGround(id, Self.Position().x, Self.Position().y, Self.Position().z)
end
Self.UseItemWithMe = function (id)
return Self.UseItemWithCreature(id, Self.ID())
end
Self.UseItemWithTarget = function (id)
return Self.UseItemWithCreature(id, Self.TargetID())
end
Self.UseItemWithFollow = function (id)
return Self.UseItemWithCreature(id, Self.FollowID())
end
Self.Head = getHeadSlotData
Self.Armor = getArmorSlotData
Self.Legs = getLegsSlotData
Self.Feet = getFeetSlotData
Self.Amulet = getAmuletSlotData
Self.Weapon = getWeaponSlotData
Self.Ring = getRingSlotData
Self.Backpack = getBackpackSlotData
Self.Shield = getShieldSlotData
Self.Ammo = getAmmoSlotData
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------- TABLE CLASS ----------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
table.append = table.insert
table.empty = function (t)
return next(t) == nil
end
table.size = function (t)
return #t
end
table.find = function (table, value, sensitive)
local sensitive = sensitive or true
if(not sensitive and type(value) == "string") then
for i, v in pairs(table) do
if(type(v) == "string") then
if(v:lower() == value:lower()) then
return i
end
end
end
return nil
end
for i, v in pairs(table) do
if(v == value) then
return i
end
end
return nil
end
table.contains = function (txt, str)
for i, v in pairs(str) do
if(txt:find(v) and not txt:find('(%w+)' .. v) and not txt:find(v .. '(%w+)')) then
return true
end
end
return false
end
table.isStrIn = table.contains
table.count = function (table, item)
local count = 0
for i, n in pairs(table) do
if(item == n) then
count = count + 1
end
end
return count
end
table.countElements = table.count
table.getCombinations = function (table, num)
local a, number, select, newlist = {}, #table, num, {}
for i = 1, select do
a[#a + 1] = i
end
local newthing = {}
while(true) do
local newrow = {}
for i = 1, select do
newrow[#newrow + 1] = table[a[i]]
end
newlist[#newlist + 1] = newrow
i = select
while(a[i] == (number - select + i)) do
i = i - 1
end
if(i < 1) then
break
end
a[i] = a[i] + 1
for j = i, select do
a[j] = a[i] + j - i
end
end
return newlist
end
function table.serialize(x, recur)
local t = type(x)
recur = recur or {}
if(t == nil) then
return "nil"
elseif(t == "string") then
return string.format("%q", x)
elseif(t == "number") then
return tostring(x)
elseif(t == "boolean") then
return t and "true" or "false"
elseif(getmetatable(x)) then
error("Can not serialize a table that has a metatable associated with it.")
elseif(t == "table") then
if(table.find(recur, x)) then
error("Can not serialize recursive tables.")
end
table.append(recur, x)
local s = "{"
for k, v in pairs(x) do
s = s .. "[" .. table.serialize(k, recur) .. "]" .. " = " .. table.serialize(v, recur) .. ", "
end
return s:sub(0, s:len() - 2) .. "}"
end
error("Can not serialize value of type '" .. t .. "'.")
end
function table.unserialize(str)
return loadstring("return " .. str)()
end
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.