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

Gooey Mass ITEM

Vitich

Member
Joined
Nov 28, 2012
Messages
266
Reaction score
11
Hi all, how can I know the change of those items?

Lua:
    [15572] = { -- gooey mass
        chances = {
            {from = 1, to = 2},
            {from = 3, to = 2167, itemId = 15487, count = 10},
            {from = 2168, to = 4243, itemId = 2152, count = 2},
            {from = 4244, to = 6196, itemId = 2144, count = 2},
            {from = 6197, to = 8149, itemId = 7591, count = 2},
            {from = 8150, to = 9823, itemId = 7590, count = 2},
            {from = 9824, to = 9923, itemId = 9971},
            {from = 9924, to = 9990, itemId = 15546},
            {from = 9991, to = 10001, itemId = 15492}

I want to know how set 2-5% to an item.
And 70-80% to an item.

Thank you!
 
Last edited by a moderator:
Solution
Looking at the script, I think if you put
Lua:
local config = {
    -- surprise bag red
    [6571] = {
        { rate = 70, item = 6576, count = { const = 1 }}, --fireworks rocket
        { rate = 25, item = 2195, count = { const = 1 }}, --boots of haste
        { rate = 5, item = 2498, count = { const = 1 }} --royal helmet
    },
}
then you will get what you want
If not just ask I will look again
This collection of items has totalrate = rate + rate + rate = 70 + 25 + 5 = 100
you dont have to worry, it does it for you
just make sure rate add up to 100
I do not want a new script, i want to know how can i set a chance for every item :/ so i think it should be in support not request
 
That's not the problem, the problem is:
I don't know what distro your using
I don't know what the script does
I don't know what the script doesn't do
I don't know what the script is supposed to do and not do
You don't even have a script, just some random lines of code and a vague description of what you want to happen
How am I supposed to help you?
 
Oh, sorry man :(

tfs 1.2 - action script - random item with rate.

Lua:
local config = {
    -- surprise bag red
    [6571] = {
        { rate = 4745, item = 6576, count = { const = 1 }}, --fireworks rocket
        { rate = 2072, item = 6394, count = { const = 1 }}, -- cream cake
        { rate = 1152, item = 6574, count = { const = 1 }}, -- bar of chocolate
        { rate = 1017, item = 6578, count = { const = 1 }}, -- party hat
        { rate = 538, item = 2114, count = { const = 1 }}, --piggy bank
        { rate = 20, item = 2112, count = { const = 1 }}, --teddy bear
        { rate = 17, item = 2195, count = { const = 1 }}, --boots of haste
        { rate = 17, item = 5080, count = { const = 1 }}, --panda teddy
        { rate = 15, item = 2520, count = { const = 1 }}, -- demon shield
        { rate = 7, item = 2173, count = { const = 1 }}, --amulet of loss
        { rate = 17, item = 2492, count = { const = 1 }}, --dragon scale mail
        { rate = 167, item = 2153, count = { const = 1 }}, --violet gem
        { rate = 37, item = 2156, count = { const = 1 }}, --red gem
        { rate = 159, item = 5944, count = { const = 1 }}, --soul orb
        { rate = 7, item = 6566, count = { const = 1 }}, --stuffed dragon
        { rate = 13, item = 2498, count = { const = 1 }} --royal helmet
    },
}

local sumOfRate = {}

for k,v in pairs(config) do
    sumOfRate[k] = 0
    for k2,v2 in pairs(v) do
        sumOfRate[k] = sumOfRate[k] + v2.rate
    end
end

function randomGift(itemid)
    local rand = math.random(1, sumOfRate[itemid])

    local subSum = 0
    local exactItem = nil
    for i,v in ipairs(config[itemid]) do
        if (subSum > rand) then
            if (i > 1) then
                exactItem = i-1
            end
            break
        end
        subSum = subSum + v.rate
        if (subSum >= rand) then
            exactItem = i
            break
        end
    end
  
    return exactItem
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local run = false
  
    for k,v in pairs(config) do
        if (k == item.itemid) then
            run = true
            break
        end
    end
  
    if (not run) then
        return false
    end
  
    local gift = randomGift(item.itemid)

    if (config[item.itemid][gift].count.const ~= nil) then
        doPlayerAddItem(cid, config[item.itemid][gift].item, config[item.itemid][gift].count.const)
    else
        doPlayerAddItem(cid, config[item.itemid][gift].item, math.random(config[item.itemid][gift].count.min, config[item.itemid][gift].count.max))
    end
  
    doSendMagicEffect(fromPosition, CONST_ME_GIFT_WRAPS)
    doRemoveItem(item.uid, 1)
    return true
end

I want to know, how can i set on every item a % of rate.

Example: royal helmet (rate 5%)
boots of haste (rate 25%)
 
Last edited by a moderator:
Looking at the script, I think if you put
Lua:
local config = {
    -- surprise bag red
    [6571] = {
        { rate = 70, item = 6576, count = { const = 1 }}, --fireworks rocket
        { rate = 25, item = 2195, count = { const = 1 }}, --boots of haste
        { rate = 5, item = 2498, count = { const = 1 }} --royal helmet
    },
}
then you will get what you want
If not just ask I will look again
 
what about this?
Lua:
    local rand = math.random(1, sumOfRate[itemid])
what do you mean it doesn't work? what happens?
 
Code:
local sumOfRate = {}

How can i know that 70 is equal 70% if there is a 4k+ rate?

Code:
[LIST=1]
[*]        { rate = 4745, item = 6576, count = { const = 1 }}, --fireworks rocket
[*]        { rate = 2072, item = 6394, count = { const = 1 }}, -- cream cake
[/LIST]
4745 is 4745% rate? hmmm
 
no, it appears 4745 is ((4745/totalrate)*100)%
so if your totalrate = 100
and RHrate = 5
then rhrate = (5/100)*100 = 5%
 
Last edited:
Now, how to put totalrate to 100? :p

@edit
I think i know now.

5 items:

1 = 25 rate
2 = 15 rate
3 = 20 rate
4 = 20 rate
5 = 20 rate

total rate = 100% right?
 
Last edited:
Looking at the script, I think if you put
Lua:
local config = {
    -- surprise bag red
    [6571] = {
        { rate = 70, item = 6576, count = { const = 1 }}, --fireworks rocket
        { rate = 25, item = 2195, count = { const = 1 }}, --boots of haste
        { rate = 5, item = 2498, count = { const = 1 }} --royal helmet
    },
}
then you will get what you want
If not just ask I will look again
This collection of items has totalrate = rate + rate + rate = 70 + 25 + 5 = 100
you dont have to worry, it does it for you
just make sure rate add up to 100
 
Solution
Back
Top