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

Solved Lottery Ticket

denkan97

Well-Known Member
Joined
Dec 27, 2011
Messages
327
Solutions
2
Reaction score
50
Would like some help here to make this script so when i use this item (id 5957).
Then i get a 25% chance to get one item and/or 10% chance to get another.

TFS 1.2

Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if math.random(50) == 1 then
        player:getPosition():sendMagicEffect(CONST_ME_GIFT_WRAPS)
        player:say("Congratulations! You won a prize!", TALKTYPE_MONSTER_SAY)
        item:transform(5958)
     
    else
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        player:say("Sorry, but you drew a blank.", TALKTYPE_MONSTER_SAY)
        item:remove(1)
    end
    return true
end
 
Last edited by a moderator:
Well, I've developed a script for you. I've tested here with TFS 1.0, but probably it'll work on TFS 1.2 as well.

Code:
function onUse(cid, item, fromPosition, itemEx, toPosition, isHotkey)
    local p = Player(cid)
    local prizes = {5958, 2421}
    if math.random(100) <= 25 then
        p:getPosition():sendMagicEffect(CONST_ME_GIFT_WRAPS)
        p:sendTextMessage(MESSAGE_INFO_DESCR, "Congratulations! You won a prize!")
        p:addItem(prizes[1])
        if math.random(100) <= 10 then
            p:addItem(prizes[2])
        end
        Item(item["uid"]):remove()
    else
        p:getPosition():sendMagicEffect(CONST_ME_POFF)
        p:sendTextMessage(MESSAGE_INFO_DESCR, "Sorry, but you drew a blank")
        Item(item["uid"]):remove()
    end
    return true
end
 
Well, I've developed a script for you. I've tested here with TFS 1.0, but probably it'll work on TFS 1.2 as well.

Code:
function onUse(cid, item, fromPosition, itemEx, toPosition, isHotkey)
    local p = Player(cid)
    local prizes = {5958, 2421}
    if math.random(100) <= 25 then
        p:getPosition():sendMagicEffect(CONST_ME_GIFT_WRAPS)
        p:sendTextMessage(MESSAGE_INFO_DESCR, "Congratulations! You won a prize!")
        p:addItem(prizes[1])
        if math.random(100) <= 10 then
            p:addItem(prizes[2])
        end
        Item(item["uid"]):remove()
    else
        p:getPosition():sendMagicEffect(CONST_ME_POFF)
        p:sendTextMessage(MESSAGE_INFO_DESCR, "Sorry, but you drew a blank")
        Item(item["uid"]):remove()
    end
    return true
end


Did some testing with this and i did both to <= 50 and used 652 tickets and thouth this should be 50/50 and i got 180-336.
 
Going with your original statement "Then i get a 25% chance to get one item and/or 10% chance to get another."
This can mean 1 of two things.

Scenario A
35% win rate, with 25% chance to get itemA and 10% chance to get itemB
Code:
local rand = math.random(100)
if rand <= 35 then
   if rand <= 25 then
     -- give itemA
   else
     -- give itemB
   end
else
   -- send fail message
end

Scenario B
Unknown win rate, but when you win, you have 73% chance to get itemA and 27% chance to get itemB.
Code:
local win_rate = 10 -- 1-100%
local rand = math.random(100)
if rand <= win_rate then
   if rand <= 73 then
     -- give itemA
   else
     -- give itemB
   end
else
   -- send fail message
end

Hope it helps.
 
Going with your original statement "Then i get a 25% chance to get one item and/or 10% chance to get another."
This can mean 1 of two things.

Scenario A
35% win rate, with 25% chance to get itemA and 10% chance to get itemB
Code:
local rand = math.random(100)
if rand <= 35 then
   if rand <= 25 then
     -- give itemA
   else
     -- give itemB
   end
else
   -- send fail message
end

Scenario B
Unknown win rate, but when you win, you have 73% chance to get itemA and 27% chance to get itemB.
Code:
local win_rate = 10 -- 1-100%
local rand = math.random(100)
if rand <= win_rate then
   if rand <= 73 then
     -- give itemA
   else
     -- give itemB
   end
else
   -- send fail message
end

Hope it helps.

Got it to work thanks for all help
 
Going with your original statement "Then i get a 25% chance to get one item and/or 10% chance to get another."
This can mean 1 of two things.

Scenario A
35% win rate, with 25% chance to get itemA and 10% chance to get itemB
Code:
local rand = math.random(100)
if rand <= 35 then
   if rand <= 25 then
     -- give itemA
   else
     -- give itemB
   end
else
   -- send fail message
end

Scenario B
Unknown win rate, but when you win, you have 73% chance to get itemA and 27% chance to get itemB.
Code:
local win_rate = 10 -- 1-100%
local rand = math.random(100)
if rand <= win_rate then
   if rand <= 73 then
     -- give itemA
   else
     -- give itemB
   end
else
   -- send fail message
end

Hope it helps.
"35% win rate, with 25% chance to get itemA and 10% chance to get itemB"
Code:
local rand = math.random(100)
if rand <= 35 then
   if rand <= 25 then
     -- give itemA
   else
     -- give itemB
   end
else
   -- send fail message
end

Thats not how math works tho.

Inside that if the rand value has 100% chance of being <= 35 so:

25/35 = 0.71, then you have "35% win rate, with 71% of getting itemA and 29% of getting itemB" with this.
 
Last edited:
Code:
local rand = math.random(100)
if rand <= 35 then
   if rand <= 25 then
     -- give itemA
   else
     -- give itemB
   end
else
   -- send fail message
end

Thats not how math works tho.

Inside that if the rand value has 100% chance of being <= 35 so:

25/35 = 0.71, then you have 71% of getting itemA and 29% of getting itemB with this.
Your math is so messed up.
 
Your math is so messed up.
What is messed up? Can you explain?

Edit: As you seem to have missed some math classes let me explain you why my math is correct.

You have a random variable with values 1 to 100.
Code:
if var <= 35 then
end
Then this if has 35% chance of being executed.

However every time this if is executed var can only be 1 - 35.

So if you place another if inside this if like:

Code:
if var <= 25 then
end

You have 35 possible outcomes and the condition will be true for 25 of them. AKA 25/35 AKA 71% (avg)
 
Last edited:
What is messed up? Can you explain?
The fact that you draw the conclusion, that the chance of getting item a is 71% and the chance of getting item b is 29%. Literally makes no sense. Sure 25/35 is .71 = 71%. But please tell me why that statistic matters, when the rand value is different every time the scripts executed?

With your logic, might as well change it to math.random(35), then maybe your math would make a little sense.

Edit: incase you didn't know the value of rand stays the same inside that conditional. The only way your math makes any fuckin sense, is if the script called another math.random.
 
The fact that you draw the conclusion, that the chance of getting item a is 71% and the chance of getting item b is 29%. Literally makes no sense. Sure 25/35 is .71 = 71%. But please tell me why that statistic matters, when the rand value is different every time the scripts executed?

With your logic, might as well change it to math.random(35), then maybe your math would make a little sense.
Read the previous post. And the rand value is not going to be different in every condition you make. It's setted only 1 time.
 
Your math is so messed up.

How come? I've written this simple program to count how many times each situation occurs out of 10e6 tests:


Code:
local function test(n, out)
    for i = 1, n do
        local rand = math.random(100)
        out.total = out.total + 1
        if rand <= 35 then
            -- won
            out.wins = out.wins + 1
            if rand <= 25 then
                out.itemA = out.itemA + 1
            else
                out.itemB = out.itemB + 1
            end
        else
            -- lost
        end
    end
end

local out = {itemA = 0, itemB = 0, wins = 0, total = 0}

test(1000000, out)

print(string.format("Wins %2d%% of the time.", 100 * out.wins / out.total))
print(string.format("Wins item A %2d%% of the time he wins.", 100 * out.itemA / out.wins))
print(string.format("Wins item B %2d%% of the time he wins.", 100 * out.itemB / out.wins))

This is the output I get:

Code:
C:\Users\Cezar\Desktop>luajit test.lua
Wins 35% of the time.
Wins item A 71% of the time he wins.
Wins item B 28% of the time he wins.

I believe it is safe to say @MatheusMkalo's math checks out.

The fact that you draw the conclusion, that the chance of getting item a is 71% and the chance of getting item b is 29%. Literally makes no sense. Sure 25/35 is .71 = 71%. But please tell me why that statistic matters, when the rand value is different every time the scripts executed?

With your logic, might as well change it to math.random(35), then maybe your math would make a little sense.

You're wrong, "rand" is assigned the return value of math.random(100) once, therefore it contains the same value and Mkalo's assumption is valid.
 
The statistics of that math isn't out of just 35 as you guys seem to think. You're clearly clueless. The script is designed to have a 25% chance to give item a, 10% chance to give item b, and a 65% chance to give nothing, or whatever else... Your math states that something is given every single time. That's not the case.
 
Sorry for asking now but i read the things that you wrote here and got more questions now :p

If i use this.

local rand = math.random(100)
if rand <= 35 then
if rand <= 25 then
-- give itemA
else
-- give itemB
end
else
-- send fail message
end

And want a 20% chance to get one of 5 items. And it should be 100% random witch one of them you get how sould it look?
 
The statistics of that math isn't out of just 35 as you guys seem to think. You're clearly clueless. The script is designed to have a 25% chance to give item a, 10% chance to give item b, and a 65% chance to give nothing, or whatever else... Your math states that something is given every single time. That's not the case.
Our math is based in his wrong statement "35% win rate, with 25% chance to get itemA and 10% chance to get itemB"
Correct would be: "35% total win rate.(DOT HERE, NO "WITH") 25% of getting itemA and 10% of getting itemB"

Try this please:
There were 2 brothers.
If the younger brother has half of the older's age and the older brother is 4 years old, how old is the younger brother when the older is 100 years old?

Sorry for asking now but i read the things that you wrote here and got more questions now :p

If i use this.

local rand = math.random(100)
if rand <= 35 then
if rand <= 25 then
-- give itemA
else
-- give itemB
end
else
-- send fail message
end

And want a 20% chance to get one of 5 items. And it should be 100% random witch one of them you get how sould it look?

Code:
local items = {100, 200, 300, 400, 500}

local rand = math.random(100)
if rand <= 20 then
    item:transform(items[math.random(5)])
end
 
Our math is based in his wrong statement "35% win rate, with 25% chance to get itemA and 10% chance to get itemB"
Correct would be: "35% total win rate.(DOT HERE, NO "WITH") 25% of getting itemA and 10% of getting itemB"

Try this please:
There were 2 brothers.
If the younger brother has half of the older's age and the older brother is 4 years old, how old is the younger brother when the older is 100 years old?



Code:
local items = {100, 200, 300, 400, 500}

local rand = math.random(100)
if rand <= 20 then
    item:transform(items[math.random(5)])
end
No your math is based on one of a few things. Either A) you didn't read @denkan97's original post. B) You did read the original post, but couldn't comprehend it well enough. C) You just wanted to be a dickhead and try calling someone out and proving you're smarter than the world. (Which clearly backfired.)

I'm going to go with C. Yep C sounds right.
 
No your math is based on one of a few things. Either A) you didn't read @denkan97's original post. B) You did read the original post, but couldn't comprehend it well enough. C) You just wanted to be a dickhead and try calling someone out and proving you're smarter than the world. (Which clearly backfired.)

I'm going to go with C. Yep C sounds right.
I don't need to read the original post to see that Xikini's statement is wrong. If you can't I'm sorry, at least I've tried.
 
I don't need to read the original post to see that Xikini's statement is wrong. If you can't I'm sorry, at least I've tried.
But Xikini's post was in regards to the original post was it not? From which you can draw your own conclusion that based on what is being said, makes sense. Guess you're one of those people that can solve complex situations, but when it comes to connecting the simple dots, flies completely over your head.

Edit: Also goes back to you trying to be a hero and calling someone out.
 
Okay im new at this and kind of dumb but can someone fix this? :(

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
local items = {1986, 1984, 1983, 1982, 4855}
local rand = math.random(100)

if rand <= 20 then
item:transform(items[math.random(5)])
end
else
player:getPosition():sendMagicEffect(CONST_ME_POFF)
player:say("Sorry, but you drew a blank.", TALKTYPE_MONSTER_SAY)
item:remove(1)
end
return true
end
 
Back
Top