Jump to content

How to determine if player is victim using an IF statement


Recommended Posts

Posted

I am creating a mod that needs to detect if the player is the victim in a scene.

 

 

For example like this:

elseIf player == victim
Debug.MessageBox("Show a message here")
endIf

I think I need to use SexLab.HookVictim(argString) but I am not sure how to use it with the player.

Posted

You need an instance of the sslThreadController from the scene in question which you can get several ways.

 

If you started the animation from one of your scripts, you can get that either from saving it into a variable from StartThread() or QuickStart(), or if you used StartSex() you can take the number that function returns and use it with SexLab.GetController(the number it returned here).

 

If you are using hooks, http://git.loverslab.com/sexlab/framework/wikis/hook than you can use HookController() or HookVictim() if the victim is all you need.

 

Or ignoring all that, you can get the controller for the player with SexLab.GetPlayerController()

 

In any case, ignoring HookVictim(), once you have the controller you can just call the Controller.VictimRef property on it to get the victim, or to validate an actor as victim you can use Controller.IsVictim(actor)

 

If ALL you care about is the player being the victim, and your mod is meant to apply to any sex scene started by other mods, the easiest way to do this would be:

; // Register globally onto PlayerAnimationStart, which will only ever be sent when the player starts an animation
event OnInit()
    RegisterForModEvent("PlayerAnimationStart", "PlayerVictim")
endEvent

; // The callback event registered by RegisterForModEvent()
event PlayerVictim(string eventName, string argString, float argNum, form sender)
    ; // Use the HookController() function to get thread that triggered this event
    sslThreadController Thread = SexLab.HookController(argString)
    ; // Check the ThreadController for the player being the victim
    if Thread.IsVictim(Player)
    	; // Due stuff specific to the player being the victim here.
    endIf
endEvent
Posted

This is my code and it still doesn't seem to work can you see anything obvious that I am missing?

 

I am not trying to start a scene just see if the player is the victim in one that is running.

 

here is a sample:

Scriptname SLdesc extends quest  
SexLabFramework Property SexLab  Auto
Actor Property PlayerRef Auto

event OnInit()
RegisterForModEvent("OrgasmStart", "PlayerDesc")
endEvent

; // Our callback we registered onto the global event AnimationEnd
event PlayerDesc(string eventName, string argString, float argNum, form sender)

sslBaseAnimation animation = SexLab.HookAnimation(argString)
actor[] actorList = SexLab.HookActors(argString)

    ; // Use the HookController() function to get thread controller that triggered this event
sslThreadController controller = SexLab.HookController(argString)

   ; // FEMALE
if controller.HasPlayer && animation.HasTag("Vaginal") && !animation.HasTag("FF") && actorList[1].GetActorBase().GetSex() == 0 && PlayerRef.GetActorBase().GetSex() == 1

float random = Utility.RandomFloat(1.0, 1.3)

if random <= 1.1
Debug.Notification(actorList[1].GetLeveledActorBase().GetName() + " 1")

elseIf random >= 1.1 && random <=1.2
Debug.Notification(actorList[1].GetLeveledActorBase().GetName() + " 2")

elseIf random >= 1.2
Debug.Notification(actorList[1].GetLeveledActorBase().GetName() + " 3")

elseIf controller.IsVictim(PlayerRef)
Debug.Notification(actorList[1].GetLeveledActorBase().GetName() + " victim text.")

endIf

    endIf

endEvent

 

 

 

 

 

 

 

Posted

Your IsVictim() elseIf condition is never going to run, because one of the first random checks is always going be true. So IsVictim should be first, because that's the special case. I also see no reason for it to be floats; unless you have some use for the random number later.

 

This is how I'd write it, assuming what you're trying to do is display an orgasm messages for scenes with the player that is specific for the player being victim, or one of 3 random messages.

Scriptname SLdesc extends quest  
SexLabFramework Property SexLab  Auto
Actor Property PlayerRef Auto

event OnInit()
	RegisterForModEvent("PlayerOrgasmStart", "PlayerDesc")
	Debug.TraceAndBox("Test: PlayerOrgasmStart event registered!")
endEvent

event PlayerDesc(string eventName, string argString, float argNum, form sender)
	Debug.TraceAndBox("Test: PlayerDesc Event Triggered!")
	
	sslThreadController Thread = SexLab.HookController(argString)
	sslBaseAnimation Animation = Thread.Animation
	actor[] Positions = Thread.Positions

	if Animation.HasTag("Vaginal") && Animation.HasTag("MF") && SexLab.GetGender(Positions[0]) == 1 && SexLab.GetGender(Positions[1]) == 0
		int rand = Utility.RandomInt(0, 3)
		if Thread.IsVictim(PlayerRef)
			Debug.Notification(Positions[1].GetLeveledActorBase().GetName() + " victim text.")
		elseIf rand > 2
			Debug.Notification(Positions[1].GetLeveledActorBase().GetName() + " 3")
		elseIf rand > 1
			Debug.Notification(Positions[1].GetLeveledActorBase().GetName() + " 2")
		else
			Debug.Notification(Positions[1].GetLeveledActorBase().GetName() + " 1")
		endIf
	endIf

endEvent

For testing purposes I added some messagebox popups so you can tell easily if the code is triggering or not. You should see 1 when loading the game and 1 during player orgasm.

 

 

Note: PlayerOrgasmStart, and all other Player{EventName} were only added in SexLab 1.33 or so, if your using an older version or want it compatible with older versions you can just do OrgasmStart instead and add the Thread.HasPlayer condition check back. I in no way condone or support people using older versions though.

Posted

Your IsVictim() elseIf condition is never going to run, because one of the first random checks is always going be true. So IsVictim should be first, because that's the special case. I also see no reason for it to be floats; unless you have some use for the random number later.

 

This is how I'd write it, assuming what you're trying to do is display an orgasm messages for scenes with the player that is specific for the player being victim, or one of 3 random messages.

Scriptname SLdesc extends quest  
SexLabFramework Property SexLab  Auto
Actor Property PlayerRef Auto

event OnInit()
	RegisterForModEvent("PlayerOrgasmStart", "PlayerDesc")
	Debug.TraceAndBox("Test: PlayerOrgasmStart event registered!")
endEvent

event PlayerDesc(string eventName, string argString, float argNum, form sender)
	Debug.TraceAndBox("Test: PlayerDesc Event Triggered!")
	
	sslThreadController Thread = SexLab.HookController(argString)
	sslBaseAnimation Animation = Thread.Animation
	actor[] Positions = Thread.Positions

	if Animation.HasTag("Vaginal") && Animation.HasTag("MF") && SexLab.GetGender(Positions[0]) == 1 && SexLab.GetGender(Positions[1]) == 0
		int rand = Utility.RandomInt(0, 3)
		if Thread.IsVictim(PlayerRef)
			Debug.Notification(Positions[1].GetLeveledActorBase().GetName() + " victim text.")
		elseIf rand > 2
			Debug.Notification(Positions[1].GetLeveledActorBase().GetName() + " 3")
		elseIf rand > 1
			Debug.Notification(Positions[1].GetLeveledActorBase().GetName() + " 2")
		else
			Debug.Notification(Positions[1].GetLeveledActorBase().GetName() + " 1")
		endIf
	endIf

endEvent

For testing purposes I added some messagebox popups so you can tell easily if the code is triggering or not. You should see 1 when loading the game and 1 during player orgasm.

 

 

Note: PlayerOrgasmStart, and all other Player{EventName} were only added in SexLab 1.33 or so, if your using an older version or want it compatible with older versions you can just do OrgasmStart instead and add the Thread.HasPlayer condition check back. I in no way condone or support people using older versions though.

 

 

Thank you, you were correct my order was wrong. It's obvious now that you pointed it out.

Posted

I tested it with the ints and it kept giving me the same number all the time, but I will test it out again and see if it was just me making a mistake.

Archived

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

  • Recently Browsing   0 members

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