Script: A check for .issneaking?

Post » Thu Jun 24, 2010 1:56 pm

I'm working on a quest script that basically functions when you are sneaking, but I'm unsure of how to word the check correctly.

Would it be(?):

If (player.issneaking == 1)

or

would I need to use a Get function? I don't think there is one though for sneaking
User avatar
james reed
 
Posts: 3371
Joined: Tue Sep 18, 2007 12:18 am

Post » Thu Jun 24, 2010 3:36 pm

The "== 1" part is redundant, but legal. Otherwise, that's fine.

For functions that return a logical (boolean) result, the alternatives are really 0 or not, so I get squeamish about assuming that "not zero" is the same as 1, so I may code "== 0" but I don't test for 1. Part of that is another personal preference for never coding a negative test, just because the "else" is a double-negative.
User avatar
tiffany Royal
 
Posts: 3340
Joined: Mon Dec 25, 2006 1:48 pm

Post » Thu Jun 24, 2010 12:25 pm

Well, I really don't need a logical result for the script. I just basically need it to be checking if the player is sneaking, otherwise I don't want the script to be working.

Here's how I currently have the check in place:


Short A
Short B
Begin Gamemode

If (player.issneaking == 1)
Set A to Rand 1 4
Else
Return
EndIf
If (A <= 2)
"Result"
Else
Return
Endif
End

**Arg, wish the forum would allow tabs in sentence structure.
User avatar
Je suis
 
Posts: 3350
Joined: Sat Mar 17, 2007 7:44 pm

Post » Thu Jun 24, 2010 1:47 am

Hmm. CS is telling me that the "If (player.issneaking == 1)" has an undefined If function. Got any suggestions?
User avatar
lexy
 
Posts: 3439
Joined: Tue Jul 11, 2006 6:37 pm

Post » Thu Jun 24, 2010 6:05 am

Well, I really don't need a logical result for the script. I just basically need it to be checking if the player is sneaking, otherwise I don't want the script to be working.
You misunderstood ghastley. What he means that you're not interested in knowing if issneaking returns exactly 1, but rather whether the player is sneaking, thus no need for the "== 1" part.

CS is telling me that the "If (player.issneaking == 1)" has an undefined If function. Got any suggestions?
The only thing the CS would react on in your script is the "Result" line. "If (player.issneaking == 1)" is certainly ok.
User avatar
Nicholas
 
Posts: 3454
Joined: Wed Jul 04, 2007 12:05 am

Post » Thu Jun 24, 2010 6:04 am

deleted
User avatar
Syaza Ramali
 
Posts: 3466
Joined: Wed Jan 24, 2007 10:46 am

Post » Thu Jun 24, 2010 7:26 am

Like Ghastley said, both the "== 1" and especially the "Else Return" are completely unnecessary.
I know that you're trying to halt the rest of the script from running if the player is not sneaking, but placing the whole script inside that If block accomplishes the same thing with greater efficiency.
It should look like
Short AShort BBegin GamemodeIf (player.issneaking)    Set A to Rand 1 4    If (A <= 2)        "Result"    EndifEndIfEnd

User avatar
Isaiah Burdeau
 
Posts: 3431
Joined: Mon Nov 26, 2007 9:58 am

Post » Thu Jun 24, 2010 7:35 am

You misunderstood ghastley. What he means that you're not interested in knowing if issneaking returns exactly 1, but rather whether the player is sneaking, thus no need for the "== 1" part.

The only thing the CS would react on in your script is the "Result" line. "If (player.issneaking == 1)" is certainly ok.


Hmm, I just placed the word "result" as a generic term. That particular part of the script is pretty large. I have a truncated version of it that only has two results. Here it is:

scn AASWRanEnc
;This is the random chance and type for encounters

Short SWChance1
Short SwChance2
Begin Gamemode

If (player.issneaking == 1) && If (GetStage AASW >= 20)
Set SWChance1 to Rand 1 4
Else
Return
EndIf
If (SWChance1 <= 2)
Set SwChance2 to Rand 1 2
Else
Return
Endif
If (SwChance2 <= 1)
Assas1Ref.moveto Player 100,100,0
Assas1.enable
Elseif (SwChance2 >= 2)
Assas2Ref.moveto Player -100,-100,0
Assas2Ref.enable
Endif
End

Edit: I'm still getting the undefined error for line 10, which is the player.issneaking and stage check. I took out the stage check and it was able to move on, so there must be a problem with the stage check. Syntax looks fine to me though. It must be something to do with the way I have the stage set up.

Edit2: I have this on a quest script and just did a test run of the script and it called the NPC up. Unfortunately, it seems to have stopped working after that. I thought quest scripts were supposed to run every 5 seconds.
User avatar
Kayleigh Williams
 
Posts: 3397
Joined: Wed Aug 23, 2006 10:41 am

Post » Thu Jun 24, 2010 12:17 pm

Hmm, I just placed the word "result" as a generic term. That particular part of the script is pretty large. I have a truncated version of it that only has two results. Here it is:

If (player.issneaking == 1) && If (GetStage AASW >= 20)

only need first if:
If (player.issneaking == 1) && (GetStage AASW >= 20)
User avatar
Roberto Gaeta
 
Posts: 3451
Joined: Tue Nov 06, 2007 2:23 am

Post » Thu Jun 24, 2010 2:14 am

Not sure of your desired percentage but with SWChance1 being a short, 'Rand 1 4' will only return 1, 2, 3 since Rand produces a float that is then truncated for the short. 4 can show up but only if Rand produces exactly 4, extremely low percantage.

Short SWChance1
Set SWChance1 to Rand 1 4
User avatar
roxxii lenaghan
 
Posts: 3388
Joined: Wed Jul 05, 2006 11:53 am

Post » Thu Jun 24, 2010 4:30 pm

Not sure of your desired percentage but with SWChance1 being a short, 'Rand 1 4' will only return 1, 2, 3 since Rand produces a float that is then truncated for the short. 4 can show up but only if Rand produces exactly 4, extremely low percantage.

Short SWChance1
Set SWChance1 to Rand 1 4



Oh okay! Thanks for the bit of info. I can also probably do a Rand 1 5 then and for the last If statement, make it >=4 to cover it. That would also explain why the other NPC would not show up on SWChance2 since it only has two outcomes. I kept wondering why the heck only one npc was showing up, LOL! That probably just saved me hours and hours of frustration and trying to figure out why that was happening.

And thanks again for the stagecheck syntax. I'll give that a go and take out the other If in it. I kind of figured it had something to do with it, but couldn't figure it out since the game has similar scripts.

Oh, after sleeping on it, I finally figured out that I needed to check the box that says repeatable stages on the Quest Data tab and got the quest script to finally run again and again. I needed to do that anyways with how the mod is going to work anyways.

Thank you so very much everyone for the help you've provided. :foodndrink: This has FINALLY gotten me to the point where I'm comfortable with the main script engine of the mod. Time to go celebrate!!!! :celebration:
User avatar
renee Duhamel
 
Posts: 3371
Joined: Thu Dec 14, 2006 9:12 am


Return to IV - Oblivion