Jump to content

Problem with random int, from 1to 1000000


Interfer0

Recommended Posts

I'm thinking there's an easy way to do this, but I suck at math. The only thing I can think of is to have it layered, >75% would be a win, then >x percent would place you in the next winning bracket, and so on and so forth until the chances of a jackpot at 1 in 250,000.

 

 


scn Slotmachinescript

short Done
short Button
short Slotm														1= The laboratory is now "brewing" a drug
short ProcessButton
ref mySelf
float Spinchance



;Globals used here


begin OnActivate
if IsActionRef player == 1
		
		set ProcessButton to 1
		ShowMessage SlotMachineMainmessage01
	
endif
end

begin gamemode

;This section of the gamemode block handles all of the button presses on the Laboratory kit

set Button to GetButtonPressed
if Button > -1
	if ProcessButton == 1
		if ( Button == 0 )
			set mySelf to getSelf
			ShowMessage SlotMachinePlaymessage01
                   mySelf.playSound3D Slotmachine01

					set Spinchance to 1.000000  * GetRandomPercent * 1000000


						if ( Spinchance >= 1 && Spinchance <=4)
							Player.AddItem Caps001 2400
							ShowMessage Slotsplay01

						elseif ( Spinchance >= 5 && Spinchance <=11)
							Player.AddItem Caps001 1199
							ShowMessage Slotsplay02

						elseif ( Spinchance >= 12 && Spinchance <=30)
							Player.AddItem Caps001 200
							ShowMessage Slotsplay03

						elseif ( Spinchance >= 31 && Spinchance <=687)
							Player.AddItem Caps001 50
							ShowMessage Slotsplay04

						elseif ( Spinchance >= 688 && Spinchance <=801)
							Player.AddItem Caps001 40
							ShowMessage Slotsplay05

						elseif ( Spinchance >= 802 && Spinchance <=1444)
							Player.AddItem Caps001 25
							ShowMessage Slotsplay06

						elseif ( Spinchance >= 1445 && Spinchance <=1648)
							Player.AddItem Caps001 20
							ShowMessage Slotsplay07

						elseif ( Spinchance >= 1649 && Spinchance <=30043)
							Player.AddItem Caps001 10
							ShowMessage Slotsplay08

						elseif ( Spinchance >= 30044 && Spinchance <=60000)
							Player.AddItem Caps001 5
							ShowMessage Slotsplay09

						elseif ( Spinchance >= 60001 && Spinchance <=750000)
							Player.AddItem Caps001 1
							ShowMessage Slotsplay10

						endif
		elseif ( Button == 1 )
			ShowMessage SlotMachineHowmessage01

		elseif ( Button == 2 )
		endif
	endif
	; clear button variable
	set ProcessButton to 0
endif



	endif
endif

end

Link to comment
Share on other sites

When posting scripts, please use "code" tags, or "codebox" tags for longer scripts, and indent them correctly - this will make them much easier to read and drastically increase the likelihood of someone bothering to help you. If you don't know how to indent scripts, here is a site that can do it for you - Script Indenter.

 

The first thing I noticed when I looked at this script is that you have two more "endif" statements than you should have - you should go back through this script and fix this.

 

GetRandomPercent returns a random integer value between 0 and 99 (inclusive), so multiplying it by 1,000,000 will not produce a random value between 0 and 99,000,000. You could instead try something like this:

ScriptName SlotMachineScript

short Button

Begin OnActivate player
set Button to -1
ShowMessage SlotMachineMainMessage01
End

Begin GameMode
if Button == -1
	set Button to GetButtonPressed
	if Button == 0
		PlaySound3D SlotMachine01
		set Button to GetRandomPercent + GetRandomPercent * 100 + GetRandomPercent * 10000
		; check value of Button
	elseif Button == 1
		ShowMessage SlotMachineHowMessage01
	endif
endif
End

Cipscis

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...