Jump to content

Making my mod SexLab independent


qotsafan

Recommended Posts

Posted

Hey all,

 

I thought, since I started my mod, that my mod would be SexLab independent (since it's only indirectly related to SexLab).

Since I now wanted to set up a new test profile for my mod, I ran it without SexLab for the first time and had to find out, that it's not independent.

 

The code that is dependent on SexLab is the following:

Int Function GetGender(Actor kActor, int gender = -1) Global
	
	if (StorageUtil.HasIntValue(kActor, "slif_gender"))
		return StorageUtil.GetIntValue(kActor, "slif_gender")
	endIf
	
	if (gender == -1)
		
		if (Game.GetModbyName("SexLab.esm") != 255)
			SexLabFramework SexLab = Game.GetFormFromFile(0xD62,"SexLab.esm") as SexLabFramework
			if (SexLab)
				int sexlab_gender = SexLab.GetGender(kActor)
				if (sexlab_gender != -1)
					if (sexlab_gender == 0)
						return StorageUtil.SetIntValue(kActor, "slif_gender", 0)
					elseIf (sexlab_gender == 1)
						return StorageUtil.SetIntValue(kActor, "slif_gender", 1)
					elseIf (sexlab_gender == 2)
						return StorageUtil.SetIntValue(kActor, "slif_gender", 5)
					elseIf (sexlab_gender == 3)
						return StorageUtil.SetIntValue(kActor, "slif_gender", 6)
					endIf
				endIf
			endIf
		endIf
		
	endIf
	
	if (gender >= 0 && gender <= 6)
		return StorageUtil.SetIntValue(kActor, "slif_gender", gender)
	endIf
	
	return StorageUtil.SetIntValue(kActor, "slif_gender", kActor.GetLeveledActorBase().GetSex())
	
EndFunction
This part in particular:

SexLab.GetGender(kActor)
I'm getting the following error message in my Papyrus log:

Error: Unable to link types associated with static function "GetGender" on object "slif_main".
One way to resolve this would be to make an extra compatibility script, with empty functions, if SexLab is not installed, like Milk Mod Economy does it for example, but I would like to ask, if there may be a better solution?

 

Regards qotsafan

Posted

The correct check is:

 

if Game.GetModbyName("SexLab.esm") != 255 && Game.GetModbyName("SexLab.esm") != -1

Posted

The correct check is:

 

if Game.GetModbyName("SexLab.esm") != 255 && Game.GetModbyName("SexLab.esm") != -1

Sadly that doesn't work either.

The problem is not that the function is called, it's rather, that the function doesn't exist and therefore throws the error.

The default of Game.GetModbyName() is 255, if the plug-in is not found, so it's either 0-254 or 255, if it's not found.

I guess there is no way around, other than to make a compatibility script, it's not the end of the world though :)

Thanks for your help though :)

Posted

If you want just to compile it, then just have the sources of SexLab in the source folder.

And DO NOT fill the properties (using SexLab stuff.)

 

I do it all the time.

Posted

If you want just to compile it, then just have the sources of SexLab in the source folder.

And DO NOT fill the properties (using SexLab stuff.)

 

I do it all the time.

No, what I meant was, that if the script uses a function from SexLab and you run the game without SexLab installed, it will throw an error and the function doesn't work at all.

 

So I have to find a workaround to make this work.

 

I will check via fomod, if SexLab is installed and will install the following script, if it is installed:

Scriptname SLIF_SexLab_Script

Int Function GetGender(Actor kActor, int gender) Global
	
	if (gender == -1)
		
		if (Game.GetModbyName("SexLab.esm") != 255)
			SexLabFramework SexLab = Game.GetFormFromFile(0xD62,"SexLab.esm") as SexLabFramework
			if (SexLab)
				int sexlab_gender = SexLab.GetGender(kActor)
				if (sexlab_gender != -1)
					if (sexlab_gender == 0)
						return StorageUtil.SetIntValue(kActor, "slif_gender", 0)
					elseIf (sexlab_gender == 1)
						return StorageUtil.SetIntValue(kActor, "slif_gender", 1)
					elseIf (sexlab_gender == 2)
						return StorageUtil.SetIntValue(kActor, "slif_gender", 5)
					elseIf (sexlab_gender == 3)
						return StorageUtil.SetIntValue(kActor, "slif_gender", 6)
					endIf
				endIf
			endIf
		endIf
		
	endIf
	
	return gender
EndFunction
(Game.GetModbyName("SexLab.esm") != 255 kind of irrelevant with this aproach)

 

If SexLab is not installed, the fomod would install the following script:

Scriptname SLIF_SexLab_Script

Int Function GetGender(Actor kActor, int gender) Global
	return gender
EndFunction
I will then call the function from the compatibility script like this:

Int Function GetGender(Actor kActor, int gender = -1) Global
	
	if (StorageUtil.HasIntValue(kActor, "slif_gender"))
		return StorageUtil.GetIntValue(kActor, "slif_gender")
	endIf
	
	gender = SLIF_SexLab_Script.GetGender(kActor, gender)
	
	if (gender >= 0 && gender <= 6)
		return StorageUtil.SetIntValue(kActor, "slif_gender", gender)
	endIf
	
	return StorageUtil.SetIntValue(kActor, "slif_gender", kActor.GetLeveledActorBase().GetSex())
	
EndFunction
not perfect, but it will have to do.
Posted

I don't think this is a good solution.

Because if you do, you still need to put a hard dependency on SL. So the mod will not start if SexLab is missing.

 

You should have an init quest (the main quest?) somewhere.

At game start and at game reload, check only ONCE if SexLab is loaded.

And in case get it with Game.getFormFromFile

 

Put the result in a property (but is should not be sexlab specific type)

And then in the other scripts just reference this property, and check if it is none before executing.

 

You get an error in the VM if and ONLY if the line is actually executed.

All calls are done with dynamic matching and never with static linking.

 

So also if the function does not exists, you will not get an error in case the mod is not loaded.

Posted

I don't think this is a good solution.

Because if you do, you still need to put a hard dependency on SL. So the mod will not start if SexLab is missing.

 

You should have an init quest (the main quest?) somewhere.

At game start and at game reload, check only ONCE if SexLab is loaded.

And in case get it with Game.getFormFromFile

 

Put the result in a property (but is should not be sexlab specific type)

And then in the other scripts just reference this property, and check if it is none before executing.

 

You get an error in the VM if and ONLY if the line is actually executed.

All calls are done with dynamic matching and never with static linking.

 

So also if the function does not exists, you will not get an error in case the mod is not loaded.

Hmm, that sounds like a good idea, so basically like this?:

Form Property SexLab Auto
if (Game.GetModbyName("SexLab.esm") != 255)
	SexLab = Game.GetFormFromFile(0xD62,"SexLab.esm")
endIf
if (SexLab)
	gender = (SexLab as SexLabFramework).GetGender(kActor)
endIf
Posted

Hmm, that sounds like a good idea, so basically like this?:

Form Property SexLab Auto
if (Game.GetModbyName("SexLab.esm") != 255)
SexLab = Game.GetFormFromFile(0xD62,"SexLab.esm")
endIf
if (SexLab)
gender = (SexLab as SexLabFramework).GetGender(kActor)
endIf

 

Sort of.

 

Scriptname mymainquest extends Quest

Form property SexLabRef Auto

Function doInit()
  if Game.GetModbyName("SexLab.esm") != 255 && Game.GetModbyName("SexLab.esm") != -1
    SexLabRef = Game.GetFormFromFile(0xD62,"SexLab.esm")
  endIf
endFunction

-------------------------------------------

Scriptname anotherscript extends whatever

mymainquest Property myQuestName Auto

Function blah(Actor kActor)
  if myQuestName.SexLabRef
    gender = (SexLabRef as SexLabFramework).GetGender(kActor)
  else
    gender = kActor.getLeveldActorBase().getSex()
  endIf
endFunction
 
Posted

- snip -

Yes, this works, I don't even need a property, this will do:

Form SexLab = none
if (Game.GetModbyName("SexLab.esm") != 255)
	SexLab = Game.GetFormFromFile(0xD62,"SexLab.esm")
endIf
if (SexLab)
	int sexlab_gender = (SexLab as SexLabFramework).GetGender(kActor)
	if (sexlab_gender != -1)
		if (sexlab_gender == 0)
			gender = 0
		elseIf (sexlab_gender == 1)
			gender = 1
		elseIf (sexlab_gender == 2)
			gender = 5
		elseIf (sexlab_gender == 3)
			gender = 6
		endIf
	endIf
endIf
Edit: no, sadly this doesn't work, I will have to continue with my previous idea :(

Archived

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

  • Recently Browsing   0 members

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