• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua Help to modify the Gift Bag script

Guerra

Member
Joined
May 1, 2018
Messages
69
Reaction score
9
Location
Natal/RN - Brasil
Hello everyone!!

I have a system on my server that are small gift bags that drop from monsters and drop random items for players. I would like to be able to control the quantity of each item that will be delivered to the player and also add the description of the drawn item to the name of the player who won it.

below follows the script I use, I ask for help to modify it !!

LUA:
local items = {31617, 31618, 31619, 31620, 6508,}
local chancenada = 50

function onUse(cid, item)

if math.random(1, 100) <= chancenada then
doPlayerSendCancel(cid, "Falha!! Mais sorte da proxima vez...")
doRemoveItem(item.uid, 1)
return true
end

doPlayerAddItem(cid, items[math.random(1, #items)], 1)
doRemoveItem(item.uid, 1)
return true
end
 
Can you better describe what you are wanting in this portion?

Also what TFS version?
sorry, I forgot to put the version !! My TFS is 1.3. This script works basically like this: The Player drops a gift from a monster and when using that gift he receives a random prize. I would like the Prize to come with the player's name in its description, you know?

#Edit

I use a system similar to my server's quest gifts, when clicking on the chest the player receives the quest prize and the item comes with his name engraved to identify it. I'll post a print of the item so you can illustrate

teste.PNG
 
Last edited:
sorry, I forgot to put the version !! My TFS is 1.3. This script works basically like this: The Player drops a gift from a monster and when using that gift he receives a random prize. I would like the Prize to come with the player's name in its description, you know?

#Edit

I use a similar system in quest quests on my server, when clicking on the chest the player receives the quest prize and the item comes with its name engraved to identify it. I'll post a print of the item so you can illustrate

View attachment 48755
Heading to the store.
I'll work on the script when I get back in 30 minutes.
 
thank you very much my friend, thank you very much !! I wait then ..

#Edit

if possible, could you also modify the script to choose the amount of each prize?
Try this I guess. xD

I'm pretty new to TFS 1.3 scripting style.
LUA:
local reward_chance = 50 -- 50% to get a reward. (100 = 100%)
local rewards = {
    -- {itemID, min_amount, max_amount}
    {31617, 1, 10},
    {31618, 1, 1},
    {31619, 1, 1}, -- note that stackable items cannot have a name engraved on them.
    {31620, 1, 1},
    {6508, 1, 1}
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    item:remove()
    if math.random(100) > reward_chance then
        player:sendCancelMessage("Sorry, no reward. Better luck next time!")
        return true
    end
  
    local rand = math.random(#rewards)
    local itemID = rewards[rand][1]
    local amount = math.random(rewards[rand][2], rewards[rand][3])
  
    if not ItemType(itemID):isStackable() then
        for i = 1, amount do
            local temp_item = Game.createItem(itemID, 1)
            temp_item:setAttribute("description", "This item was obtained by " .. player:getName() .. ".")
            player:addItemEx(temp_item)
        end
    else
        player:addItem(itemID, amount)
    end
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "Congratulations! You won a prize!")
    return true
end
 
Last edited by a moderator:
Try this I guess. xD

I'm pretty new to TFS 1.3 scripting style.
LUA:
local reward_chance = 50 -- 50% to get a reward. (100 = 100%)
local rewards = {
    -- {itemID, min_amount, max_amount}
    {31617, 1, 10},
    {31618, 1, 1},
    {31619, 1, 1}, -- note that stackable items cannot have a name engraved on them.
    {31620, 1, 1},
    {6508, 1, 1}
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    item:remove()
    if math.random(100) > reward_chance then
        player:sendCancelMessage("Sorry, no reward. Better luck next time!")
        return true
    end

    local rand = math.random(#rewards)
    local itemID = rewards[rand][1]
    local amount = math.random(rewards[rand][2], rewards[rand][3])

    if not ItemType(itemID):isStackable() then
        for i = 1, #amount do
            local temp_item = Game.createItem(itemID, 1)
            temp_item:setAttribute("description", "This item was obtained by " .. player:getName() .. ".")
            player:addItemEx(temp_item)
        end
    else
        player:addItem(itemID, amount)
    end
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "Congratulations! You won a prize!")
    return true
end
it didn't work, it doesn't give any error but when it is to receive the item out of the 50% chance of failing only from the message "you cannot use this object" ...

Look this:
 
Last edited:
Back
Top