You dont need anymore just register the event and id in the lua script.
In my opinion that a mistake, because in system with alot items with system some times its better you have an xml to keep track of files by id easy in xml.
any way some tips:
Tutorial: Creating and Using Action Events
Action events in TFS allow you to create custom behaviors when players use specific items.
Step 1: Setting Up the Action Event
To get started, you'll need to define the action event using the
function. This function serves as the foundation for your custom behavior. Here's how you can set it up:
Code:
local exampleAction = Action()
Step 2: Writing the Action Function
The heart of the action event is the function that gets triggered when a player uses the designated item. Inside this function, you can define what should happen when the item is used. In this example, we'll make the player send a fire effect to a specific position:
Code:
function exampleAction.onUse(player, item, fromPosition, target, toPosition, isHotkey)
toPosition:sendMagicEffect(CONST_ME_HITBYFIRE)
end
In this code:
-
represents the player who used the item.
-
is the item that was used.
-
is the position where the item was used from.
-
represents the target of the action (e.g., a creature or player).
-
is the position where the action is targeted.
-
is a boolean indicating whether the action was triggered by a hotkey.
In the example, when the item is used, a fire effect is sent to the
.
Step 3: Assigning an Item ID
Next, you need to specify the item ID for which this action event should trigger. In the example, we'll use item ID 5468:
Step 4: Registering the Action Event
After setting up the action event, you need to register it so that the game knows to trigger the specified behavior when the designated item is used:
Putting It All Together
Here's the complete code for the action event:
Code:
local exampleAction = Action()
function exampleAction.onUse(player, item, fromPosition, target, toPosition, isHotkey)
toPosition:sendMagicEffect(CONST_ME_HITBYFIRE)
end
exampleAction:id(5468)
exampleAction:register()
How It Works
1. The
is defined using the
function.
2. Inside the
function, the
function is defined. This function is triggered when the designated item is used by a player.
3. In the
function, the
is sent a fire magic effect using
Code:
sendMagicEffect(CONST_ME_HITBYFIRE)
.
4. The item ID 5468 is assigned to this action event using
.
5. Finally, the action event is registered with
.