Script for "Dice Roll"

Post » Fri Jan 14, 2011 12:27 pm

Ok for my mod it's like a 'Random encounter' how do I make a random number/dice roll? I heres bit of what it is going to do but I don't know how to set 'encounterNum' var to a Random number (like 1-30) if your can help me I am lost in what to do for the Random number/dice roll thing lol.

SCN CUSRINLinPoopleattSCRPTshort encounterGo ; 1 = start the encountershort EnReturn	; 1 = cancel encounter (one Or NPC(s) is dead0short encounterNumBEGIN gamemodeif player.getincell MyCellID == 1if encounterNum == 1; do nothing endif encounterNum == 2; do nothing endif encounterNum == 3if BobGenREF.getdead == 0set encounterGo to 1BobGenREF.enableBobGenREF.moveto playerBobGenREF.startcombat playerelseset EnReturn to 1endifendifendEND

User avatar
Gemma Archer
 
Posts: 3492
Joined: Sun Jul 16, 2006 12:02 am

Post » Fri Jan 14, 2011 7:55 am

1. You cannot end your 'IF' commands with an 'end' command. The end command will terminate the current script block.

2. Use http://geck.gamesas.com/index.php/GetRandomPercent to get a random number. I usually use the default and return a value from 0 to 99. I then split that up in my IF checks divided evenly.

set myRanNum to GetRandomPercentif myRanNum < 3   ;do thiselseif myRanNum < 6   ;do thiselseif myRanNum < 9   ;do thiselseif myRanNum < 12   ;do thiselseif myRanNum < 15   ;do thiselse   do thisendif


And since the first 'true' statement is executed, you do not need to check for 'greater than' values if you set it up checking lowest to highest.
User avatar
Amanda Furtado
 
Posts: 3454
Joined: Fri Dec 15, 2006 4:22 pm

Post » Fri Jan 14, 2011 10:51 am

1. You cannot end your 'IF' commands with an 'end' command. The end command will terminate the current script block.

2. Use http://geck.gamesas.com/index.php/GetRandomPercent to get a random number. I usually use the default and return a value from 0 to 99. I then split that up in my IF checks divided evenly.

set myRanNum to GetRandomPercentif myRanNum < 3   ;do thiselseif myRanNum < 6   ;do thiselseif myRanNum < 9   ;do thiselseif myRanNum < 12   ;do thiselseif myRanNum < 15   ;do thiselse   do thisendif


And since the first 'true' statement is executed, you do not need to check for 'greater than' values if you set it up checking lowest to highest.

Thanks with your help I Came up with this it only gets the values 1-10 now thanks I forgot about GetRandomPercent if anyone thinking what 'enGo' is it's just a var to stop looping lol
if player.getincell Tenpenny01 == 1 && enGo == 0set encounterNum to  GetRandomPercent * 1/10if encounterNum == 1;Do nothingset enGo to 1elseif encounterNum >= 2 && encounterNum <=4Showmessage DebugMESSset enGo to 1elseif encounterNum == 5Showmessage DebugMESSset enGo to 1elseif encounterNum == 6;Do nothingset enGo to 1elseif encounterNum == 7Showmessage DebugMESSset enGo to 1elseif encounterNum == 8Showmessage DebugMESSset enGo to 1elseif encounterNum == 10;Do nothingset enGo to 1elseif encounterNum == 10Showmessage DebugMESSset enGo to 1ENDIFENDIF

User avatar
Miranda Taylor
 
Posts: 3406
Joined: Sat Feb 24, 2007 3:39 pm

Post » Fri Jan 14, 2011 2:13 am

You have two '10's which is probably a typo. One of them probably should be a '9'.
User avatar
adame
 
Posts: 3454
Joined: Wed Aug 29, 2007 2:57 am

Post » Fri Jan 14, 2011 4:16 am

You have two '10's which is probably a typo. One of them probably should be a '9'.

Yea typo lol one last question on 'Return' does 'Return' stop rest of the code from executing? here is it so far
SCN CUSRINLinPoopleattSCRPTshort enGo ; 1 = start the encounter ;2 = encounter not doneshort EnReturn	; 1 = cancel encountershort encounterNumshort EnEnd ;set to 1 from a different script (the NPCs  script)BEGIN GameModeif player.getincell OldOlney01 == 0 ;PC is now  not in the cell OldOlney01if EnReturn == 1 ; used if one or more of the NPCs are still dead and has not being respawned yet.set EnReturn to 0 ; sets back to 0Return ;******THISendifif enGo ==1 && EnEnd ==0set enGo to 0elseif enGo == 2 && EnEnd ==1set enGo to 0set enEnd to 0endifendifendifif player.getincell OldOlney01 == 1 && enGo == 0 && EnEnd == 0                                     set encounterNum to  GetRandomPercent * 1/10                if encounterNum == 1;Do nothing                      set enGo to 1                    elseif encounterNum >= 2 && encounterNum <=4                    if CUSRENLinPeopleF44MagREF.getdead == 0 && CUSRENLinPeopleMREF.getdead == 0CUSRENLinPeopleF44MagREF.enableCUSRENLinPeopleMREF.enableCUSRENLinPeopleF44MagREF.moveto playerCUSRENLinPeopleMREF.moveto playerset enGo to 2elseset EnReturn to 1 ;Err One or both NPCs are dead cancel encounter for now.Return ;******THISendifelseif encounterNum == 5set enGo to 1elseif encounterNum == 6set enGo to 1  ;Do nothing set to 1 to stop code from executing till PC reenters cell OldOlney01elseif encounterNum == 7set enGo to 1  ;Do nothing set to 1 to stop code from executing till PC reenters cell OldOlney01elseif encounterNum == 8set enGo to 1  ;Do nothing set to 1 to stop code from executing till PC reenters cell OldOlney01elseif encounterNum == 9set enGo to 1   ;Do nothing set to 1 to stop code from executing till PC reenters cell OldOlney01elseif encounterNum == 10set enGo to 1  ;Do nothing set to 1 to stop code from executing till PC reenters cell OldOlney01ENDIFENDIFEND


Nothing much for the NPCs scr
SCN LinPeopEn01SCRshort DeathCounterBEGIN ondeathset DeathCounter to DeathCounter +1if DeathCounter >=2set DeathCounter to 0set CUSRINLinPeopleatt.EnEnd to 1endifEND

User avatar
Javier Borjas
 
Posts: 3392
Joined: Tue Nov 13, 2007 6:34 pm

Post » Fri Jan 14, 2011 2:29 pm

I cant read your script easily without being indented for each IF/Endif block of code. (like my example above)

You can read up on the http://cs.elderscrolls.com/constwiki/index.php/Return command there.
User avatar
Sun of Sammy
 
Posts: 3442
Joined: Mon Oct 22, 2007 3:38 pm


Return to Fallout 3