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:
functiononUse(player,item,fromPosition,target,toPosition,isHotkey) -- can name the arguments what you like.local SwordLevel = player:getSkillLevel(SKILL_SWORD)if SwordLevel <70then player:sendCancelMessage("This technique requires a sword fighting skill of 70 or higher.")returnfalseendifnot item:hasAttribute(ITEM_ATTRIBUTE_EXTRADEFENSE) then player:sendCancelMessage("Only swords known for their well balance and extra defense are suitable for this task.")
returnfalseendif fromPosition:isSightClear(toPosition) then player:sendCancelMessage("You must have a clear path to your target")returnfalseendif target:isPlayer() then player:sendCancelMessage("To execute this technique properly, the target needs to be a player.")returnfalseendif isHotkey then player:sendCancelMessage("You can't use this item with a hotkey!")returnfalseend-- Executing the technique-- Teleport to the position player:teleportTo(toPosition)-- Configure bleeding damagelocal bleed = { damage=50, rounds=10, interval=1 }-- Apply deadly bleeding attack on target player:addDamageCondition(target, CONDITION_BLEEDING, DAMAGELIST_CONSTANT_PERIOD, bleed.damage, bleed.interval, bleed.rounds)
-- Warn target that they just got slashed hard from player:getName and their blood is puring out! target:sendTextMessage(MESSAGE_STATUS_WARNING, "You just recieved a blood gushing wound from "..player:getName().."'s deadly sword technique!")
returntrueend
Revscript Action
Revscript 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.
local swordTechnique =Action() -- we created a variable to access Action interface
Action has the available methods and event to use with revscripts
local swordTechnique =Action() -- we created a variable to access Action interfaceswordTechnique:id(2376) -- sword's itemId to register for event
Action:aid()
local swordTechnique =Action() -- we created a variable to access Action interfaceswordTechnique:aid(15428) -- an actionId to register for event
Action:uid()
local swordTechnique =Action() -- we created a variable to access Action interfaceswordTechnique:uid(1337) -- a uniqueId to register for event
Action:allowFarUse()
local swordTechnique =Action() -- we created a variable to access Action interfaceswordTechnique:allowFarUse(true) -- True/False. True we can be more than one square away to use
Action:blockWalls()
local swordTechnique =Action() -- we created a variable to access Action interfaceswordTechnique:blockWalls(true) -- True/false. True and walls will block usage of item.
Action:checkFloor()
local swordTechnique =Action() -- we created a variable to access Action interfaceswordTechnique:checkFloor(true) -- True/false. True and we can only use item on same floor as us.
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:
local swordTechnique =Action() -- we created a variable to access Action interface-- Here we register items to use for action, using swordTechnique variable.swordTechnique:id(2376) -- sword's itemId to register for eventswordTechnique:aid(15428) -- an actionId to register for eventswordTechnique:uid(1337) -- a uniqueId to register for event-- Here we configure our other action methods, still using swordTechniqu variable.swordTechnique:allowFarUse(true)swordTechnique:checkFloors(true)swordTechnique:blockWalls(true)--- Here we call the event using the same swordTechnique variable.function swordTechnique.onUse(player, item, fromPosition, target, toPosition, isHotkey) -- can name the arguments what you like.
local SwordLevel = player:getSkillLevel(SKILL_SWORD)if SwordLevel <70then player:sendCancelMessage("This technique requires a sword fighting skill of 70 or higher.")returnfalseendifnot item:hasAttribute(ITEM_ATTRIBUTE_EXTRADEFENSE) then player:sendCancelMessage("Only swords known for their well balance and extra defense are suitable for this task.")
returnfalseendif fromPosition:isSightClear(toPosition) then player:sendCancelMessage("You must have a clear path to your target")returnfalseendif target:isPlayer() then player:sendCancelMessage("To execute this technique properly, the target needs to be a player.")returnfalseendif isHotkey then player:sendCancelMessage("You can't use this item with a hotkey!")returnfalseend-- Executing the technique-- Teleport to the position player:teleportTo(toPosition)-- Configure bleeding damagelocal bleed = { damage=50, rounds=10, interval=1 }-- Apply deadly bleeding attack on target player:addDamageCondition(target, CONDITION_BLEEDING, DAMAGELIST_CONSTANT_PERIOD, bleed.damage, bleed.interval, bleed.rounds)
-- Warn target that they just got slashed hard from player:getName and their blood is puring out! target:sendTextMessage(MESSAGE_STATUS_WARNING, "You just recieved a blood gushing wound from "..player:getName().."'s deadly sword technique!")
returntrueend-- Finally after all logic is completed, we register the event, still using swordTechniqueswordTechnique:register()