Codex NG
Recurrent Flamer
- Joined
- Jul 24, 2015
- Messages
- 2,994
- Solutions
- 12
- Reaction score
- 1,657
I will be using 1.0, 1.1 & 1.2 for this tutorial/explanation.
Since there is no proper documentation for this anywhere, this will be it.
First let me say this so its out of the way, an interface is not a function in the sense that
we know of like add(2, 2) = 4, no it is a mechanism which allows us to interact with the server.
The parameters of the interface are actually arguments which are sent from the server based on our
actions in the game, whether it is logging in, stepping on a tile, equipping or using an item etc..
this information is sent to the interface's parameters, which we then use in our scripts.
List of interfaces
Actions
Chat Channel Events
Creature Events
Global Events
Monster Events
Movements
NPCs
Raids
Talkactions
Spells
Weapons
--------------------------------------------
cid, player, creature, npc, monster
1.0
The parameter cid is the id of the player, creature, npc or monster
1.1 - 1.2
The parameter player, creature, npc, monster is userdata, it is a pointer to a metatable of the
respected argument, however the argument can be creature and be refering to a player or monster etc..
this is why we use
To determine if the value passed is the intended target.
Please note, this information might not be 100% correct, but it is better than nothing.
This code is lifted from the sources.
--------------------------------------------
Actions
onUse
1.0
1.1 / 1.2
item is userdata it contains the itemid and unique id of the item, however it also
contains other things like the name, description etc and is accessable via its metamethods.
fromPosition is a metatable which contains x, y, z & stackpos of the item, fromPosition
returns the position of where the item you are using came from.. e.g. your backpack, the ground etc..
itemEx or target is userdata it contains the itemid and unique id of the item you use the item on,
however it also contains other things like the name, description etc and is accessable via its metamethods.
toPosition is a metatable which contains x, y, z & stackpos of the itemEx or target, toPosition returns
the position of itemEx or target.. e.g. your backpack, the ground etc..
isHotkey is a boolean value, the return value of this is true if a hotkey was pressed and false if it wasn't.
--------------------------------------------
Movements
onStepIn & onStepOut
1.0
1.1 / 1.2
We've already discussed cid and creature,
item see actions for indepth explanation, however it is not an item you use, it is an item you walk on or off, this doesn't
have to be a stationary item such a ground tile this can be a moveable item aswell.
pos is the position of the item you are walking on or off.
fromPosition is the position of where you came from.
onEquip & onDeEquip
1.0
1.1 / 1.2
Both onEquip and onDeEquip are only used by the player, see the cid and player
explanation above, item see the indepth explanation above, however it is not an
item you step on or off, or even an item you use, it is as the name of the interfaces imply it is
an item in which you equip to or remove from the player.
slot is a number, the slot id of where item is equipped to or de-equipped from.
onAddItem & onRemoveItem
1.0 - 1.2
Both moveitem & tileitem are userdata, moveitem is the item you move on to tileitem, pos is a table with the position of tileitem.
For instance if tileitem is a dustbin (itemid 1777), and you took your backpack off and tossed it in the dustbin, moveitem would be your backpack.
This rule applies to both onAddItem & onRemoveItem and can be used in conjunction with onStepIn or onStepOut or both.
--------------------------------------------
Talkactions
onSay
1.0
1.1 - 1.2
See cid and player above for an in-depth explanation.
words is a string, it contains the command used when executing the talkaction.
param is also a string it contains the argument you pass to the command.
type is a number it is the speak class used when executing the talkaction.
If you run a print(type(type)) over it will return 1, which is TALKTYPE_SAY
--------------------------------------------
Raids
onRaid
1.0 - 1.2
onRaid has no parameters, its parameters are read from the xml which is beyond the scope of this tutorial.
--------------------------------------------
Since there is no proper documentation for this anywhere, this will be it.
First let me say this so its out of the way, an interface is not a function in the sense that
we know of like add(2, 2) = 4, no it is a mechanism which allows us to interact with the server.
The parameters of the interface are actually arguments which are sent from the server based on our
actions in the game, whether it is logging in, stepping on a tile, equipping or using an item etc..
this information is sent to the interface's parameters, which we then use in our scripts.
List of interfaces
Actions
Code:
onUse
Chat Channel Events
Code:
canJoin
onJoin
onLeave
onSpeak
Creature Events
Code:
onAdvance
onDeath
onExtendedOpcode
onHealthChange
onKill
onLogin
onLogout
onManaChange
onModalWindow
onPrepareDeath
onTextEdit
onThink
Global Events
Code:
onRecord
onShutdown
onStartup
onTime
Monster Events
Code:
onCreatureAppear
onCreatureDisappear
onCreatureMove
onCreatureSay
onThink
Movements
Code:
onAddItem
onDeEquip
onEquip
onRemoveItem
onStepIn
onStepOut
NPCs
Code:
onCreatureAppear
onCreatureDisappear
onCreatureMove
onCreatureSay
onPlayerCloseChannel
onPlayerEndTrade
onThink
Raids
Code:
onRaid
Talkactions
Code:
onSay
Spells
Code:
onCastSpell
Weapons
Code:
onUseWeapon
cid, player, creature, npc, monster
1.0
The parameter cid is the id of the player, creature, npc or monster
1.1 - 1.2
The parameter player, creature, npc, monster is userdata, it is a pointer to a metatable of the
respected argument, however the argument can be creature and be refering to a player or monster etc..
this is why we use
Code:
if isPlayer(cid) then
-- do something
end
or
if creature:isPlayer() then
-- do something
end
Please note, this information might not be 100% correct, but it is better than nothing.
This code is lifted from the sources.
--------------------------------------------
Actions
onUse
1.0
Code:
onUse(cid, item, fromPosition, itemEx, toPosition, isHotkey)
1.1 / 1.2
Code:
onUse(player, item, fromPosition, target, toPosition, isHotkey)
contains other things like the name, description etc and is accessable via its metamethods.
fromPosition is a metatable which contains x, y, z & stackpos of the item, fromPosition
returns the position of where the item you are using came from.. e.g. your backpack, the ground etc..
itemEx or target is userdata it contains the itemid and unique id of the item you use the item on,
however it also contains other things like the name, description etc and is accessable via its metamethods.
toPosition is a metatable which contains x, y, z & stackpos of the itemEx or target, toPosition returns
the position of itemEx or target.. e.g. your backpack, the ground etc..
isHotkey is a boolean value, the return value of this is true if a hotkey was pressed and false if it wasn't.
--------------------------------------------
Movements
onStepIn & onStepOut
1.0
Code:
onStepIn(cid, item, pos, fromPosition)
onStepOut(cid, item, pos, fromPosition)
1.1 / 1.2
Code:
onStepIn(creature, item, pos, fromPosition)
onStepOut(creature, item, pos, fromPosition)
We've already discussed cid and creature,
item see actions for indepth explanation, however it is not an item you use, it is an item you walk on or off, this doesn't
have to be a stationary item such a ground tile this can be a moveable item aswell.
pos is the position of the item you are walking on or off.
fromPosition is the position of where you came from.
onEquip & onDeEquip
1.0
Code:
onEquip(cid, item, slot)
onDeEquip(cid, item, slot)
1.1 / 1.2
Code:
onEquip(player, item, slot)
onDeEquip(player, item, slot)
Both onEquip and onDeEquip are only used by the player, see the cid and player
explanation above, item see the indepth explanation above, however it is not an
item you step on or off, or even an item you use, it is as the name of the interfaces imply it is
an item in which you equip to or remove from the player.
slot is a number, the slot id of where item is equipped to or de-equipped from.
onAddItem & onRemoveItem
1.0 - 1.2
Code:
onAddItem(moveitem, tileitem, pos)
onRemoveItem(moveitem, tileitem, pos)
Both moveitem & tileitem are userdata, moveitem is the item you move on to tileitem, pos is a table with the position of tileitem.
For instance if tileitem is a dustbin (itemid 1777), and you took your backpack off and tossed it in the dustbin, moveitem would be your backpack.
This rule applies to both onAddItem & onRemoveItem and can be used in conjunction with onStepIn or onStepOut or both.
--------------------------------------------
Talkactions
onSay
1.0
Code:
onSay(cid, words, param, type)
Code:
onSay(player, words, param, type)
words is a string, it contains the command used when executing the talkaction.
param is also a string it contains the argument you pass to the command.
type is a number it is the speak class used when executing the talkaction.
If you run a print(type(type)) over it will return 1, which is TALKTYPE_SAY
--------------------------------------------
Raids
onRaid
1.0 - 1.2
Code:
onRaid()
onRaid has no parameters, its parameters are read from the xml which is beyond the scope of this tutorial.
--------------------------------------------
Last edited: