• 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.5] Small Action Reward Container System

Sarah Wesker

ƐƖєgαηт Sуηтαx ❤
Staff member
TFS Developer
Support Team
Joined
Mar 16, 2017
Messages
1,408
Solutions
154
Reaction score
1,958
Location
London
GitHub
MillhioreBT
Twitch
millhiorebt
This is a short script that I wrote quickly for those who still have the habit of creating small chest rewards in the map editor.

data/scripts/rewardContainerSystem.lua
Lua:
local action = Action()

function action.onUse(player, item, fromPos, target, toPos, isHotkey)
    if not item:getType():isContainer() then
        return true
    end

    local storageId = 5000 + item:getUniqueId()
    if player:getStorageValue(storageId) == 1 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "It is empty.")
        return true
    end

    local bag = Game.createItem("bag", 1)
    for index, item in pairs(item:getItems()) do
        bag:addItemEx(item:clone())
    end

    local returnValue = player:addItemEx(bag)
    if returnValue ~= RETURNVALUE_NOERROR then
        bag:remove()
        player:sendCancelMessage(returnValue)
        return true
    end

    player:sendTextMessage(MESSAGE_LOOT, string.format("You found: %s", bag:getContentDescription()))
    player:setStorageValue(storageId, 1)
    return true
end

action:aid(8010)
action:register()

This is the base storage of the system: 5000
1640063486243.png
This means that if in your editor you configure the container with a uniqueID of 1000, then the result will be 6000
This storage is where the status of the reward will be saved, in this way we can know if a character has already obtained said reward and in the future we will not give it to them anymore, this is where we say that the container is empty:
1640063620101.png

This is where we will create a new bag, this bag will contain the reward, so what we do is clone the items inside our container and these cloned items will go directly to the new bag:
1640063722854.png

Next we will try to give the bag to the player, if it is not possible to give it to him it is because he does not have the capacity to carry it, then we will send a message to the player, the message will be related to the reason why the player cannot carry it
1640064085703.png
OFC we will eliminate the bag, since it is virtual and no one will use it at any time. (in case the player cannot carry it)

If everything is correct, the player will receive his reward and we will send him a message with the content
We will also update the storage so that in the future this player will not receive this reward again
1640064270787.png

That's it, here I will leave a quick video demonstration of how I did it
Note: in the video I forgot to add bag:remove() ajajja sorry

 
This is a short script that I wrote quickly for those who still have the habit of creating small chest rewards in the map editor.

data/scripts/rewardContainerSystem.lua
Lua:
local action = Action()

function action.onUse(player, item, fromPos, target, toPos, isHotkey)
    if not item:getType():isContainer() then
        return true
    end

    local storageId = 5000 + item:getUniqueId()
    if player:getStorageValue(storageId) == 1 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "It is empty.")
        return true
    end

    local bag = Game.createItem("bag", 1)
    for index, item in pairs(item:getItems()) do
        bag:addItemEx(item:clone())
    end

    local returnValue = player:addItemEx(bag)
    if returnValue ~= RETURNVALUE_NOERROR then
        bag:remove()
        player:sendCancelMessage(returnValue)
        return true
    end

    player:sendTextMessage(MESSAGE_LOOT, string.format("You found: %s", bag:getContentDescription()))
    player:setStorageValue(storageId, 1)
    return true
end

action:aid(8010)
action:register()

This is the base storage of the system: 5000
View attachment 64104
This means that if in your editor you configure the container with a uniqueID of 1000, then the result will be 6000
This storage is where the status of the reward will be saved, in this way we can know if a character has already obtained said reward and in the future we will not give it to them anymore, this is where we say that the container is empty:
View attachment 64105

This is where we will create a new bag, this bag will contain the reward, so what we do is clone the items inside our container and these cloned items will go directly to the new bag:
View attachment 64106

Next we will try to give the bag to the player, if it is not possible to give it to him it is because he does not have the capacity to carry it, then we will send a message to the player, the message will be related to the reason why the player cannot carry it
View attachment 64108
OFC we will eliminate the bag, since it is virtual and no one will use it at any time. (in case the player cannot carry it)

If everything is correct, the player will receive his reward and we will send him a message with the content
We will also update the storage so that in the future this player will not receive this reward again
View attachment 64109

That's it, here I will leave a quick video demonstration of how I did it
Note: in the video I forgot to add bag:remove() ajajja sorry

Can u share the plugin from the video its dope
 
ehh ffor me dont work becaue canary dnt have function callback
 

Attachments

  • Screen Shot 05-01-22 at 11.09 PM.PNG
    Screen Shot 05-01-22 at 11.09 PM.PNG
    816.6 KB · Views: 10 · VirusTotal
Back
Top