Jump to content

How to make function do work when load game?


Recommended Posts

I make a mod to change npc wigs color,but when load game,wigs color change back.

I try event onload(),It don't work when load game until npc go to another cell.

someone can help.

Scriptname outfit__MainScript extends ReferenceAlias  
.............
ColorForm _hairColor = None
EVENT OnLoad()
	wait(0.25)
	UnStrip()
	HairColorSet
EndEVENT

Function HairColorSet()
	ActorRef = self.GetActorRef()
	ActorBase ActorB = ActorRef.GetActorBase()
	int red
	int green
	int blue
	if !HasIntValue(ActorRef, "Red0")
		int hp = ActorB.GetIndexOfHeadPartByType(3)
		string hpname = ActorB.GetNthHeadPart(hp).GetPartName()
		int HairTintColor = NiOverride.GetNodePropertyInt(ActorRef,false,hpname,7,-1)
		red = GetRed(HairTintColor)
		green = GetGreen(HairTintColor)
		blue = GetBlue(HairTintColor)
		SetIntValue(ActorRef,"Red0",Red)
		SetIntValue(ActorRef,"Green0",Green)
		SetIntValue(ActorRef,"Blue0",Blue)
	else
		red = GetIntValue(ActorRef,"Red0")
		green = GetIntValue(ActorRef,"Green0")
		blue = GetIntValue(ActorRef,"Blue0")
	endif
	red = red/2
	green = green/2
	blue = blue/2
	int color = 65536*red + 256*green + blue
	_hairColor = ActorB.GetHairColor()
	_hairColor.setcolor(color)
	ActorB.SetHairColor(_hairColor)
	ActorRef.QueueNiNodeUpdate()
EndFunction
.....................

ps:this mod work with skee.dll(racemenu)

Edited by pxd2050
Link to comment
Share on other sites

Looking at your code, pretty sure you've got SKSE involved somewhere. You can still use OnPlayerLoadGame to remotely trigger functions on the NPC aliases.

 

Here is a solution that will work (needs tested for compilation and function). It uses the following:

OnPlayerLoadGame

RegisterForSingleUpdate

OnUpdate

RegisterForModEvent -- requires SKSE

SendModEvent -- requires SKSE

 

Script on NPC aliases:

 

 

Scriptname outfit__MainScript extends ReferenceAlias  
.............
ColorForm _hairColor = None
EVENT OnInit()
  RegisterForSingleUpdate(0.25) ;short update registration -- allows bypassing that some quests trigger OnInit twice
EndEVENT
 
Event OnUpdate()
  RegisterForModEvent("pxd_LoadGame","pxdOnLoadGame")
EndEvent
 
Event pxdOnLoadGame(string eventName, string strArg, float numArg, Form sender)
  UnStrip()
  HairColorSet()
EndEvent
 
Function UnStrip()
; do stuff
EndFunction

Function HairColorSet()
; do stuff
EndFunction

 

 

 

 

The player alias script:

 

 

Scriptname SomePlayerAliasScript Extends ReferenceAlias
 
Event OnPlayerLoadGame()
  RegisterForSingleUpdate(5.0) ; wait to ensure the NPC aliases have setup and registered for the mod event
EndEvent

Event OnUpdate()
  SendModEvent("pxd_LoadGame")
EndEvent

 

 

 

 

Link to comment
Share on other sites

Looking at your code, pretty sure you've got SKSE involved somewhere. You can still use OnPlayerLoadGame to remotely trigger functions on the NPC aliases.

 

Here is a solution that will work (needs tested for compilation and function). It uses the following:

OnPlayerLoadGame

RegisterForSingleUpdate

OnUpdate

RegisterForModEvent -- requires SKSE

SendModEvent -- requires SKSE

 

Script on NPC aliases:

 

 

Scriptname outfit__MainScript extends ReferenceAlias  
.............
ColorForm _hairColor = None
EVENT OnInit()
  RegisterForSingleUpdate(0.25) ;short update registration -- allows bypassing that some quests trigger OnInit twice
EndEVENT
 
Event OnUpdate()
  RegisterForModEvent("pxd_LoadGame","pxdOnLoadGame")
EndEvent
 
Event pxdOnLoadGame(string eventName, string strArg, float numArg, Form sender)
  UnStrip()
  HairColorSet()
EndEvent
 
Function UnStrip()
; do stuff
EndFunction

Function HairColorSet()
; do stuff
EndFunction

 

 

 

 

The player alias script:

 

 

Scriptname SomePlayerAliasScript Extends ReferenceAlias
 
Event OnPlayerLoadGame()
  RegisterForSingleUpdate(5.0) ; wait to ensure the NPC aliases have setup and registered for the mod event
EndEvent

Event OnUpdate()
  SendModEvent("pxd_LoadGame")
EndEvent

 

 

 

 

thank you very much,I have solved this problem with onplayerloadgame (). But I find your method more useful. Next, I will try the method you provided.

:thumbsup: :thumbsup: :thumbsup:

Edited by pxd2050
Link to comment
Share on other sites

  • Recently Browsing   0 members

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