Action

Action's Event Interface

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

  • 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

    <action itemid="4856" script="test.lua" />
    <action fromid="2146" toid="2147" script="other/enchanting.lua" />
  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:

function onUse(player, item, fromPosition, target, toPosition, isHotkey)  -- can name the arguments what you like.
    local SwordLevel = player:getSkillLevel(SKILL_SWORD)
    if SwordLevel < 70 then
        player:sendCancelMessage("This technique requires a sword fighting skill of 70 or higher.")
        return false
    end

    if not item:hasAttribute(ITEM_ATTRIBUTE_EXTRADEFENSE) then
        player:sendCancelMessage("Only swords known for their well balance and extra defense are suitable for this task.")
        return false
    end

    if fromPosition:isSightClear(toPosition) then 
        player:sendCancelMessage("You must have a clear path to your target")
        return false
    end

    if target:isPlayer() then 
        player:sendCancelMessage("To execute this technique properly, the target needs to be a player.")
        return false
    end

    if isHotkey then 
        player:sendCancelMessage("You can't use this item with a hotkey!")
        return false
    end
     -- Executing the technique

    -- Teleport to the position
    player:teleportTo(toPosition)

    -- Configure bleeding damage
    local 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!")
   return true
end

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

Here is an example.

Action has the available methods and event to use with revscripts

Event

  • onUse(player, item, fromPosition, itemEx, toPosition, isHotkey)

Methods

Action:id()

Action:aid()

Action:uid()

Action:allowFarUse()

Action:blockWalls()

Action:checkFloor()

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:

Last updated

Was this helpful?