Page 2 of 2

Re: Need help with making a "gambling machine"

Posted: Sun Sep 16, 2012 2:54 pm
by Shroom
Shadowfied wrote: I'm so confused about the math part.

if math.random(100) < math.random(90) then

I know what this does but it just confuses me.. Is there a way to print which number is randomed to the console? That would help me understand a lot.
it says:- roll a random number between 1 and 100 and then compare it with another number between 1 and 90.

This makes the 'house' more likely to win - if the numbers are equal then its a nearly even (use <= to make it even)

to break it out

Code: Select all

local playerRoll = math.random(100)
local houseRoll = math.random(90)
hudPrint("Player rolled "..playerRoll.." House rolled "..houseRoll)
if playerRoll < houseRoll then
For some reason I set this to whoever rolls lowest - dont ask me why - maybe thats why it looks wrong

Re: Need help with making a "gambling machine"

Posted: Sun Sep 16, 2012 3:33 pm
by Shadowfied
Snip: removed

Re: Need help with making a "gambling machine"

Posted: Sun Sep 16, 2012 4:24 pm
by Shroom
Replacing the gamble() function

Code: Select all

function gamble()

   if checkContents(alcove_bet, "torch_everburning") then
       local playerRoll = math.random(90)
       local houseRoll = math.random(100)
       hudPrint("Player rolled "..playerRoll.." House rolled "..houseRoll)
       if playerRoll > houseRoll then
         hudPrint("You Win")
         playSound("level_up")
         alcove_win:addItem(spawn("boots_valor"))
      else
         hudPrint("You lose")
         spawn("poison_cloud", party.level, party.x, party.y, 0)
      end
   end

   lever_gamble:setLeverState("deactivated")
end
I have changed it round so that the highest roll wins, with the same bias as before though. Take out the hudPrint once your happy, or revert to the old code without the variables

Re: Useful scripts repository

Posted: Wed Sep 19, 2012 9:34 am
by sevenbirds
Komag wrote:to create a "gambling" setup/machine, where you pay with a certain type of item, and then have a chance at winning a good thing or else get damaged:
--------------
example from Shroom:
I created 2 alcoves and a lever

alcove_bet
alcove_win
lever_gamble

Added an lua entity and put this code in it

Code: Select all

function gamble()

   if checkContents(alcove_bet, "torch_everburning") then
      if math.random(100) < math.random(90) then
         hudPrint("You Win")
         playSound("level_up")
         alcove_win:addItem(spawn("boots_valor"))
      else
         hudPrint("You lose")
         spawn("poison_cloud", party.level, party.x, party.y, 0)
      end
   end

   lever_gamble:setLeverState("deactivated")
end

function checkContents(location,item)
   for object in location:containedItems() do

      -- if you want to show the name of items you actually put in the alcove
      -- then uncomment the hudPrint below
      -- hudPrint(object.name)
      if object.name == item then
         --remove object (but havent worked out how yet!)
         return true
      end
   end
   return false
end
click on the lever and add a connector to the lua script - select "gamble" in the last combo box

As you can see, I have used the item "torch_everburning" as this is what the champion has in his hand when you hit preview. Put this in the alcove and pull the lever.

the math.random() dictate the win chances 1-100 vs 1-90, so not in characters favour.

Change these values as you want to, and code for which items etc.

One thing I couldn't see how to do was remove the bet item. If you want I can post a link with an example saved in the editor.

Hello Komag,

first, your scripts have been really helpful and have allowed me to begin making some great dungeons!
Second, I have a question about your gambling script above. How would you implement a timer so that players can't just pull the lever repeatedly until they win? I know you mentioned trying to remove the item being offered, but I figured a timer could be helpful as well.

Re: Useful scripts repository

Posted: Wed Sep 19, 2012 1:50 pm
by Komag
sevenbirds wrote: Hello Komag,
first, your scripts have been really helpful and have allowed me to begin making some great dungeons!
Second, I have a question about your gambling script above. How would you implement a timer so that players can't just pull the lever repeatedly until they win? I know you mentioned trying to remove the item being offered, but I figured a timer could be helpful as well.
First, thanks! Second, it's Shroom's script, not mine, so I really don't know the inner workings that well. Third, a timer could be part of the "circuit" which would make the lever ineffective for a little while, but the lever itself would still go up and down which might confuse the player why it's not working at the moment, but perhaps that might be okay

Re: Need help with making a "gambling machine"

Posted: Sun Jan 13, 2013 11:44 am
by Asteroth
[quote="frankman2112"]Poker is very easy. The part you have to understand is what hand beats what hand. The important thing is to watch not only what you have, but what the others may have..

________

{old poker link was here - EDITED BY KOMAG}

OK, I admit it. This confuses me. Is this an extremely well directed spam, or just a rather odd comment to revive an old thread for.
'cause it is appropiatly placed like most spam bots would not bother with, yet pretty much an advertisement with nothing to actually say about the topic.

Re: Need help with making a "gambling machine"

Posted: Sun Jan 13, 2013 12:35 pm
by Kuningas
Asteroth wrote:
frankman2112 wrote:Poker is very easy. The part you have to understand is what hand beats what hand. The important thing is to watch not only what you have, but what the others may have..

________

{old poker link was here - EDITED BY KOMAG}
OK, I admit it. This confuses me. Is this an extremely well directed spam, or just a rather odd comment to revive an old thread for.
'cause it is appropiatly placed like most spam bots would not bother with, yet pretty much an advertisement with nothing to actually say about the topic.
They are evolving!

Re: Need help with making a "gambling machine"

Posted: Sun Jan 13, 2013 4:12 pm
by Komag
The spambot just searches for any threads about "gambling" in this case and then auto-submits the spam post which may luckily (to them) seem to fit right in and be harder to detect as pure spam.