Jump to content

How to check if player/npc is nude or has nude suit (script)


trepleen

Recommended Posts

If you want to check if an actor, npc or player is nude/naked, I've made the following function.
 
It also checks for nude suits, by seeing if there is a keyword on the slot 32 (body/chest) armor that contains the substring "nude" or "naked".
If player has a nude suit equipped and it has the keyword "SHB_Nude_Body", the keyword nude would be found.
 
Please find ways to improve this script to make it as compatible as possible with other mods.
 
I use this script to check if player is nude/naked before they can take a bath.  I don't strip them automatically for reasons specific to the mod.
 
The following is Yurik's optimized version which is cleaner and easier to implement:
 

;player refalias
referencealias property refalias_player auto

;slot masks we'll check before the player can bathe
int Property kSlotMask30 = 0x00000001 AutoReadOnly ; HEAD
int Property kSlotMask32 = 0x00000004 AutoReadOnly ; BODY
int Property kSlotMask33 = 0x00000008 AutoReadOnly ; Hands
int Property kSlotMask37 = 0x00000080 AutoReadOnly ; Feet

;furniture or something
event onactivate(objectreference akactionref)

	;check if player is nude before doing anything, we'll also check for nude/naked suits
	;check slots 30 (helmet), 32 (body), 33 (gloves), 37 (boots)
	if (IsNaked(refalias_player.getactorreference())
		debug.notification("player is nude, start bath")
		;start bathtub logic
		;bathtublogic()	
	endif
endevent

bool function IsNaked(Actor akActor)
;start with helmet, does player have a helmet equipped?
if (!player().getwornform(kSlotMask30))
		;debug.notification("player is not equipping a helmet")

		;check for gloves
		if (!akActor.getwornform(kSlotMask33))
			;debug.notification("player is not equipping gloves")

			;check for boots
			if (!akActor.getwornform(kSlotMask37))
				;debug.notification("player is not equipping boots")

				;check for body/clothing
				if (!akActor.getwornform(kSlotMask32))
					return true
				else

					;get what's in slot 32
					form armorform = akActor.getwornform(kSlotMask32)

					int num = armorform.getnumkeywords()
					while (num > 0)
                                                num -= 1

						;check this keyword
						string keywordtocheck = armorform.getnthkeyword(num).getstring()

						;if we've found the word nude or naked in any keywords on this armor then we'll consider the play nude
						if (stringutil.find(keywordtocheck , "nude") > 0) || (stringutil.find(keywordtocheck , "naked") > 0) 
							debug.notification("player is nude but with nude suit, start bath")
							return true
						endif						
					endwhile
				endif
			endif
		endif
	endif
        return false
endfunction

 The following is my previous code, for learning purposes compare mine to Yurick's optimized version.

 

;player refalias
referencealias property refalias_player auto

;slot masks we'll check before the player can bathe
int Property kSlotMask30 = 0x00000001 AutoReadOnly ; HEAD
int Property kSlotMask32 = 0x00000004 AutoReadOnly ; BODY
int Property kSlotMask33 = 0x00000008 AutoReadOnly ; Hands
int Property kSlotMask37 = 0x00000080 AutoReadOnly ; Feet

;furniture or something
event onactivate(objectreference akactionref)

	;check if player is nude before doing anything, we'll also check for nude/naked suits
	;check slots 30 (helmet), 32 (body), 33 (gloves), 37 (boots)

	;start with helmet, does player have a helmet equipped?
	if (refalias_player.getactorref().getwornform(kSlotMask30 ) == none)
		;debug.notification("player is not equipping a helmet")

		;check for gloves
		if (refalias_player.getactorref().getwornform(kSlotMask33) == none)
			;debug.notification("player is not equipping gloves")

			;check for boots
			if (refalias_player.getactorref().getwornform(kSlotMask37) == none)
				;debug.notification("player is not equipping boots")

				;check for body/clothing
				if (refalias_player.getactorref().getwornform(kSlotMask32) == none)

					debug.notification("player is nude, start bath")

					;ENTER ANY CODE YOU WANT HERE
					;yourfunction() yourcode

				else

					;get what's in slot 32
					form armorform = refalias_player.getactorref().getwornform(kSlotMask32)

					int count = armorform.getnumkeywords()
					int index
					while (index < count)

						;check this keyword
						string keywordtocheck = armorform.getnthkeyword(index).getstring()
					
						;does the keyword have nude anywhere in its name?
						int keyword_nude_find_index = stringutil.find(keywordtocheck , "nude")
						;does the keyword have naked anywhere in its name?
						int keyword_naked_find_index = stringutil.find(keywordtocheck , "naked")

						;if we've found the word nude or naked in any keywords on this armor then we'll consider the play nude
						if (keyword_naked_find_index > 0) || (keyword_nude_find_index > 0) 
							debug.notification("player is nude but with nude suit, start bath")
						endif

						;next keyword
						index += 1
					endwhile
				endif
			endif
		endif
	endif
endevent

;thanks to darkconsole for his help

 

 

Link to comment

OK, you asked for it:

1. first, you missed the 'bathtublogic()' in the 'check slot32 keywords' branch :exclamation:

2. the while cycle does not break when it finds an item with keyword (so if there's several 'nude/naked' keywords, cycle block will be executed for each of them)

3. the 'keyword_naked_find_index > 0) || (keyword_nude_find_index > 0' condition can be shortcutted

4. refalias_player.getactorref() copy-pasting is not very good

5. also, I'd encapsulate the IsNude checking logic inside some function (20% more SOLID :D)

Here:

 

;player refalias
referencealias property refalias_player auto

;slot masks we'll check before the player can bathe
int Property kSlotMask30 = 0x00000001 AutoReadOnly ; HEAD
int Property kSlotMask32 = 0x00000004 AutoReadOnly ; BODY
int Property kSlotMask33 = 0x00000008 AutoReadOnly ; Hands
int Property kSlotMask37 = 0x00000080 AutoReadOnly ; Feet

;furniture or something
event onactivate(objectreference akactionref)

	;check if player is nude before doing anything, we'll also check for nude/naked suits
	;check slots 30 (helmet), 32 (body), 33 (gloves), 37 (boots)
	if (IsNaked(refalias_player.getactorreference())
		debug.notification("player is nude, start bath")
		;start bathtub logic
		;bathtublogic()	
	endif
endevent

bool function IsNaked(Actor akActor)
;start with helmet, does player have a helmet equipped?
if (!akActor.getwornform(kSlotMask30))
		;debug.notification("player is not equipping a helmet")

		;check for gloves
		if (!akActor.getwornform(kSlotMask33))
			;debug.notification("player is not equipping gloves")

			;check for boots
			if (!akActor.getwornform(kSlotMask37))
				;debug.notification("player is not equipping boots")

				;check for body/clothing
				if (!akActor.getwornform(kSlotMask32))
					return true
				else

					;get what's in slot 32
					form armorform = akActor.getwornform(kSlotMask32)

					int num = armorform.getnumkeywords()
					while (num > 0)
                                                num -= 1

						;check this keyword
						string keywordtocheck = armorform.getnthkeyword(num).getstring()

						;if we've found the word nude or naked in any keywords on this armor then we'll consider the play nude
						if (stringutil.find(keywordtocheck , "nude") > 0) || (stringutil.find(keywordtocheck , "naked") > 0) 
							debug.notification("player is nude but with nude suit, start bath")
							return true
						endif						
					endwhile
				endif
			endif
		endif
	endif
        return false
endfunction

 

 

Link to comment

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

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

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. For more information, see our Privacy Policy & Terms of Use