Scripts within scripts?

Post » Mon Aug 23, 2010 5:33 pm

Is there any way to have a script that will decide which script is to be performed next, but those scripts are actually listed as separate scripts?

For example, first, I make Script A.

Then, I make Script B.

Then, I make Script X, which chooses a random percentage, and then, it says, if the random percentage is 49 or less, then cause Script A to be performed, but if it is 50 or greater, perform Script B.

I think this is at least theoretically possible. After all, it is possible to put leveled items INSIDE leveled items. For example, if I want an NPC to carry a random, leveled sword, but that sword is randomly either a shortsword or a longsword, then all I have to do is create a leveled longsword (between iron and daedric) and a leveled shortsword, and then create a third "leveled" item that has both of those other leveled items, but they are both available at level one. That way, whenever the item is chosen, it could be a steel shortsword, or a steel longsword.

So, because you can have leveled items within leveled items, I'm pretty sure that it's possible to have scripts within scripts. But... how do you do it?
User avatar
Crystal Clear
 
Posts: 3552
Joined: Wed Aug 09, 2006 4:42 am

Post » Mon Aug 23, 2010 9:26 am

Is there any way to have a script that will decide which script is to be performed next, but those scripts are actually listed as separate scripts?

For example, first, I make Script A.

Then, I make Script B.

Then, I make Script X, which chooses a random percentage, and then, it says, if the random percentage is 49 or less, then cause Script A to be performed, but if it is 50 or greater, perform Script B.


Script A and B need to be Quest Scripts. To do this go into the CS and create two new quests (i.e. ScriptAQuest and ScriptBQuest) and then from the Quest dialog window you can assign ScriptA and ScriptB to ScriptAQuest and ScriptBQuest respectively. After you've done that it is just a matter of using the StartQuest command inside of ScriptX.

Begin GameModeif ( RandomVariable >= 50 )	StartQuest ScriptAQuestelse	StartQuest ScriptBQuestendif	End


I'm not sure how to generate a random number in the CS, but if you use http://obse.silverlock.org/ there is a function called http://cs.elderscrolls.com/constwiki/index.php/Rand that will take care of it.

With OBSE you can also have scripts inside scripts through http://obse.silverlock.org/obse_command_doc.html#User_Defined_Functions, but I suspect you can get by without it at this time.
User avatar
Kirsty Wood
 
Posts: 3461
Joined: Tue Aug 15, 2006 10:41 am

Post » Mon Aug 23, 2010 8:35 pm

Create a global variable called myNumberGBL

Make the controller script 'however', it will update the global variable.
GetRandomPercent returns a number from 0-99.

If the scripts are location specific, you can just place them on an activator and drop it in the cell, hidden from view.
Otherwise you will need to make these quest scripts with conditions around them.

scn myMasterScriptshort myNbegin GameMode   if myNumberGBL == 0      set myN to GetRandomPercent      if myN < 50         set myNumberGBL to 1      else         set myNumberGBL to 2      endif   endifend


scn my1Scriptbegin GameMode   if myNumberGBL == 1      ;do stuff in script 1      ;When done set global back to 0   endifend


scn my2Scriptbegin GameMode   if myNumberGBL == 2      ;do stuff in script 1      ;When done set global back to 0   endifend

User avatar
Rich O'Brien
 
Posts: 3381
Joined: Thu Jun 14, 2007 3:53 am


Return to IV - Oblivion