Action
Action's Event Interface

Action.onUse(player, item, fromPosition, itemEx, toPosition, isHotkey)

onUse is an event of the class Action
    player -- 1st arg/parameter /userdata/ = The player who uses the item.
    item -- 2nd arg/parameter/ userdata/ = The first item player uses/use with.
    fromPosition - 3rd arg/parameter/userdata/ = The position the first item is at.
    itemEx -- 4th arg/parameter/userdata/ = The target of item's Use With, can be item or creature
    toPosition - 5th arg/parameter/ userdata/ = The position the first item is used on, with crosshairs.
    isHotkey - 6th arg/parameter/ boolean/ = Did the player use item via hot key? True/False.
    1.
    onUse is called whenever an item registered to the action is used.
    2.
    You can register actions in data/actions/actions.xml
    1
    <action itemid="4856" script="test.lua" />
    Copied!
    1
    <action fromid="2146" toid="2147" script="other/enchanting.lua" />
    Copied!
    3.
    Alternatively you can use revscript method to register via lua, by saving a .lua file in data/scripts folder.
After you have registered your action in actions.xml you can call the event in a script like so:
1
function onUse(player, item, fromPosition, target, toPosition, isHotkey) -- can name the arguments what you like.
2
local SwordLevel = player:getSkillLevel(SKILL_SWORD)
3
if SwordLevel < 70 then
4
player:sendCancelMessage("This technique requires a sword fighting skill of 70 or higher.")
5
return false
6
end
7
8
if not item:hasAttribute(ITEM_ATTRIBUTE_EXTRADEFENSE) then
9
player:sendCancelMessage("Only swords known for their well balance and extra defense are suitable for this task.")
10
return false
11
end
12
13
if fromPosition:isSightClear(toPosition) then
14
player:sendCancelMessage("You must have a clear path to your target")
15
return false
16
end
17
18
if target:isPlayer() then
19
player:sendCancelMessage("To execute this technique properly, the target needs to be a player.")
20
return false
21
end
22
23
if isHotkey then
24
player:sendCancelMessage("You can't use this item with a hotkey!")
25
return false
26
end
27
-- Executing the technique
28
29
-- Teleport to the position
30
player:teleportTo(toPosition)
31
32
-- Configure bleeding damage
33
local bleed = {
34
damage=50,
35
rounds=10,
36
interval=1
37
}
38
-- Apply deadly bleeding attack on target
39
player:addDamageCondition(target, CONDITION_BLEEDING, DAMAGELIST_CONSTANT_PERIOD, bleed.damage, bleed.interval, bleed.rounds)
40
41
-- Warn target that they just got slashed hard from player:getName and their blood is puring out!
42
target:sendTextMessage(MESSAGE_STATUS_WARNING, "You just recieved a blood gushing wound from "..player:getName().."'s deadly sword technique!")
43
return true
44
end
Copied!

Revscript Action

Revscript Actions share the same event onUse() with the same arguments listed above.
To access any events through revscripts, you must create a variable first to access the interface
you must have one variable per event callback no matter which type of interface you wish to access!
Here is an example.
1
local swordTechnique = Action() -- we created a variable to access Action interface
Copied!
Revscript Action has the available methods and event to use with its interface
Event
    onUse(player, item, fromPosition, itemEx, toPosition, isHotkey)
Methods
    action:register() -- Registers the action event.
    action:id(x) -- Registers items with id x for event
    action:aid(x) -- Registers items with action id x for event
    action:uid(x) -- Registers items with unique id x for event
    action:allowFarUse(t/f) -- Allow far use? True/False
    action:blockWalls(t/f) -- Do walls block item usage? True/False
    action:checkFloor(t/f) -- Are we on same floor as target? True/False

Action:id()

1
local swordTechnique = Action() -- we created a variable to access Action interface
2
3
swordTechnique:id(2376) -- sword's itemId to register for event
Copied!

Action:aid()

1
local swordTechnique = Action() -- we created a variable to access Action interface
2
3
swordTechnique:aid(15428) -- an actionId to register for event
Copied!

Action:uid()

1
local swordTechnique = Action() -- we created a variable to access Action interface
2
3
swordTechnique:uid(1337) -- a uniqueId to register for event
Copied!

Action:allowFarUse()

1
local swordTechnique = Action() -- we created a variable to access Action interface
2
3
swordTechnique:allowFarUse(true) -- True/False. True we can be more than one square away to use
Copied!

Action:blockWalls()

1
local swordTechnique = Action() -- we created a variable to access Action interface
2
3
swordTechnique:blockWalls(true) -- True/false. True and walls will block usage of item.
Copied!

Action:checkFloor()

1
local swordTechnique = Action() -- we created a variable to access Action interface
2
3
swordTechnique:checkFloor(true) -- True/false. True and we can only use item on same floor as us.
Copied!
To register an Action script using the Revscript Method, please first ensure it is saved at proper directory location, inside you data/scripts folder, then you can see the same action as above demonstrated as a revscript like so:
1
local swordTechnique = Action() -- we created a variable to access Action interface
2
3
-- Here we register items to use for action, using swordTechnique variable.
4
swordTechnique:id(2376) -- sword's itemId to register for event
5
swordTechnique:aid(15428) -- an actionId to register for event
6
swordTechnique:uid(1337) -- a uniqueId to register for event
7
8
-- Here we configure our other action methods, still using swordTechniqu variable.
9
swordTechnique:allowFarUse(true)
10
swordTechnique:checkFloors(true)
11
swordTechnique:blockWalls(true)
12
13
--- Here we call the event using the same swordTechnique variable.
14
function swordTechnique.onUse(player, item, fromPosition, target, toPosition, isHotkey) -- can name the arguments what you like.
15
16
local SwordLevel = player:getSkillLevel(SKILL_SWORD)
17
if SwordLevel < 70 then
18
player:sendCancelMessage("This technique requires a sword fighting skill of 70 or higher.")
19
return false
20
end
21
22
23
if not item:hasAttribute(ITEM_ATTRIBUTE_EXTRADEFENSE) then
24
player:sendCancelMessage("Only swords known for their well balance and extra defense are suitable for this task.")
25
return false
26
end
27
28
29
if fromPosition:isSightClear(toPosition) then
30
player:sendCancelMessage("You must have a clear path to your target")
31
return false
32
end
33
34
35
if target:isPlayer() then
36
player:sendCancelMessage("To execute this technique properly, the target needs to be a player.")
37
return false
38
end
39
40
41
if isHotkey then
42
player:sendCancelMessage("You can't use this item with a hotkey!")
43
return false
44
end
45
46
-- Executing the technique
47
48
-- Teleport to the position
49
player:teleportTo(toPosition)
50
51
-- Configure bleeding damage
52
local bleed = {
53
damage=50,
54
rounds=10,
55
interval=1
56
}
57
-- Apply deadly bleeding attack on target
58
player:addDamageCondition(target, CONDITION_BLEEDING, DAMAGELIST_CONSTANT_PERIOD, bleed.damage, bleed.interval, bleed.rounds)
59
60
-- Warn target that they just got slashed hard from player:getName and their blood is puring out!
61
target:sendTextMessage(MESSAGE_STATUS_WARNING, "You just recieved a blood gushing wound from "..player:getName().."'s deadly sword technique!")
62
63
return true
64
end
65
66
-- Finally after all logic is completed, we register the event, still using swordTechnique
67
swordTechnique:register()
Copied!
Last modified 3mo ago