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

Casino slotmachines % of winning or loose

Thorn

Spriting since 2013
Joined
Sep 24, 2012
Messages
2,203
Solutions
1
Reaction score
921
Location
Chile
Hello, i have been trying to find a system that has a slotmachine (some item) and you right click it, and it takes x amount of x item and you have like 30% of winning, if you win you get the price (item z) and if you loose it says something like you lost, keep playing or whatever...does this exists? i can't find it, and if not, i'm requesting this to anyone plz :))
oh also you have like to pay 20 cc to play for item A, 40 cc for item B, 60 cc for item C, and so... and with percentages of winning or loose
i use tfs 0.3 (otx 2.52) and my server is 9.83

Bump

Bump =(
 
Last edited by a moderator:
I use 0.3.7.. I'll quickly script a onUse function.. it really doesn't seem hard.
Unsure how to create a lever to do multiple 'casinos'.. so you'll have to create a different lever for each item people can play for.

Completely untested.
Use with a lever.
-- Green texted. Should be easy enough to understand.
Code:
function onUse(cid, item, frompos, item2, topos)

  local player_gold  = getPlayerItemCount(cid,2148)
  local player_plat  = getPlayerItemCount(cid,2152)*100
  local player_crys  = getPlayerItemCount(cid,2160)*10000
  local player_money  = player_gold + player_plat + player_crys
   
   -- don't edit above
   
   local cost_per_click  = 30000 -- Amount in gold coins. 30,000 = 3 cc. Set to 0 if you want no money to be taken.
   
   local item_per_click  = 150 -- Amount of items needed to use lever. Set to 0 in you want no item to be used.
   local item_currency  = 6500 -- Item needed to use lever. Set as Demonic Essences currently.
   local item_name  = "demonic essence"
   
   local reward_for_win  = 2494 -- ItemID needs to be used. 2494 = Demon Armor
   local name_of_item  = "demon armor"
   local amount_to_win  = 1 -- Amount of item to be won. If stackable item, change as required.
   local chance_to_win  = 30 -- Percent 30/100
   
   local position_of_lever = {x = 1000, y = 1000, z = 7} -- Position of your lever (use standard lever, ID = 1945
   
   
   -- Don't edit below unless your sure you know what to do. :P   
   
   local time = 5
   function resetLever()
     doTransformItem(getTileItemById(position_of_lever, 1946).uid, 1945)
   end
   
   if item.itemid == 1945 then
     doTransformItem(item.uid, 1946)
     if player_money >= cost_per_click then
       if item_currency >= item_per_click then
         doPlayerRemoveMoney(cid, cost_per_click)
         doPlayerRemoveItem(cid, item_currency, item_per_click)
         if(math.random(1, 100) <= chance_to_win) then
           doPlayerAddItem(cid,reward_for_win,amount_to_win)
           if amount_to_win <= 1 then
             doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "Winner! You receive ".. amount_to_win .." ".. name_of_item ..".")
           else
             doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "Winner! You receive ".. amount_to_win .." ".. name_of_item .."s.")
           end
         else
           doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "Sorry, no luck!")
         end
       else
         doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "You require ".. item_per_click .." ".. item_name .." to use the lottery machine.")
       end
     else
       doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "You require ".. cost_per_click .." gold coins to use the lottery machine.")
     end
   addEvent(resetLever, time*1000)
   else
     return doPlayerSendCancel(cid, "You must wait a few seconds before using the lever again.")
   end
return true
end
 
Last edited:
Thanks!! thank you so much! i will test it in a few and let you know how it goes, altho, could i use the click on a slotmachine? that i have? not a lver?
 
Thanks!! thank you so much! i will test it in a few and let you know how it goes, altho, could i use the click on a slotmachine? that i have? not a lver?
Doing this from my phone.. hopefully I don't screw it up. lol
Just a FYI, if you use it without the lever you'll need to add an exhaust or something so players cannot use it rapidly. I used the lever so players could not accidentally double click and lose money.
Code:
function onUse(cid, item, frompos, item2, topos)

  local player_gold  = getPlayerItemCount(cid,2148)
  local player_plat  = getPlayerItemCount(cid,2152)*100
  local player_crys  = getPlayerItemCount(cid,2160)*10000
  local player_money  = player_gold + player_plat + player_crys
   
   -- don't edit above
   
   local cost_per_click  = 30000 -- Amount in gold coins. 30,000 = 3 cc. Set to 0 if you want no money to be taken.
   
   local item_per_click  = 150 -- Amount of items needed to use lever. Set to 0 in you want no item to be used.
   local item_currency  = 6500 -- Item needed to use lever. Set as Demonic Essences currently.
   local item_name  = "demonic essence"
   
   local reward_for_win  = 2494 -- ItemID needs to be used. 2494 = Demon Armor
   local name_of_item  = "demon armor"
   local amount_to_win  = 1 -- Amount of item to be won. If stackable item, change as required.
   local chance_to_win  = 30 -- Percent 30/100
   
   local casino_machine = 00000000
   
   
   -- Don't edit below unless your sure you know what to do. :P   
   
   if item.itemid == casino_machine then
     if player_money >= cost_per_click then
       if item_currency >= item_per_click then
         doPlayerRemoveMoney(cid, cost_per_click)
         doPlayerRemoveItem(cid, item_currency, item_per_click)
         if(math.random(1, 100) <= chance_to_win) then
           doPlayerAddItem(cid,reward_for_win,amount_to_win)
           if amount_to_win <= 1 then
             doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "Winner! You receive ".. amount_to_win .." ".. name_of_item ..".")
           else
             doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "Winner! You receive ".. amount_to_win .." ".. name_of_item .."s.")
           end
         else
           doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "Sorry, no luck!")
         end
       else
         doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "You require ".. item_per_click .." ".. item_name .." to use the lottery machine.")
       end
     else
       doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "You require ".. cost_per_click .." gold coins to use the lottery machine.")
     end
   else
     return doPlayerSendCancel(cid, "This is the incorrect item for this script! Check casino_machine ID.")
   end
return true
end
 
It worked! but with one problem, when i click it (it does remove money and give item) i get this error
[31/5/2015 18:17:53] [Error - Action Interface]
[31/5/2015 18:17:53] In a timer event called from:
[31/5/2015 18:17:53] data/actions/scripts/Slotmachine.lua:eek:nUse
[31/5/2015 18:17:53] Description:
[31/5/2015 18:17:53] (LuaInterface::luaDoTransformItem) Item not found

i only have one slotmachine, and it doesn't transform to anything, maybe i have to delete something right?

also now that it works, i have a few questions:
Code:
   local cost_per_click  = 100000 -- Amount in gold coins. 30,000 = 3 cc. Set to 0 if you want no money to be taken.
  
   local item_per_click  = 0 -- Amount of items needed to use lever. Set to 0 in you want no item to be used.
   local item_currency  = 6500 -- Item needed to use lever. Set as Demonic Essences currently.
   local item_name  = "demonic essence"
  
   local reward_for_win  = 2494 -- ItemID needs to be used. 2494 = Demon Armor
   local name_of_item  = "demon armor"
   local amount_to_win  = 1 -- Amount of item to be won. If stackable item, change as required.
   local chance_to_win  = 10 -- Percent 10/100
  
   local position_of_lever = {x = 1000, y = 1000, z = 7} -- Position of your lever (use standard lever, ID = 1945

what is:
local item per click? local item name?

also, how can i do so i set many items in the rewards? like randomly? for example:
item1 10/100
item2 10/100
item3 20/100
 
Last edited:
It worked! but with one problem, when i click it (it does remove money and give item) i get this error


i only have one slotmachine, and it doesn't transform to anything, maybe i have to delete something right?

also now that it works, i have a few questions:
Code:
   local cost_per_click  = 100000 -- Amount in gold coins. 30,000 = 3 cc. Set to 0 if you want no money to be taken.
  
   local item_per_click  = 0 -- Amount of items needed to use lever. Set to 0 in you want no item to be used.
   local item_currency  = 6500 -- Item needed to use lever. Set as Demonic Essences currently.
   local item_name  = "demonic essence"
  
   local reward_for_win  = 2494 -- ItemID needs to be used. 2494 = Demon Armor
   local name_of_item  = "demon armor"
   local amount_to_win  = 1 -- Amount of item to be won. If stackable item, change as required.
   local chance_to_win  = 10 -- Percent 10/100
  
   local position_of_lever = {x = 1000, y = 1000, z = 7} -- Position of your lever (use standard lever, ID = 1945

what is:
local item per click? local item name?

also, how can i do so i set many items in the rewards? like randomly? for example:
item1 10/100
item2 10/100
item3 20/100
Your using the lever script.
Either change to the other script or set the lever position.
If you read the green text I explained everything already.
You can make the slot machine take money, items, or both. Again, read the green text.
As for the random items create a table and loop through them to choose an item, or do another random roll to decide what item to give.
 
Finished in private.
Here is the finished script.

Allows for multiple items to be used as a prize, and added exhaustion to the script so a lever was no longer required.

Code:
function onUse(cid, item, frompos, item2, topos)

-- https://otland.net/members/xikini.102396/
-- https://otland.net/threads/casino-slotmachines-of-winning-or-loose.232794/#post-2245827

   local cost_per_click  = 30000 -- Amount in gold coins. 30,000 = 3 cc. Set to 0 if you want no money to be taken.
   local item_per_click  = 150 -- Amount of items needed to use lever. Set to 0 in you want no item to be used.
   local item_currency  = 6500 -- Item needed to use lever. Set as Demonic Essences currently.
   local item_name  = "demonic essence" -- name of item_currency

   local chance_to_win  = 30 -- Percent 30/100
   local casino_machine = 00000000 -- ItemID of casino machine
   local exhaust_time = 5 -- 5 seconds (how long before a player can use the machine again) (note:Gm/cm/god is not affected by exhaustion)
   local winner_effect = 30 -- Animation sent at players location when you win

   local ids = { -- THIS IS WHERE YOU PUT ALL ITEMS YOU WANT FOR PRIZES
     [1] =  {item_name = "demon armor", itemID = 2494, amount = 1},
     [2] =  {item_name = "aaaaaaaaaaaa", itemID = 1111111111, amount = 1},
     [3] =  {item_name = "aaaaaaaaaaaa", itemID = 1111111111, amount = 1},
     [4] =  {item_name = "aaaaaaaaaaaa", itemID = 1111111111, amount = 1},
     [5] =  {item_name = "aaaaaaaaaaaa", itemID = 1111111111, amount = 1}  -- LAST LINE MUST NEVER HAVE A " , "
   }

  -- Don't edit below unless your sure you know what to do. :P
   local exstorage = 45001
   local pos = getCreaturePosition(cid)
   local player_gold  = getPlayerItemCount(cid,2148)
   local player_plat  = getPlayerItemCount(cid,2152)*100
   local player_crys  = getPlayerItemCount(cid,2160)*10000
   local player_money  = player_gold + player_plat + player_crys
   if exhaustion.check(cid, exstorage) then
     return doPlayerSendCancel(cid, "Please wait a few seconds before using the casino again.")
   end
   if item.itemid == casino_machine then
     if player_money >= cost_per_click then
       if getPlayerItemCount(cid,item_currency) >= item_per_click then
         doPlayerRemoveMoney(cid, cost_per_click)
         doPlayerRemoveItem(cid, item_currency, item_per_click)
         if(math.random(1, 100) <= chance_to_win) then
           local rand = ids[math.random(#ids)]
           local item = doPlayerAddItem(cid, rand.itemID, rand.amount)
           if rand.amount <= 1 then
             doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "Winner! You receive ".. rand.amount .." ".. rand.item_name ..".")
           else
             doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "Winner! You receive ".. rand.amount .." ".. rand.item_name .."s.")
           end
          doSendMagicEffect(pos, winner_effect)
         else
           doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "Sorry, no luck!")
         end
       else
         doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "You require ".. item_per_click .." ".. item_name .." to use the lottery machine.")
       end
     else
       doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "You require ".. cost_per_click .." gold coins to use the lottery machine.")
     end
   else
     return doPlayerSendCancel(cid, "This is the incorrect item for this script! Check casino_machine ID.")
   end
   exhaustion.set(cid, exstorage, exhaust_time)
return true
end
--Edit
Some mistakes in the code.
Editing to fix.
 
Last edited:
Back
Top