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

Math.random

Saper1995

Technologic
Joined
Jul 11, 2009
Messages
104
Reaction score
3
Location
Poland
Hi, i tried to make casino machine with my own sprites but something goes wrong. I do 3 math.random
first is "CASINO_WIN" - id of winning color sprites
and second is "CASINO_LOSS" - you know
and third is a main random (win/loss)
but even if i loss script make a winning sprites in that pos. or if i win then make losing sprites. How to fix?

Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
local CASINO1 = 11366
local storage = 50002
local wait = 1.0
local CASINO_WIN = {11367, 11368, 11369, 11370} --- winning sprites
local CASINO_LOSS = {11371, 11372, 11373, 11374, 11375, 11404} --- losing sprites
local WINS = math.random(1, #CASINO_WIN)
local LOSES = math.random(1, #CASINO_LOSS)
local machine = {x=1919, y=696, z=8}
local roll = math.random(1, 10)
if item.itemid == CASINO1 and exhaustion.get(cid, storage) == FALSE and getPlayerItemCount(cid, 2152) >= 10 and (roll <=2) then
doPlayerRemoveItem(cid, 2152, 10)
doSendMagicEffect(machine, 188)
doCreateItem(CASINO_WIN[WINS],1,machine)
doPlayerAddItem(cid, 2152, 50)
doSendAnimatedText(fromPosition, "+$", TEXTCOLOR_GREEN)
exhaustion.set(cid, storage, wait)
elseif item.itemid == CASINO1 and exhaustion.get(cid, storage) == FALSE and getPlayerItemCount(cid, 2152) >= 10 and (roll >=3) then
doPlayerRemoveItem(cid, 2152, 10)
doSendMagicEffect(machine, 188)
doCreateItem(CASINO_LOSS[LOSES],1,machine)
doSendAnimatedText(fromPosition, "-$", TEXTCOLOR_RED)
exhaustion.set(cid, storage, wait)
elseif item.itemid == CASINO1 and exhaustion.get(cid, storage) == FALSE and getPlayerItemCount(cid, 2152) < 10 then
doPlayerSendCancel(cid, "You don\'t have enough money to play.")
exhaustion.set(cid, storage, wait)
elseif item.itemid == CASINO1 and exhaustion.get(cid, storage) == TRUE then
doPlayerSendCancel(cid, "The machine is running.")
end
    return TRUE
end
 
Made it more readable..
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)

   -- locals
   local CASINO1 = 11366
   local storage = 50002
   local wait = 1.0
   local CASINO_WIN = {11367, 11368, 11369, 11370} --- winning sprites
   local CASINO_LOSS = {11371, 11372, 11373, 11374, 11375, 11404} --- losing sprites
   local WINS = math.random(1, #CASINO_WIN)
   local LOSES = math.random(1, #CASINO_LOSS)
   local machine = {x=1919, y=696, z=8}
   local roll = math.random(1, 10)
 
   -- if win
   if item.itemid == CASINO1 and exhaustion.get(cid, storage) == FALSE and getPlayerItemCount(cid, 2152) >= 10 and (roll <=2) then
     doPlayerRemoveItem(cid, 2152, 10)
     doSendMagicEffect(machine, 188)
     doCreateItem(CASINO_WIN[WINS],1,machine)
     doPlayerAddItem(cid, 2152, 50)
     doSendAnimatedText(fromPosition, "+$", TEXTCOLOR_GREEN)
     exhaustion.set(cid, storage, wait)
   
   -- if lose
   elseif item.itemid == CASINO1 and exhaustion.get(cid, storage) == FALSE and getPlayerItemCount(cid, 2152) >= 10 and (roll >=3) then
     doPlayerRemoveItem(cid, 2152, 10)
     doSendMagicEffect(machine, 188)
     doCreateItem(CASINO_LOSS[LOSES],1,machine)
     doSendAnimatedText(fromPosition, "-$", TEXTCOLOR_RED)
     exhaustion.set(cid, storage, wait)
   
   -- if no money
   elseif item.itemid == CASINO1 and exhaustion.get(cid, storage) == FALSE and getPlayerItemCount(cid, 2152) < 10 then
     doPlayerSendCancel(cid, "You don\'t have enough money to play.")
     exhaustion.set(cid, storage, wait)
   
   -- if item is used to fast
   elseif item.itemid == CASINO1 and exhaustion.get(cid, storage) == TRUE then
     doPlayerSendCancel(cid, "The machine is running.")
   
   -- end if
   end
 
   -- return onUse function
  return TRUE
end
Optimized it a bit..
Unsure what the problem is.
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)

   -- locals
   local CASINO1 = 11366
   local storage = 50002
   local wait = 1.0
   local CASINO_WIN = {11367, 11368, 11369, 11370} --- winning sprites
   local CASINO_LOSS = {11371, 11372, 11373, 11374, 11375, 11404} --- losing sprites
   local WINS = math.random(1, #CASINO_WIN)
   local LOSES = math.random(1, #CASINO_LOSS)
   local machine = {x=1919, y=696, z=8}
   local roll = math.random(1, 10)
  
   -- check which casino machine
   if item.itemid == CASINO1 then
  
     -- if item is used to fast
     if exhaustion.get(cid, storage) == TRUE then
       doPlayerSendCancel(cid, "The machine is running.")
       return true
     end
    
     -- if no money
     if getPlayerItemCount(cid, 2152) < 10 then
       doPlayerSendCancel(cid, "You don\'t have enough money to play.")
       exhaustion.set(cid, storage, wait)
       return true
     end
    
     -- start checks
     -- if win
     if (roll <=2) then
       doCreateItem(CASINO_WIN[WINS],1,machine)
       doPlayerAddItem(cid, 2152, 50)
       doSendAnimatedText(fromPosition, "+$", TEXTCOLOR_GREEN)
      
     -- if lose
     elseif (roll >=3) then
       doCreateItem(CASINO_LOSS[LOSES],1,machine)
       doSendAnimatedText(fromPosition, "-$", TEXTCOLOR_RED)
      
     -- end checks
     end
    
     -- remove money, add exhaustion, send effect
     doPlayerRemoveItem(cid, 2152, 10)
     doSendMagicEffect(machine, 188)
     exhaustion.set(cid, storage, wait)
    
   -- end if (check which casino machine)
   end
  
   -- return onUse function
  return TRUE
end
 
Last edited:
If the player wins the machine should create a random ID at the position indicated in the table "CASINO_WIN" and if they lose it, "CASINO_LOSS". Unfortunately it does not work and creates random ID. The script does not check the 2 tables, he make a random ID from 2 of them like it was one.
 
Hrm.. well try this and tell me if the issue still persists.
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)

-- locals
local CASINO1 = 11366
local storage = 50002
local wait = 1.0
local CASINO_WIN = {11367, 11368, 11369, 11370} --- winning sprites
local CASINO_LOSS = {11371, 11372, 11373, 11374, 11375, 11404} --- losing sprites
local WINS = math.random(1, #CASINO_WIN)
local LOSES = math.random(1, #CASINO_LOSS)
local machine = {x=1919, y=696, z=8}
local roll = math.random(1, 10)

-- check which casino machine
if item.itemid == CASINO1 then

-- if item is used to fast
if exhaustion.get(cid, storage) == TRUE then
doPlayerSendCancel(cid, "The machine is running.")
return true
end

-- if no money
if getPlayerItemCount(cid, 2152) < 10 then
doPlayerSendCancel(cid, "You don\'t have enough money to play.")
exhaustion.set(cid, storage, wait)
return true
end

-- start checks
-- if win
if (roll <=2) then
doCreateItem(CASINO_WIN[WINS],1,machine)
doPlayerAddItem(cid, 2152, 50)
doSendAnimatedText(fromPosition, "+$", TEXTCOLOR_GREEN)

-- if lose
elseif (roll >=3) then
doCreateItem(CASINO_LOSS[LOSES],1,machine)
doSendAnimatedText(fromPosition, "-$", TEXTCOLOR_RED)

-- end checks
end

-- remove money, add exhaustion, send effect
doPlayerRemoveItem(cid, 2152, 10)
doSendMagicEffect(machine, 188)
exhaustion.set(cid, storage, wait)

-- end if (check which casino machine)
end

-- return onUse function
return TRUE
end
 
Still doesn't work. Idk u even understand what is the problem. It looks like script choose one ID of this 2 table together.
This could looks like:
local CASINO_WIN = {11367, 11368, 11369, 11370} --- winning sprites
local CASINO_LOSS = {11371, 11372, 11373, 11374, 11375, 11404} --- losing sprites

But script see this like : local CASINO_WINSLOSES {11367, 11368, 11369, 11370,11371, 11372, 11373, 11374, 11375, 11404}

Do u understand now? :)
 
So what you are saying is that
a) Sometimes you win and get IDs that are in CASINO_LOSS
b) Sometimes you lose and get IDs that are in CASINO_WIN
Yes?
 
From what your saying there's 2 possibilities.
Either there are some winning ID's in the losing area..
Or your mistaking the 'effect' of the casino that plays every time as the ID that's malfunctioning.
Code:
doSendMagicEffect(machine, 188)
If neither of these statement are true.. then try commenting out the effects for winning,.. and then commenting out the effects for losing.. and find out if they are playing correctly or not.
Code:
doCreateItem(CASINO_WIN[WINS],1,machine)
Code:
doCreateItem(CASINO_LOSS[LOSES],1,machine)
 
Back
Top