Jump to content

A generic scanner in sexout (code review please!)


prideslayer

Recommended Posts

You modders with scanners, Loogie, Hal, and Prkr mainly, does this idea hold any interest for you?

 

I'm thinking of implementing a generic scanner in sexout that could be hooked by all the mods that want scanning functionality. It would cut down on code maintenance by everyone, ensure all mods using scanners play nicely together (at least their scanning will!), and so on.

 

My thought is to implement three different scanners initially. One for male NPCs, one for female, one for creatures, with a frequency of 1hz (once per second).

 

Mods would register for notification the same way the global sex hook works. Create a formlist (or three) in your mod, and a spell, and add them all to new sexout formlists (SexoutScannerListsM, SexoutScannerListsF, SexoutScannerListsC, SexoutScannerSpells).

 

Whenever the scanner runs, it will bulld an internal formlist for each of the three categories listed above and:

- skip children

- skip creatures that there is no animation for

- ??? (ideas welcome)

 

After the scanner runs, it will copy the formlists into the ones your mods provide, and then call your spells (on the player) to notify you that your form lists have been updated. Put protection inside your spell script to ensure it isn't run more than once -- it won't happen anyway to most people, but some (looking at you astymma!) run threading mods that allow many scripts to run at once.

 

As with the other global hook, it will be up to you to clear out your formlists -- ideally in the StartEffect block.

 

If this is something other modders think is a good idea, I'll put it on my list, implement it, and modify basic SexoutRapers to use it as a sort of demo.

 

 

Link to comment

Formlists are easy. Look at sexoutnotify to see how they're used, this system will be much the same. Even if just the two of you use it, along with rapers, it's worth it. It's a "big win" if tryouts can switch to it as well -- every one of them has a scanner.

 

If nothing else it'll cut down on CPU usage. They don't use a lot, but it can't be "good" having 15 different mods all running exactly the same scanner code constantly.

Link to comment

Sounds good, I'm also looking for some way to detect the start & end of sex events, ideally later I'd also like to be able to control the duration of the event. I'm thinking of creating an arousal/orgasm based plugin later so sex would look at the Lust built and preferences to determine orgasm occuring for raper/rapee, of course in the case of rape the raper wouldn't stop till they got to orgasm.

Link to comment

I'd look into using' date=' I guess, though I'd have no idea how.

[/quote']

 

I could do the first one or two for you. Hell maybe I'll be bored and do them all.

 

Sounds good' date=' I'm also looking for some way to detect the start & end of sex events[/quote']

 

Use the global hook for the start, that already exists. Notify and Crowds both use it. Detecting the end, right now, you have to watch for 00SexoutActor to vanish.

 

, ideally later I'd also like to be able to control the duration of the event. I'm thinking of creating an arousal/orgasm based plugin later so sex would look at the Lust built and preferences to determine orgasm occuring for raper/rapee, of course in the case of rape the raper wouldn't stop till they got to orgasm.

 

You can set the duration fairly long (like 5 minutes), and then abort it earlier if you need to.

Link to comment

I'd look into using' date=' I guess, though I'd have no idea how.

[/quote']

 

Yes. I'm all for it, not just because of CPU usage but it's simply nice to have some code ready-to-use if I ever decided to make something that has to use a scanner. The less people have to struggle with code because it's already available and optimized, the more they can focus on the gameplay/dialogue/immersion/quests side of things. But that would also require some easy-to-follow instructions for people like myself who aren't too quick on the uptake... (at the moment, I'm not even sure how to make people have sex :P)

 

Link to comment

Docta, lots of instructions on how to use sexout are linked to in the first post in its thread, it's pretty easy.

 

Using the formlists will be.. easier than writing your own scanner, but not braindead easy. You'll need to.

 

1. Create three formlists. Easy clicking in the geck.

2. Create an init block in your mods main quest script, if it doesn't already have one (naughty naughty!)

3. Create a spell (this requires creating an effect script and a base effect). More geck clicking, except the script of course.

4. In the init block, add each formlist to the corresponding sexout formlist.

ListAddForm SexoutScannerListsM MyScannedMales
ListAddForm SexoutScannerListsF MyScannedFemales
ListAddForm SexoutScannerListsC MyScannedCreatures

5. Add the spell you made to the formlist for spells.

ListAddForm SexoutScannerSpells MySpell

 

 

That's "it".

 

The script you write in step three will be run on the player once every second, by casting the spell you provided on the player. When that happens, the three lists above (MyScanned*) that are in your mod, will contain all the males, females, and creatures.

 

You can loop through the lists 'doing stuff' with those NPCs. When you're done (end of the spell block) you need to clear those three MyScanned* formlists.

 

It may make more sense for there to just be one list for everything, and leave detecting males, females, and creatures up to the individual mods, as I think about it.

 

Some of the scanners are using GetDistance and stuff like that, which will become combersome to find the "closest" NPC when you don't care about gender or creatureness.

Link to comment

So the revised proposal is to just have one formlist, not all three. Sexout will have two. SexoutScannerListN (NPCs) and SexoutScannerListS (Spells).

 

You'll only need one in your own mod.

 

Sneaky trick: You can also use this as a 1hz timer / "clock pulse". Just don't do the formlist part. Sexout will cast the spell on the player once per second, if there's something else you want to do every second, that has nothing to do with scanning.

Link to comment

I could do the first one or two for you. Hell maybe I'll be bored and do them all.

 

 

Once I have an example to follow, I could do the rest. Only concern I have is scanners that turn off and on during special circumstances, like the NCR and fiends ones.

 

 

 

Link to comment

I could do the first one or two for you. Hell maybe I'll be bored and do them all.

 

 

Once I have an example to follow' date=' I could do the rest. Only concern I have is scanners that turn off and on during special circumstances, like the NCR and fiends ones.

 

 

 

[/quote']

 

You can check those flags in your spell. You could do the same thing by either:

 

1. Removing your spell from the sexout formlist when you don't want it called.

 

2. Checking your enable/disable flag in your spell instead of in the scanner.

 

The 2nd option is probably easier and safer.

Link to comment
Sneaky trick: You can also use this as a 1hz timer / "clock pulse". Just don't do the formlist part. Sexout will cast the spell on the player once per second' date=' if there's something else you want to do every second, that has nothing to do with scanning.[/quote']

And if you want to have a game world timing script that keeps track of real time missed during sleep / wait & fast travel you can use this nifty code in the block fired by the 1Hz timer.

; *** Alter Script run times to catch up after Fast Travel / Wait / Sleep

; *** Intitialise so script doesn't lockup
If fLastUpdatedTime == 0 || fHoursPassed <= 0
	Set fLastUpdatedTime to (GameDaysPassed * 24) - .0002
endif

; *** GameDays passed

Set gTimeStep to .1
Set fCurrentTime to GameDaysPassed * 24
Set fHoursPassed to fCurrentTime - fLastUpdatedTime

If fHoursPassed > gTimeStep
	If fHoursPassed > 1
		Set gTimeStep to .2
	endif
	If fHoursPassed > 4
		Set gTimeStep to .5
	endif
	If fHoursPassed > 8
		Set gTimeStep to 1
	endif
	If fHoursPassed > 16
		Set gTimeStep to 2
	endif
	Set fLastUpdatedTime to fLastUpdatedTime + gTimeStep

:*** do anything here you want repeated if missed to catchup, this script will keep firing this block every second till it catches up then resume to working just every 6 minutes (.1 gTimeStep) I increase gTimeStep to catchup faster and I then use gTimestep as a multiplier in the stuff done here. You would use a gTimeStep of 1 if you only wanted to check or modify something every game hour instead of 6 minutes.

endif

Link to comment

Code for this is in and ready. Posting the scanner quest script here for any additional ideas, criticisms, or comments before I release a version with it and modify rapers (or perhaps crowds) to use it.

 

Debugging statements will obviously be changed to debugprints or removed before release.

 

scn SexoutScannerQSCRIPT

int gInitS
int gInitE
float gsp
float fDelay
ref lastCell
ref actor
int whileIa
int whileIb
int whileSa
int whileSb
int whileSc
int whileCa
int whileCb
int nIdx
int nCnt
ref remoteList
ref remoteSpell
int dbgScanCnt

begin MenuMode
 if ((MenuMode 1012) || (MenuMode 1007))
   ; Sets the delay timer whenever sleeping or loading
   if (fDelay != 5)
     set fDelay to 5
   endif
 endif
end

begin GameMode
 set gsp to GetSecondsPassed

 if (GetGameRestarted || GetGameLoaded)
   set whileIa to 0
   set whileIb to 1
   set whileSa to 10
   set whileSb to 11
   set whileSc to 12
   set whileCa to 20
   set whileCb to 21
   set fDelay to 5
   set dbgScanCnt to 0

   ; reset formlists to clear dirty data
   set nCnt to ListGetCount SexoutScannerListN
   Label whileIa
   if (nCnt > 0)
     ListRemoveNth SexoutScannerListN 0
     set nCnt to ListGetCount SexoutScannerListN
     goto whileIa
   endif

   set nCnt to ListGetCount SexoutScannerListS
   Label whileIb
   if (nCnt > 0)
     ListRemoveNth SexoutScannerListS 0
     set nCnt to ListGetCount SexoutScannerListS
     goto whileIb
   endif
 endif

 ; Delay block for fast travel etc.
 if fDelay > 0
   set fDelay to fDelay - gsp
   return
 endif

 ; begin scanner
 PrintToConsole "Scanning..."
 set actor to GetFirstRef 200
 Label whileSa
 if actor
   PrintToConsole "SEXSCAN DEBUG: Found %n" actor
   set nCnt to ListGetCount SexoutScannerListN
   set nIdx to 0

   if (nCnt > 0)
     Label whileSb
     if ((nIdx + 1) <= nCnt)
       set remoteList to ListGetNthForm SexoutScannerListN nIdx
       ListAddForm remoteList actor
       PrintToConsole "SEXSCAN DEBUG: Added %n to %n" actor remoteList
       set nIdx to nIdx + 1
       goto whileSb
     endif
   endif
   set actor to GetNextRef
   goto whileSa
 endif
 PrintToConsole "Scan %g complete" dbgScanCnt
 set dbgScanCnt to dbgScanCnt + 1
 ; end scanner

 ; Call remote spells
 set nCnt to ListGetCount SexoutScannerListS
 set nIdx to 0
 if (nCnt > 0)
   Label whileCa
   if ((nIdx + 1) <= nCnt)
     set remoteSpell to ListGetNthForm SexoutScannerListS nIdx
     PrintToConsole "SEXSCAN DEBUG: Casting %n on player" remoteSpell
     player.cios remoteSpell
     set nIdx to nIdx + 1
     goto whileCa
   endif
 endif
end

Link to comment

The only issue I'm already seeing in my mind is that the list clearing may cause a problem if another mod inits (and adds itself) to me before my own init runs. I think it would be best if mods using this just do the "blind add" in their own loops to ensure they are added to the form. If not a blind add than something like this:

 

if (0 == MyFormList.IsInList SexoutScannerListN)
 ListAddForm SexoutScannerListN MyFormList
endif

 

Same thing for the spell.

 

I need to do the clear or else 'junk' added by a mod might remain in the list even if that mod is unloaded, which will cause this script to bomb out. I say might because I haven't tested. I don't know how well the reference cleaning stuff in the game works when it comes to formlist contents.

Link to comment

My trip got cancelled' date=' so I can do real modding today. Is this generic scanner good to go or do kinks need worked out before Tryouts use it?

[/quote']

 

It's only in the beta ESM right now, nothing is using it yet, but it should work. Hoping that while people are testing the beta, others can look over that script above and tell me how it looks. That's not the script you'll need, that's the one in sexout.esm, just fyi.

Link to comment

Loogie, Rapers is a mess so I'm shelving switching that right now. I'm working on modifying Kings Tryout to use the new scanner and will send it to you when it's done. Shouldn't take more than half an hour or so.

 

Edit: Gonna be a bit more than half an hour. I decided to document my work as I go to provide a tutorial for everyone when I'm done. Writing documentation is slower than writing code.. ;)

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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