Need help with making a "gambling machine"

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
User avatar
Shroom
Posts: 98
Joined: Tue Mar 27, 2012 6:37 pm
Location: UK

Re: Need help with making a "gambling machine"

Post 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
User avatar
Shadowfied
Posts: 47
Joined: Wed Apr 11, 2012 10:42 pm

Re: Need help with making a "gambling machine"

Post by Shadowfied »

Snip: removed
Last edited by Shadowfied on Sun Feb 17, 2019 4:30 pm, edited 1 time in total.
User avatar
Shroom
Posts: 98
Joined: Tue Mar 27, 2012 6:37 pm
Location: UK

Re: Need help with making a "gambling machine"

Post 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
User avatar
sevenbirds
Posts: 10
Joined: Wed Sep 19, 2012 9:26 am

Re: Useful scripts repository

Post 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.
User avatar
Komag
Posts: 3658
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: Useful scripts repository

Post 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
Finished Dungeons - complete mods to play
User avatar
Asteroth
Posts: 471
Joined: Wed Oct 24, 2012 10:41 am
Location: Eastern U.S.

Re: Need help with making a "gambling machine"

Post 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.
I am the God of darkness and corruption.
viewtopic.php?f=14&t=4250
User avatar
Kuningas
Posts: 268
Joined: Wed Apr 11, 2012 10:29 pm
Location: Northern Finland

Re: Need help with making a "gambling machine"

Post 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!
BASILEUS
User avatar
Komag
Posts: 3658
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: Need help with making a "gambling machine"

Post 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.
Finished Dungeons - complete mods to play
Post Reply