Polyfemus Posted May 3, 2014 Share Posted May 3, 2014 FIXED: Figured it out as indicated in the last post I made. Okay so for whatever odd-ball reason it seems that the GetRandomPercent function doesn't work properly when attached to a quest script. I simply rewrote my scripts so that the randomiser portion is handled in the script attached to my activator instead of my quest. I'm working on a prototype of a project to test a repeatable randomizer system that spawns 1 of 2 NPCs with each NPC having a 50% chance of being spawned. I've been successful in making the script to be repeatable however the randomizer doesn't ever spawn 1 of the 2 NPCs. Here's the script: scn aaRepVarsQuestSCRIPT int startRand ; 0 = unintialized randomiser, 1 = randomiser start int RnumCust ; the random number, <= 49 Customer A, >= 50 Customer B int CustAstatus ; 0 = disabled/stand still, 1 = enabled/initiate dialogue, 2 = end dialogue int CustBstatus ; 0 = disabled, 1 = enabled/initiate dialogue, 2 = end dialogue Begin Gamemode if startRand == 1 set RnumCust to GetRandomPercent if (RnumCust <= 49) aaTargetAREF.enable aaTargetAREF.moveto aaRepXmarkerREF set CustAstatus to 1 if (aaTargetAREF.GetIsGhost == 0) aaTargetAREF.setghost 1 endif set startRand to 0 endif elseif (RnumCust >= 50) aaTargetBREF.enable aaTargetBREF.moveto aaRepXmarkerREF set CustBstatus to 1 if (aaTargetBREF.GetIsGhost == 0) aaTargetBREF.setghost 1 endif set startRand to 0 endif endif END There's more to my prototype project than just this script but this script is responsible for randomly assigning a variable a value between 0 to 99 (inclusive). And if that variable value is <= 49 it should spawn NPC A and if the variable is >= 50 it should spawn NPC B. Then after the NPC spawns a dialogue is initiated, then the NPC disappears and the quest and scripts reset. Then once again 1 of the 2 NPCs is ready to be spawned when a button/activator is pushed. However the problem is that NPC A is the only one that gets spawned for whatever reason. I've gone through multiple trials and NPC A is always the only one to be spawned. I don't understand it. I wonder if this is just another silly GECK idiosyncrasy and I'll just have to find another solution. While I wait for someone to respond I'll try changing up the randomizer. For example I'll try this: set randVal to 1 + GetRandomPercent * max / 100 If that doesn't work I'll try the NVSE function Rand. Even if one of these 2 alternate solutions work I'll still be dumfounded why my first solution doesn't. EDIT: Before anyone points it out I do know that about a year ago I made this topic. But the issue and project in that thread is different. Also if you look at the randomizer function used in that other thread it is pretty much the same as the one I'm using here. Link to comment Share on other sites More sharing options...
Polyfemus Posted May 3, 2014 Author Share Posted May 3, 2014 FIXED: Figured it out as indicated in the last post I made. Okay so for whatever odd-ball reason it seems that the GetRandomPercent function doesn't work properly when attached to a quest script. I simply rewrote my scripts so that the randomiser portion is handled in the script attached to my activator instead of my quest. Okay. I've been trying different mutations of my randomizer script but I can't seem to get it to work properly. The script is behaving very oddly. Let me explain. As I posted in the code above I mentioned that NPC A is the only one that gets spawned/selected, suggesting that the value of RnumCust only always gets set into a value <= 49. I tried switching around the placement of NPC A and NPC B in the script. Meaning that I switched it to to where if RnumCust gets set to a value <= 49, this time it will spawn NPC B instead. Doing so actually spawned NPC B. So I tried another mutation of my randomizer script. And what I seemed to have found out is that the script does something it shouldn't! This time I changed the first conditional to point to a condition that should never be satisfied, but the other conditional should always be satisfied. I changed the randomized variable to be set to either the value of 1 or 2. And my second conditional is looking for the RnumCust value of either 1 or 2. Here's the script: scn aaRepVarsQuestSCRIPT int startRand ; 0 = unintialized randomiser, 1 = randomiser start int RnumCust ; the random number, <= 49 Customer A, >= 50 Customer B int CustAstatus ; 0 = disabled/stand still, 1 = enabled/initiate dialogue, 2 = end dialogue int CustBstatus ; 0 = disabled, 1 = enabled/initiate dialogue, 2 = end dialogue Begin Gamemode if startRand == 1 set RnumCust to 1 + GetRandomPercent * 2 / 100 if (RnumCust == 5) aaTargetBREF.enable aaTargetBREF.moveto aaRepXmarkerREF set CustBstatus to 1 if (aaTargetBREF.GetIsGhost == 0) aaTargetBREF.setghost 1 endif set startRand to 0 endif elseif (RnumCust == 1 || RnumCust == 2) aaTargetAREF.enable aaTargetAREF.moveto aaRepXmarkerREF set CustAstatus to 1 if (aaTargetAREF.GetIsGhost == 0) aaTargetAREF.setghost 1 endif set startRand to 0 endif endif END As you can see in the code the conditional for NPC B should never be reached yet on the other hand the conditional for NPC A should definitely satisfied. However when I tried the mod using this script what happened was that none of the NPCs' got spawned. If seems that for whatever reason my script has a bias for the first conditional but failing that conditional it doesn't even bother running through the second conditional. So could anyone shed some light on this problem? Is the GECK scripting really not able to properly do this script? Will I have better success using NVSE functions instead? EDIT: I've tried using the NVSE function Rand instead to see if that would work. It doesn't. The same issue happens where the first satisfiable conditional statement is the only one that gets run at all. Here's the script: scn aaRepVarsQuestSCRIPT int startRand ; 0 = unintialized randomiser, 1 = randomiser start float RnumCust ; the random number, <= 49 Customer A, >= 50 Customer B int CustAstatus ; 0 = disabled/stand still, 1 = enabled/initiate dialogue, 2 = end dialogue int CustBstatus ; 0 = disabled, 1 = enabled/initiate dialogue, 2 = end dialogue Begin Gamemode if startRand == 1 set RnumCust to Rand 1 3 if (RnumCust >= 1 && RnumCust < 2) aaTargetBREF.enable aaTargetBREF.moveto aaRepXmarkerREF set CustBstatus to 1 if (aaTargetBREF.GetIsGhost == 0) aaTargetBREF.setghost 1 endif set startRand to 0 endif elseif (RnumCust >= 2 && RnumCust <= 3) aaTargetAREF.enable aaTargetAREF.moveto aaRepXmarkerREF set CustAstatus to 1 if (aaTargetAREF.GetIsGhost == 0) aaTargetAREF.setghost 1 endif set startRand to 0 endif endif END As you can see NPC A has a slightly increased chance of being spawned (since its chances are 2 to 3 inclusive versus NPC B's 1 (inclusive) to 2 (exclusive). However, since NPC A's relevant script is the second conditional statement for whatever reason NPC A never gets spawned. Whenever I push the spawn button NPC B is the only one to get spawned. All this prototyping has convinced me that a randomizer button that spawns 1 of either 2 NPC is just not possible for whatever reason, at least not the way I've written it due to some GECK flaw. The worst part about all of this is I was able to actually make a randomizer such as this before except I used quest stages rather than simply incremented quest variables. Here's a video that demonstrates the prototype of my old randomizer: http://www.youtube.com/watch?v=VzcSbOv7ZII The reason I scraped that randomizer (of which I still have a copy of the .esp) was because when I tried to expand that system (adding more potential NPCs to the pool) it got increasingly harder and complicated to do the randomizer to the point that I couldn't actually predict what the getstage function was going to give out. Eventually the getstage function simply didn't give me quest stage I anticipated. I'm not sure what I can do at this point, if what I'm trying is feasible. I know that Skyrim has a built-in randomiser for it's repeatable quests so something like this might be easier there but I don't like Skyrim as much. Hmm... Link to comment Share on other sites More sharing options...
Polyfemus Posted May 3, 2014 Author Share Posted May 3, 2014 Figured it out. Okay so for whatever odd-ball reason it seems that the GetRandomPercent function doesn't work properly when attached to a quest script. I simply rewrote my scripts so that the randomiser portion is handled in the script attached to my activator instead of my quest. So now my prototype works and that means that my project should be underway no problem! I hope this helps other people. I repeat, the GetRandomPercent function doesn't work properly when attached to a quest script. Link to comment Share on other sites More sharing options...
wendelgrey Posted June 19, 2014 Share Posted June 19, 2014 I happened on this thread while searching for something yesterday. Anyway, I think the problem is in your code, not the GetRandomPercent function. If you're still interested and haven't worked it out let me know and I'll explain what I mean. Link to comment Share on other sites More sharing options...
Polyfemus Posted June 19, 2014 Author Share Posted June 19, 2014 The fix that worked for me was that the GetRandomPercent function seemed to not work properly when attached to a quest. It doesn't make sense I know but it's the conclusion that I came to after trying it another way. In fact you'll see that the scripts run properly in my Become a Hotdog Vendor mod after I made the GetRandomPercent in my activator script. To take this one step beyond I even wrote up a tutorial for the random customer system I wrote for the mod for another Nexus user. I'll just go ahead and post the tutorial here as well. Link to comment Share on other sites More sharing options...
Polyfemus Posted June 19, 2014 Author Share Posted June 19, 2014 Couldn't post the tutorial in its original form so I've made a .pdf out of it. Here's a download link:https://www.sendspace.com/file/28u71h Link to comment Share on other sites More sharing options...
wendelgrey Posted June 21, 2014 Share Posted June 21, 2014 I'm new to scripting, but I'm using GetRandomPercent in a quest script. The purpose is to add a random item from FormID list 'a9test' to the player's inventory. It's working fine, which wouldn't be the case if GetRandomPercent didn't work. scn a9TestScript ref SourceList ref RetrievedForm short RandomIndex short SourceListItemCount BEGIN GameMode set SourceList to a9test set SourceListItemCount to ListGetCount SourceList set RandomIndex to GetRandomPercent * SourceListItemCount / 100 printc "a9TestScript: %.0f", RandomIndex set RetrievedForm to ListGetNthForm SourceList RandomIndex player.additem RetrievedForm 1 ;stopQuest a9addThingQuest END But as for your script, I see you use syntax like: if (RnumCust <= 49) ; 50%chance to spawn customer A setaaCustQuest.startSpawn to 1; Incrementsa variable in ourquest relevent to customer A endif elseif (RnumCust >= 50) && (RnumCust <= 99) ; 50% chance to spawn customer B set aaCustQuest.startSpawn to 2 endif I'm kind of surprised that even compiles, because everything I've seen indicates you should be doing: if (RnumCust <= 49) ; 50%chance to spawn customer A setaaCustQuest.startSpawn to 1; Incrementsa variable in ourquest relevent to customer A elseif (RnumCust >= 50) && (RnumCust <= 99) ; 50% chance to spawn customer B set aaCustQuest.startSpawn to 2 endif And moreover, you could just leave out the tests in the second half: if (RnumCust <= 49) ; 50%chance to spawn customer A setaaCustQuest.startSpawn to 1; Incrementsa variable in ourquest relevent to customer A else ; 50% chance to spawn customer B set aaCustQuest.startSpawn to 2 endif Link to comment Share on other sites More sharing options...
Recommended Posts