• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

TFS 1.X+ TFS 1.X instruction - how add actions in script folder etc.

OTcreator

Active Member
Joined
Feb 14, 2022
Messages
425
Solutions
1
Reaction score
44
Hi,
I am currently using TFS 0.3.7.
I need to rewrite all the scripts under TFS 1.4.2.

The problem is that I can see the scripts folder with folders actions, movements etc. but there is no e.g. actions.xml.

In addition, there are some folders in lib like storages etc. is it some database with all storage?
Can someone explain all this to me, how it all works in the latest TFS?
 
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
Code:
Action()
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:
  • Code:
    player
    represents the player who used the item.
  • Code:
    item
    is the item that was used.
  • Code:
    fromPosition
    is the position where the item was used from.
  • Code:
    target
    represents the target of the action (e.g., a creature or player).
  • Code:
    toPosition
    is the position where the action is targeted.
  • Code:
    isHotkey
    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
Code:
toPosition
.

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:
Code:
exampleAction: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:
Code:
exampleAction:register()

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
Code:
exampleAction
is defined using the
Code:
Action()
function.
2. Inside the
Code:
exampleAction
function, the
Code:
onUse
function is defined. This function is triggered when the designated item is used by a player.
3. In the
Code:
onUse
function, the
Code:
toPosition
is sent a fire magic effect using
Code:
sendMagicEffect(CONST_ME_HITBYFIRE)
.
4. The item ID 5468 is assigned to this action event using
Code:
exampleAction:id(5468)
.
5. Finally, the action event is registered with
Code:
exampleAction:register()
.
 
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
Code:
Action()
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:
  • Code:
    player
    represents the player who used the item.
  • Code:
    item
    is the item that was used.
  • Code:
    fromPosition
    is the position where the item was used from.
  • Code:
    target
    represents the target of the action (e.g., a creature or player).
  • Code:
    toPosition
    is the position where the action is targeted.
  • Code:
    isHotkey
    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
Code:
toPosition
.

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:
Code:
exampleAction: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:
Code:
exampleAction:register()

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
Code:
exampleAction
is defined using the
Code:
Action()
function.
2. Inside the
Code:
exampleAction
function, the
Code:
onUse
function is defined. This function is triggered when the designated item is used by a player.
3. In the
Code:
onUse
function, the
Code:
toPosition
is sent a fire magic effect using
Code:
sendMagicEffect(CONST_ME_HITBYFIRE)
.
4. The item ID 5468 is assigned to this action event using
Code:
exampleAction:id(5468)
.
5. Finally, the action event is registered with
Code:
exampleAction:register()
.

Thank you! And storage? How it's works?

Now i must modify all old scripts for 0.3.7 to 1.X :(
 
Last edited:
Thank you! And storage? How it's works?

Now i must modify all old scripts for 0.3.7 to 1.X :(
Most of the scripts should work very well with the compat.lua above.
[Storage] Tutorial: Sending a One-Time Message using Player Storage

In this tutorial, we'll create a system that sends a message to a player only once when they perform a specific action. We'll use player storage to keep track of whether the message has already been sent.

Step 0: Understanding What is Player Storage

Player storage is a fundamental mechanism within your game's database that allows you to store custom values for each individual player.
Think of it as a set of personalized storage slots dedicated to every player.
When you make use of player storage, you're effectively modifying and updating these storage slots in the game's database. It's crucial to keep in mind that these storage values must always be numerical.


Step 1: Define the Action

First, let's define the action using the provided code snippet:

Code:
-- Define the action class
local exampleAction = Action()

-- Define the storage key for tracking whether the message has been sent
local MESSAGE_SENT_STORAGE = 1001

-- Function to check if a player has already received the message
local function hasReceivedMessage(player)
    return player:getStorageValue(MESSAGE_SENT_STORAGE) == 1
end

-- Function to mark the message as sent for a player
local function markMessageAsSent(player)
    player:setStorageValue(MESSAGE_SENT_STORAGE, 1)
end

-- Define the action's behavior
function exampleAction.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if not hasReceivedMessage(player) then
        -- Send the message to the player
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You've received a one-time message!")

        -- Mark the message as sent for the player
        markMessageAsSent(player)
    else
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You've already received the message.")
    end

    -- Perform the original action's effect
    toPosition:sendMagicEffect(CONST_ME_HITBYFIRE)
end

-- Register the action
exampleAction:id(5468)
exampleAction:register()

Step 2: Explanation

In the provided code, we've added two functions: hasReceivedMessage and markMessageAsSent. The hasReceivedMessage function checks if a player has already received the message by looking at their storage value. The markMessageAsSent function updates the player's storage to indicate that the message has been sent.

Inside the exampleAction.onUse function, we check if the player has received the message using the hasReceivedMessage function. If they haven't, we send them the message and mark it as sent using the markMessageAsSent function. If they have already received the message, we send a different message indicating that they've already received it.

Step 3: Integration

Replace the player:sendTextMessage calls with the appropriate function for sending text messages in your game's scripting environment.
 
Back
Top