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

C++ (Action) Request SLOT MACHINE

jededias

Member
Joined
Jan 21, 2019
Messages
66
Solutions
1
Reaction score
12
When I use the Item with actionid 5555 (Slot Machine) I can receive a random item between (10, 500, 600, 700, 855) or nothing.

And the items have custom win %
Item 500 is 10% win rate
Item 10 is 80% win rate
 
Solution
You can add a option to remove item 1444 when use the machine?
Like a price to use the Machine
Add this directly under function onUse
Lua:
    if getPlayerItemCount(cid, 1444) < 1 then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You require 1 xxxxxxxxxx to use this slot machine.")
        return true
    end
    doPlayerRemoveItem(cid, 1444, 1)
There's like 20+ different ways to create the slot machine based on the info you gave.
Here's the easiest version.
Lua:
local winnable_items = {
    -- {item_id, item_count, % chance}
    {2148, 10, 90},
    {2152, 5, 40},
    {2160, 1, 10}
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    for i = 1, #winnable_items do
        local rand = math.random(100)
        if rand <= winnable_items[i][3] then
            doPlayerAddItem(cid, winnable_items[i][1], winnable_items[i][2], true)
        end
    end
    return true
end
 
There's like 20+ different ways to create the slot machine based on the info you gave.
Here's the easiest version.
Lua:
local winnable_items = {
    -- {item_id, item_count, % chance}
    {2148, 10, 90},
    {2152, 5, 40},
    {2160, 1, 10}
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    for i = 1, #winnable_items do
        local rand = math.random(100)
        if rand <= winnable_items[i][3] then
            doPlayerAddItem(cid, winnable_items[i][1], winnable_items[i][2], true)
        end
    end
    return true
end


You can add a option to remove item 1444 when use the machine?
Like a price to use the Machine
 
You can add a option to remove item 1444 when use the machine?
Like a price to use the Machine
Add this directly under function onUse
Lua:
    if getPlayerItemCount(cid, 1444) < 1 then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You require 1 xxxxxxxxxx to use this slot machine.")
        return true
    end
    doPlayerRemoveItem(cid, 1444, 1)
 
Solution
Add this directly under function onUse
Lua:
    if getPlayerItemCount(cid, 1444) < 1 then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You require 1 xxxxxxxxxx to use this slot machine.")
        return true
    end
    doPlayerRemoveItem(cid, 1444, 1)
How put a message when player receive one item and how do chance to receive nothing ?
 
How put a message when player receive one item and how do chance to receive nothing ?
There's like 20+ different ways to create the slot machine based on the info you gave.
I already said this previously.
If you want something changed, tell me exactly how you want your system to work.

As-is, there is already a chance to receive nothing.
For the message, just copy-paste the previous line and change the text.
 
This is the updated code, please help me add a message when player receive item, Example: "You won 1 Diamond (11447)"

local winnable_items = {
-- {item_id, item_count, % chance}
{11447, 1, 90},
{11442, 1, 40}
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
if getPlayerItemCount(cid, 12186) < 1 then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Message Here.")
return true
end
doPlayerRemoveItem(cid, 12186, 1)
for i = 1, #winnable_items do
local rand = math.random(100)
if rand <= winnable_items[3] then
doPlayerAddItem(cid, winnable_items[1], winnable_items[2], true)
end
end
return true
end
 
(-‸ლ)

I remember why I stopped helping people now.

It's like you just refuse to even help yourself.

Me: Hey! Tell me what you want, and I'll make it.
You: I want words added to the script.
Me: Well.. that's not really explaining to me anything.. but uh.. just copy this line and change what you want.
Me: Anything else? Just explain what you want to happen.
You: Yeah.. I want some other words added to the script in another spot.
Me: ???? (-‸ლ) Seriously?

Anyways.. enough ranting.
Here's what I assume you want. Since you refuse to actually explain it.

Lua:
local config = {
    chance_for_nothing = 50,
    required_item = 1444,
    winnable_items = {
        {2148, 10, "gold coins"},
        {2152, 5, "platinum coins"},
        {2160, 1, "crystal coin"}
    }
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if getPlayerItemCount(cid, 1444) < 1 then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You require 1 xxxxxxxxxx to use the slot machine.")
        return true
    end
    doPlayerRemoveItem(cid, 1444, 1)
    local rand = math.random(100)
    if rand > config.chance_for_nothing then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Ding ding. Result: Nothing! :C")
        return true
    end
    local reward = config.winnable_items
    rand = math.random(#reward)
    doPlayerAddItem(cid, reward[rand][1], reward[rand][2], true)
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Ding ding. Result: " .. reward[rand][2] .. " " .. reward[rand][3] .. "! :D")
    return true
end
 
(-‸ლ)

I remember why I stopped helping people now.

It's like you just refuse to even help yourself.

Me: Hey! Tell me what you want, and I'll make it.
You: I want words added to the script.
Me: Well.. that's not really explaining to me anything.. but uh.. just copy this line and change what you want.
Me: Anything else? Just explain what you want to happen.
You: Yeah.. I want some other words added to the script in another spot.
Me: ???? (-‸ლ) Seriously?

Anyways.. enough ranting.
Here's what I assume you want. Since you refuse to actually explain it.

Lua:
local config = {
    chance_for_nothing = 50,
    required_item = 1444,
    winnable_items = {
        {2148, 10, "gold coins"},
        {2152, 5, "platinum coins"},
        {2160, 1, "crystal coin"}
    }
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if getPlayerItemCount(cid, 1444) < 1 then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You require 1 xxxxxxxxxx to use the slot machine.")
        return true
    end
    doPlayerRemoveItem(cid, 1444, 1)
    local rand = math.random(100)
    if rand > config.chance_for_nothing then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Ding ding. Result: Nothing! :C")
        return true
    end
    local reward = config.winnable_items
    rand = math.random(#reward)
    doPlayerAddItem(cid, reward[rand][1], reward[rand][2], true)
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Ding ding. Result: " .. reward[rand][2] .. " " .. reward[rand][3] .. "! :D")
    return true
end
Thanks man, sorry for the work :(
Liked
 
Back
Top