• 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!

Lua no text message appear

Kawaki69

Member
Joined
Mar 4, 2022
Messages
72
Reaction score
8
Hi this script works but the reward message doesn't appear can some one help me to convert it to 1.4 thank you
Lua:
local items = {
     [0] = {id = 10129, count = 1, chance = 9},
     [1] = {id = 10128, count = 1, chance = 19},
     [2] = {id = 2328, count = 1, chance = 22},
     [3] = {id = 2195, count = 1, chance = 24},
     [4] = {id = 2160, count = 10, chance = 31},
     [5] = {id = 6569, count = 10, chance = 37}
}
function onUse(cid, item, fromPos, itemEx, toPos)
     for i = 0, #items do
         if (items[i].chance > math.random(1, 100)) then
             doPlayerSetMaxCapacity(cid, getPlayerFreeCap(cid) + 100)
             doPlayerAddItem(cid, items[i].id, items[i].count) 
             doRemoveItem(item.uid, 1)
              doCreatureSay(cid, 'I congratulate you won item! This item is '..getItemNameById(items[i].id)..'!', TALKTYPE_MONSTER)
         end
     end
     doRemoveItem(item.uid, 1)
     doCreatureSay(cid, 'I congratulate you won item! This item is '..getItemNameById(items[i].id)..'!', TALKTYPE_MONSTER)
end
 
Solution
Assumptions of your script..

Use item + remove item
-> get 0-6 items.

Lua:
local items = {
    {id = 10129, count = 1,  chance = 9}, -- 9% chance
    {id = 10128, count = 1,  chance = 19},
    {id = 2328,  count = 1,  chance = 22},
    {id = 2195,  count = 1,  chance = 24},
    {id = 2160,  count = 10, chance = 31},
    {id = 6569,  count = 10, chance = 37}
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local rewardObtained = false
    for i = 1, #items do
        if math.random(100) <= items[i].chance then
            player:setCapacity(player:getCapacity() + 100)
            player:addItem(items[i].id, items[i].count, true)
            player:say("I congratulate you won item! This item is " ...
Lua:
local items = {
     [0] = {id = 10129, count = 1, chance = 9},
     [1] = {id = 10128, count = 1, chance = 19},
     [2] = {id = 2328, count = 1, chance = 22},
     [3] = {id = 2195, count = 1, chance = 24},
     [4] = {id = 2160, count = 10, chance = 31},
     [5] = {id = 6569, count = 10, chance = 37}
}
function onUse(cid, item, fromPos, itemEx, toPos)
     for i = 0, #items do
         if (items[i].chance > math.random(1, 100)) then
             doPlayerSetMaxCapacity(cid, getPlayerFreeCap(cid) + 100)
             doPlayerAddItem(cid, items[i].id, items[i].count)
             doRemoveItem(item.uid, 1)
              player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "I congratulate you won item! This item is '..getItemNameById(items[i].id)..'!',")
         end
     end
     doRemoveItem(item.uid, 1)
     player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "I congratulate you won item! This item is '..getItemNameById(items[i].id)..'!',")
end
Test ^^^
 
Last edited:
Lua:
local items = {
     [0] = {id = 10129, count = 1, chance = 9},
     [1] = {id = 10128, count = 1, chance = 19},
     [2] = {id = 2328, count = 1, chance = 22},
     [3] = {id = 2195, count = 1, chance = 24},
     [4] = {id = 2160, count = 10, chance = 31},
     [5] = {id = 6569, count = 10, chance = 37}
}
function onUse(cid, item, fromPos, itemEx, toPos)
     for i = 0, #items do
         if (items[i].chance > math.random(1, 100)) then
             doPlayerSetMaxCapacity(cid, getPlayerFreeCap(cid) + 100)
             doPlayerAddItem(cid, items[i].id, items[i].count)
             doRemoveItem(item.uid, 1)
              player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "I congratulate you won item! This item is")
         end
     end
     doRemoveItem(item.uid, 1)
     player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "I congratulate you won item! This item is")
end
Test ^^^
You didn't add
Code:
getItemNameById
to check the items table for getting it in a text message for example "I congratulate you on winning the item! This item is a bronze warrior trophy."
 
Lua:
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "I congratulate you won item! This item is " .. getItemNameById(items[i].id) .. "!")
It gives me this error
Code:
[Warning - Event::checkScript] Can not load script: scripts/random_reward_box.lua
data/actions/scripts/random_reward_box.lua:1: '=' expected near 'items'
 
Assumptions of your script..

Use item + remove item
-> get 0-6 items.

Lua:
local items = {
    {id = 10129, count = 1,  chance = 9}, -- 9% chance
    {id = 10128, count = 1,  chance = 19},
    {id = 2328,  count = 1,  chance = 22},
    {id = 2195,  count = 1,  chance = 24},
    {id = 2160,  count = 10, chance = 31},
    {id = 6569,  count = 10, chance = 37}
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local rewardObtained = false
    for i = 1, #items do
        if math.random(100) <= items[i].chance then
            player:setCapacity(player:getCapacity() + 100)
            player:addItem(items[i].id, items[i].count, true)
            player:say("I congratulate you won item! This item is " .. ItemType(items[i].id):getName() .. "!", TALKTYPE_SAY)
            rewardObtained = true
        end
    end
    item:remove(1)
    if not rewardObtained then
        player:say("No item won! Sad. :(", TALKTYPE_SAY)
    end
    return true
end
 
Solution
Assumptions of your script..

Use item + remove item
-> get 0-6 items.

Lua:
local items = {
    {id = 10129, count = 1,  chance = 9}, -- 9% chance
    {id = 10128, count = 1,  chance = 19},
    {id = 2328,  count = 1,  chance = 22},
    {id = 2195,  count = 1,  chance = 24},
    {id = 2160,  count = 10, chance = 31},
    {id = 6569,  count = 10, chance = 37}
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local rewardObtained = false
    for i = 1, #items do
        if math.random(100) <= items[i].chance then
            player:setCapacity(player:getCapacity() + 100)
            player:addItem(items[i].id, items[i].count, true)
            player:say("I congratulate you won item! This item is " .. ItemType(items[i].id):getName() .. "!", TALKTYPE_SAY)
            rewardObtained = true
        end
    end
    item:remove(1)
    if not rewardObtained then
        player:say("No item won! Sad. :(", TALKTYPE_SAY)
    end
    return true
end
Thanks @Xikini works flawless i owe you :)
 
Back
Top