Jump to content

Get player detection level?


PrincessBridget

Recommended Posts

I've been trying this since Oblivion and still can't figure out how to do it. Basically I want to script something where things happen depending on your detection level, like play a sound when I go into [DANGER] state, etc. The problem is, every command other than IsInCombat, seems to need a reference and that's where I'm stuck. How can I tell it to go off my detected level instead of what some certain thing detects me?

 

I'm thinking the GetDetectionLevel command would probably be perfect, but it needs a reference. Ughhh!

 

This is the best I could come with for something that doesn't need a reference, but it plays the sound when I go into caution mode too, which is bad.

 

scn aaDetectScript

Int Detected ;this is to stop it from looping

begin GameMode

if player.isincombat && detected != 1
playsound aaDetectSound
set Detected to 1
endif

if player.isincombat == 0 && detected != 0
set Detected to 0
endif

end

Link to comment
Share on other sites

GetDetected is an all or nothing thing. It can't differentiate the level of detection like GetDectionLevel can. So you are either detected or you aren't. What you need would require FOSE. If you used FOSE you could preform a "Ref-Walk" which can check each reference in a region. You could then check the detection level of each of those refs and play the appropriate sound based on the highest detection level found during the ref-walk. If you are willing to add FOSE as a requirement to your mod, I would be glad to describe the code segment that would work for you.
Link to comment
Share on other sites

I have always found it lame that the vanilla scripting language did not include a command to get the reference of nearby objects, but that's why FOSE came along. I too, started out with the intention that I was going to stay away from FOSE, but in the end, I started using it because it allows for so much more in the way of scripting commands. Anyway, on to the ref-walk...

 

scn MyDetectionScript


Short Depth
Short DLevel
Short MaxDLevel
Ref rCurRef


Begin GameMode
Set MaxDLevel to 0					;reset the maximum detection level to 0
Set Depth to 2 * (player.IsInInterior ==0)		;Assign Cell Depth
set rCurRef to GetFirstRef 200 Depth 0			;Search for all Actors
Label 10						;Loop Start
if rCurRef						;Is it a valid reference?
	Set DLevel to rCurRef.GetDetectionLevel Player	;Determine DLevel for this ref to the player
	If DLevel > MaxDLevel				;Is it the highest DLevel found so far
		Set MaxDLevel to DLevel			;Yes, set the new max DLevel
	Endif
	Set rCurRef to Apple				;Prevent the "Apple" bug
	Set rCurRef to GetNextRef			;Cycle to the next reference
	Goto 10						;Goto Label to cycle the code again
Endif							;Loop will end when no more references are found
If MaxDLevel == 3
	;Player is Seen: Flashing Danger
ElseIf MaxDlevel == 2
	;Player is Noticed: Danger
ElseIf MaxDLevel == 1
	;Player is Unseen: Caution
Else 
	;Player is Lost: Unseen
Endif
End

 

Sorry for the crappy colors in the above code box. If you highlight them, you should be able to read it.

 

This should be put into a quest script with a processing delay of 0.25 or so. That will make it run 4 times a second. The quest should be set as "Start Game Enabled" and when you paste this into the script window, don't forget to set the Script Type to "Quest" in the drop down box on the tool bar of the script window. Just add the code you want to play your sounds in the section at the bottom. It is broken out into the 4 possible detection levels. Your code would go where the comments are. If you have any questions about the code that aren't explained by the comments, just ask. :yes:

Link to comment
Share on other sites

Woww thanks! Yep, I would've never figured that out! I don't have a chance to try it yet, but it should be soon. Thanks again! By the way, I'm thinking of making it Metal Gear Solid-ish sounds on different detections and conditions, but of course minus stealing their sounds because of whatever copyright stuff. Although I don't think/hope recreating the same sounds from scratch should be a problem...
Link to comment
Share on other sites

That code isn't complete. Its just a starting point. For example, you will want to control your sounds from playing repeatedly. If you just added a PlaySound command and the player was currently being detected, that sound would be set to play again and again every 1/4 second - which will result in a horrible buzzing noise. Unfortunately, there is no "stopsound" command even with FOSE. So you will have to time your sounds and run a timer that prevents any new sounds from playing until the current one is finished.
Link to comment
Share on other sites

Hmm, I just tried it and put a playsound and showmessage where the comments were, and nothing's happening. I tried a test message right after Begin GameMode to make sure the script is active, and that message showed up, sooo I'm confused. I'm thinking maybe it's because of the goto 10 thing looping back to label 10 and it doesn't get a chance to proceed maybe?

 

edit: I forgot to mention, I'm testing by walking up to a random friendly person and punching them until they hate me. I tried both in Megaton and the caravans outside Megaton.

Link to comment
Share on other sites

First off, do you have FOSE installed for your game? Second, you have to start FOSE when starting the GECK as well by using "FOSE_Loader.exe -editor". Third to check things out while running the game, you can use FOSE's "PrintC" command to display stuff in the console. In this case, displaying DLevel and MaxDLevel would be useful. You can lookup the formatting codes for printc in the FOSE commands documentation here. If all that fails to get you anywhere, you can upload your file to www.mediafire.com or the like and pass a link to the file here or in a PM and I can take a look at it for you.
Link to comment
Share on other sites

Yes I have FOSE and use the -editor shortcut for the GECK. I knew I should've mentioned that. And well my script is the exact same as what you made, with playsounds at the bottom where you said. I did the quest stuff and the script's definitely active, it's just I couldn't get anything out of putting stuff where you told me.

 

Can you give me a quick example how to put a variable in printC? There's a whole bunch of %a %e %i, I don't know which one it would be. Normally I'd just go in and try a million trial and erroring myself until I figure it out, or stress out and quit, but my god I have to close and reopen the whole game every time I make even a teeny change. At least it doesn't take as long as Oblivion did to load...ugh. But I don't suppose there's a way to edit a mod without needing to reopen the game? The GECK always errors if I try that.

Link to comment
Share on other sites

For those short variables, printc would look like this:

 

printc "DLevel = %.0f MaxDLevel = %.0f" Dlevel MaxDLevel

 

I am sorry it didn't work straight off. I didn't test that code myself beyond making sure it would compile. I do use very similar versions all over the place without issue.

 

There is another console command that might be useful to you in this case, and that is:

 

scof "MyTextFile.txt"

 

If you use the scof (Set Console Output File) command, it will redirect all console output to the text file you specify. The file will be in your \Fallout folder and then you can see all of the console output that was generated, not just the last page that you see on the screen. If you still don't get anywhere, I'll try it out myself and see what gives.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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