Need help with making a "gambling machine"

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
User avatar
Shadowfied
Posts: 47
Joined: Wed Apr 11, 2012 10:42 pm

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.
Lmaoboat
Posts: 359
Joined: Wed Apr 11, 2012 8:55 pm

Re: Need help with making a "gambling machine"

Post by Lmaoboat »

I think I saw stuff about random numbers here:
http://www.grimrock.net/modding/save-ga ... variables/
Fistchandeles
Posts: 23
Joined: Wed Sep 12, 2012 10:02 pm

Re: Need help with making a "gambling machine"

Post by Fistchandeles »

Another thing to think about . . .

It's not much of a gamble if it's a rock. Perhaps a loss of life or hunger?
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 »

You could have the pressure plate respond only to items (not monsters or the party), although this would allow other objects to work and not just rocks
Finished Dungeons - complete mods to play
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
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 »

one crazy way is to have the plate connect to a script that toggles a lever, then you can always check the lever state with "mylever:getLeverState()"

- make plate
- make script (lua):

Code: Select all

-- plate lever toggle
function platetoggle()
     mylever:toggle()
end
- in plate Inspector, create connection to script, with "platetoggle" as the action

so far, this gets the pressure plate to activate a lever. Test it by placing a lever nearby (even on the wall right in front of the plate) to just see if it works right, making the lever go down and up when placing a rock on and off the plate)

Then you can move the lever to some little room far away so it isn't heard

- then make a script that checks the lever state and does something if it's activated

Code: Select all

-- do something special script
function leveraction()
     if mylever:getLeverState() == "activated" then
          superdoor:open()
     else
          superdoor:close()
     end
end
- go into mylever inspector and create a connection to the new script with "leveraction" as the Action
this would then open the door you have called "superdoor", so you can set this up for a test
So if you want it to do something else, you can change "superdoor:open()" to some other action


This whole setup above is ridiculous though because it's easy to just link a plate to a door. But it just illustrates how you can do some things with scripts.
Finished Dungeons - complete mods to play
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 »

You could use

entitiesAt(level, x, y)

in order to find out what they are 'betting'.

So, for example, use a lever activate a teleport which just moves objects to a holding area - this hits a floor trigger which runs the code to scan the contents. Do some random rolling and then create winnings at another location next to them, before finally destroying the 'bets'


edit: just found this while looking through the references

Alcove:containedItems()

so no need for teleporters etc
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 »

Sure :)

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.
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.
Post Reply