Re: Useful scripts repository
Posted: Fri Sep 14, 2012 2:59 pm
Create a "gambling" setup/machine
(you pay with a certain type of item, then have a chance at winning a good thing or getting 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
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.
------------
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
For some reason I set this to whoever rolls lowest - dont ask me why - maybe thats why it looks wrong
----------------------
FINAL EXAMPLE:
Replacing the gamble() function
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
-----
original thread for discussion/questions:
viewtopic.php?f=14&t=3063
(you pay with a certain type of item, then have a chance at winning a good thing or getting 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
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.
------------
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
----------------------
FINAL EXAMPLE:
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
-----
original thread for discussion/questions:
viewtopic.php?f=14&t=3063