Script doesn't work for Actor

Post » Thu Jun 21, 2012 2:30 am

This script:
Scriptname DivineGifts_LevelingStats_Script extends ObjectReferenceActor Property ActorOwningScript  AutoInt Property StartingLevel_of_ScriptOwner  AutoInt Property level_old  AutoInt Property level_new  AutoFloat Property Weight_of_Health_from_Class  AutoFloat Property Weight_of_Magicka_from_Class  AutoFloat Property Weight_of_Stamina_from_Class  AutoFloat Property Weight_of_OneHanded_from_Class  AutoFloat Property Weight_of_TwoHanded_from_Class  AutoFloat Property Weight_of_Archery_from_Class  AutoFloat Property Weight_of_Block_from_Class  AutoFloat Property Weight_of_Smithing_from_Class  AutoFloat Property Weight_of_HeavyArmor_from_Class  AutoFloat Property Weight_of_LightArmor_from_Class  AutoFloat Property Weight_of_Pickpocket_from_Class  AutoFloat Property Weight_of_Lockpicking_from_Class  AutoFloat Property Weight_of_Sneak_from_Class  AutoFloat Property Weight_of_Alchemy_from_Class  AutoFloat Property Weight_of_Speech_from_Class  AutoFloat Property Weight_of_Alteration_from_Class  AutoFloat Property Weight_of_Conjuration_from_Class  AutoFloat Property Weight_of_Destruction_from_Class  AutoFloat Property Weight_of_Illusion_from_Class  AutoFloat Property Weight_of_Restoration_from_Class  AutoFloat Property Weight_of_Enchanting_from_Class  AutoFloat Property Start_Health  AutoFloat Property Start_Magicka  AutoFloat Property Start_Stamina  AutoFloat Property Start_OneHanded  AutoFloat Property Start_TwoHanded  AutoFloat Property Start_Archery  AutoFloat Property Start_Block  AutoFloat Property Start_Smithing  AutoFloat Property Start_HeavyArmor  AutoFloat Property Start_LightArmor  AutoFloat Property Start_Pickpocket  AutoFloat Property Start_Lockpicking  AutoFloat Property Start_Sneak  AutoFloat Property Start_Alchemy  AutoFloat Property Start_Speech  AutoFloat Property Start_Alteration  AutoFloat Property Start_Conjuration  AutoFloat Property Start_Destruction  AutoFloat Property Start_Illusion  AutoFloat Property Start_Restoration  AutoFloat Property Start_Enchanting  AutoFloat HealthMagickaStamina_Points_per_level = 10.0Float Skill_Points_per_level = 8.0Float Sum_of_weights_of_HMS_Points = 0.0Float Sum_of_weights_of_Skill_Points = 0.0Float NPCs_Health_Bonus_per_level = 5.0;Int level_old = 1;Int level_new = 1Int level_difference = 0Event OnInit()RegisterForUpdate(10) ;update co 10 sekund czasu rzeczywistegoendEventEvent OnUpdate();UpdateStats()CheckANDSetStats();Debug.Notification(ActorOwningScript.GetBaseActorValue("Health"));Debug.Notification("OK")endEventFunction SetDefaultStats()If(!Start_Health)  Start_Health = 50.0EndIfIf(!Start_Magicka)  Start_Magicka = 50.0EndIfIf(!Start_Stamina)  Start_Stamina = 50.0EndIfIf(!Start_OneHanded)  Start_OneHanded = 15.0EndIfIf(!Start_TwoHanded)  Start_TwoHanded = 15.0EndIfIf(!Start_Archery)  Start_Archery = 15.0EndIfIf(!Start_Block)  Start_Block = 15.0EndIfIf(!Start_Smithing)  Start_Smithing = 15.0EndIfIf(!Start_HeavyArmor)  Start_HeavyArmor = 15.0EndIfIf(!Start_LightArmor)  Start_LightArmor = 15.0EndIfIf(!Start_Pickpocket)  Start_Pickpocket = 15.0EndIfIf(!Start_Lockpicking)  Start_Lockpicking = 15.0EndIfIf(!Start_Sneak)  Start_Sneak = 15.0EndIfIf(!Start_Alchemy)  Start_Alchemy = 15.0EndIfIf(!Start_Speech)  Start_Speech = 15.0EndIfIf(!Start_Alteration)  Start_Alteration = 15.0EndIfIf(!Start_Conjuration)  Start_Conjuration = 15.0EndIfIf(!Start_Destruction)  Start_Destruction = 15.0EndIfIf(!Start_Illusion)  Start_Illusion = 15.0EndIfIf(!Start_Restoration)  Start_Restoration = 15.0EndIfIf(!Start_Enchanting)  Start_Enchanting = 15.0EndIfendFunctionFunction CheckANDSetStats()SetDefaultStats()Float Sum_of_weights_of_HMS_Points2 = 0.0Float Sum_of_weights_of_Skill_Points2 = 0.0Float CurrentLevel0 = ActorOwningScript.GetLevel() as floatFloat CurrentLevel = CurrentLevel0 - 1.0Sum_of_weights_of_HMS_Points2 = Weight_of_Health_from_Class + Weight_of_Magicka_from_Class + Weight_of_Stamina_from_ClassSum_of_weights_of_Skill_Points2 = Weight_of_OneHanded_from_Class + Weight_of_TwoHanded_from_Class + Weight_of_Archery_from_Class + Weight_of_Block_from_Class + Weight_of_Smithing_from_Class + Weight_of_HeavyArmor_from_Class + Weight_of_LightArmor_from_Class + Weight_of_Pickpocket_from_Class + Weight_of_Lockpicking_from_Class + Weight_of_Sneak_from_Class + Weight_of_Alchemy_from_Class + Weight_of_Speech_from_Class + Weight_of_Alteration_from_Class + Weight_of_Conjuration_from_Class + Weight_of_Destruction_from_Class + Weight_of_Illusion_from_Class + Weight_of_Restoration_from_Class + Weight_of_Enchanting_from_ClassFloat New_Health = Start_Health + CurrentLevel  * (NPCs_Health_Bonus_per_level + (Weight_of_Health_from_Class / Sum_of_weights_of_HMS_Points2) * HealthMagickaStamina_Points_per_level)Float New_Magicka = Start_Magicka + CurrentLevel * (Weight_of_Magicka_from_Class / Sum_of_weights_of_HMS_Points2) * HealthMagickaStamina_Points_per_levelFloat New_Stamina = Start_Stamina + CurrentLevel * (Weight_of_Stamina_from_Class / Sum_of_weights_of_HMS_Points2) * HealthMagickaStamina_Points_per_levelFloat New_OneHanded = Start_OneHanded + CurrentLevel * (Weight_of_OneHanded_from_Class / Sum_of_weights_of_Skill_Points2) * Skill_Points_per_levelFloat New_TwoHanded = Start_TwoHanded + CurrentLevel * (Weight_of_TwoHanded_from_Class / Sum_of_weights_of_Skill_Points2) * Skill_Points_per_levelFloat New_Archery = Start_Archery + CurrentLevel * (Weight_of_Archery_from_Class / Sum_of_weights_of_Skill_Points2) * Skill_Points_per_levelFloat New_Block = Start_Block + CurrentLevel * (Weight_of_Block_from_Class / Sum_of_weights_of_Skill_Points2) * Skill_Points_per_levelFloat New_Smithing = Start_Smithing + CurrentLevel * (Weight_of_Smithing_from_Class / Sum_of_weights_of_Skill_Points2) * Skill_Points_per_levelFloat New_HeavyArmor = Start_HeavyArmor + CurrentLevel * (Weight_of_HeavyArmor_from_Class / Sum_of_weights_of_Skill_Points2) * Skill_Points_per_levelFloat New_LightArmor = Start_LightArmor + CurrentLevel * (Weight_of_LightArmor_from_Class / Sum_of_weights_of_Skill_Points2) * Skill_Points_per_levelFloat New_Pickpocket = Start_Pickpocket + CurrentLevel * (Weight_of_Pickpocket_from_Class / Sum_of_weights_of_Skill_Points2) * Skill_Points_per_levelFloat New_Lockpicking = Start_Lockpicking + CurrentLevel * (Weight_of_Lockpicking_from_Class / Sum_of_weights_of_Skill_Points2) * Skill_Points_per_levelFloat New_Sneak = Start_Sneak + CurrentLevel * (Weight_of_Sneak_from_Class / Sum_of_weights_of_Skill_Points2) * Skill_Points_per_levelFloat New_Alchemy = Start_Alchemy + CurrentLevel * (Weight_of_Alchemy_from_Class / Sum_of_weights_of_Skill_Points2) * Skill_Points_per_levelFloat New_Speech = Start_Speech + CurrentLevel * (Weight_of_Speech_from_Class / Sum_of_weights_of_Skill_Points2) * Skill_Points_per_levelFloat New_Alteration = Start_Alteration + CurrentLevel * (Weight_of_Alteration_from_Class / Sum_of_weights_of_Skill_Points2) * Skill_Points_per_levelFloat New_Conjuration = Start_Conjuration + CurrentLevel * (Weight_of_Conjuration_from_Class / Sum_of_weights_of_Skill_Points2) * Skill_Points_per_levelFloat New_Destruction = Start_Destruction + CurrentLevel * (Weight_of_Destruction_from_Class / Sum_of_weights_of_Skill_Points2) * Skill_Points_per_levelFloat New_Illusion = Start_Illusion + CurrentLevel * (Weight_of_Illusion_from_Class / Sum_of_weights_of_Skill_Points2) * Skill_Points_per_levelFloat New_Restoration = Start_Restoration + CurrentLevel * (Weight_of_Restoration_from_Class / Sum_of_weights_of_Skill_Points2) * Skill_Points_per_levelFloat New_Enchanting = Start_Enchanting + CurrentLevel * (Weight_of_Enchanting_from_Class / Sum_of_weights_of_Skill_Points2) * Skill_Points_per_level;If (ActorOwningScript.GetBaseActorValue("Health") < New_Health)  ActorOwningScript.SetActorValue("Health",  New_Health);EndIf;If (ActorOwningScript.GetBaseActorValue("Magicka") < New_Magicka)  ActorOwningScript.SetActorValue("Magicka", New_Magicka);EndIf;If (ActorOwningScript.GetBaseActorValue("Stamina") < New_Stamina)  ActorOwningScript.SetActorValue("Stamina", New_Stamina);EndIf;If (ActorOwningScript.GetBaseActorValue("OneHanded") < New_OneHanded)  ActorOwningScript.SetActorValue("OneHanded", New_OneHanded);EndIf;If (ActorOwningScript.GetBaseActorValue("TwoHanded") < New_TwoHanded)  ActorOwningScript.SetActorValue("TwoHanded", New_TwoHanded);EndIf;If (ActorOwningScript.GetBaseActorValue("Marksman") < New_Archery)  ActorOwningScript.SetActorValue("Marksman", New_Archery);EndIf;If (ActorOwningScript.GetBaseActorValue("Block") < New_Block)  ActorOwningScript.SetActorValue("Block", New_Block);EndIf;If (ActorOwningScript.GetBaseActorValue("Smithing") < New_Smithing)  ActorOwningScript.SetActorValue("Smithing", New_Smithing);EndIf;If (ActorOwningScript.GetBaseActorValue("HeavyArmor") < New_HeavyArmor)  ActorOwningScript.SetActorValue("HeavyArmor", New_HeavyArmor);EndIf;If (ActorOwningScript.GetBaseActorValue("LightArmor") < New_LightArmor)  ActorOwningScript.SetActorValue("LightArmor", New_LightArmor);EndIf;If (ActorOwningScript.GetBaseActorValue("Pickpocket") < New_Pickpocket)  ActorOwningScript.SetActorValue("Pickpocket", New_Pickpocket);EndIf;If (ActorOwningScript.GetBaseActorValue("Lockpicking") < New_Lockpicking)  ActorOwningScript.SetActorValue("Lockpicking", New_Lockpicking);EndIf;If (ActorOwningScript.GetBaseActorValue("Sneak") < New_Sneak)  ActorOwningScript.SetActorValue("Sneak", New_Sneak);EndIf;If (ActorOwningScript.GetBaseActorValue("Alchemy") < New_Alchemy)  ActorOwningScript.SetActorValue("Alchemy", New_Alchemy);EndIf;If (ActorOwningScript.GetBaseActorValue("Speechcraft") < New_Speech)  ActorOwningScript.SetActorValue("Speechcraft", New_Speech);EndIf;If (ActorOwningScript.GetBaseActorValue("Alteration") < New_Alteration)  ActorOwningScript.SetActorValue("Alteration", New_Alteration);EndIf;If (ActorOwningScript.GetBaseActorValue("Conjuration") < New_Conjuration)  ActorOwningScript.SetActorValue("Conjuration", New_Conjuration);EndIf;If (ActorOwningScript.GetBaseActorValue("Destruction") < New_Destruction)  ActorOwningScript.SetActorValue("Destruction", New_Destruction);EndIf;If (ActorOwningScript.GetBaseActorValue("Illusion") < New_Illusion)  ActorOwningScript.SetActorValue("Illusion", New_Illusion);EndIf;If (ActorOwningScript.GetBaseActorValue("Restoration") < New_Restoration)  ActorOwningScript.SetActorValue("Restoration", New_Restoration);EndIf;If (ActorOwningScript.GetBaseActorValue("Enchanting") < New_Enchanting)  ActorOwningScript.SetActorValue("Enchanting", New_Enchanting);EndIfActorOwningScript.Disable()ActorOwningScript.Enable()endFunction

There works only first update after 10s. Next updates don't work - human Actor is not disabled and reenabled.
This script is also attached to 4 other animal actors with different Properties and there it works. If I delete script from animal actors, script in human actor works then correct, but I must have scripts in animal actors too.
What is problem? Please help.
This game is the buggiest game which I have, is almost not playable.
User avatar
Eve Booker
 
Posts: 3300
Joined: Thu Jul 20, 2006 7:53 pm

Post » Wed Jun 20, 2012 9:51 pm

I'm wondering why you are using disable, then enable again ?

Also, it's interesting that the script works on the actor, only if the script is NOT running on the animals at the time. Are sure ActorOwningScript is set correctly on each script?

Question: Is the script still updating after the first 10 seconds?
--- if you put
Debug.Notification("OK")

back in the update function, do you see it every 10 seconds?
User avatar
Esther Fernandez
 
Posts: 3415
Joined: Wed Sep 27, 2006 11:52 am

Post » Wed Jun 20, 2012 7:27 pm

Just wondering, did you try to put this script on the player and 4 animals? Then tried it on some actor not the player and no animals?
User avatar
Robert Bindley
 
Posts: 3474
Joined: Fri Aug 03, 2007 5:31 pm

Post » Thu Jun 21, 2012 12:50 am

I'm wondering why you are using disable, then enable again ? Also, it's interesting that the script works on the actor, only if the script is NOT running on the animals at the time. Are sure ActorOwningScript is set correctly on each script? Question: Is the script still updating after the first 10 seconds? --- if you put Debug.Notification("OK") back in the update function, do you see it every 10 seconds?

I want to see script working (Disable()->Enable()). In final script I won't use Disable() and Enable().
ActorOwningScript is set correctly.
Script for animals works correctly, for Redguard doesn't.
Debug.Notification("OK") without ";" appears only for animals, for human only once.

Just wondering, did you try to put this script on the player and 4 animals? Then tried it on some actor not the player and no animals?
1. Doesn't work for the player, works for animals.
2. Yesterday worked, today doesn't work for human (even if animals have no script).



I didn't change anything, but this script today doesn't work (even once) for human, only for animals.



EDIT 10:49AM 2012-04-09:
If i give this script as quest script and I call it at the end of topic, it works for human correctly. But I prefer to have it in actor, not in quest.
User avatar
Shirley BEltran
 
Posts: 3450
Joined: Wed Jul 26, 2006 4:14 pm

Post » Wed Jun 20, 2012 9:54 pm

Just put the script on 4 animals and the human but do nothing in the update other than print a message displaying the ObjectReference. If it works, then your problem is in the function, if not, the problem is elsewhere. Better to rule out the sources as early as possible. Those Disable() Enable() calls at the end of your function look a little suspicious to me.
User avatar
Isabel Ruiz
 
Posts: 3447
Joined: Sat Nov 04, 2006 4:39 am

Post » Wed Jun 20, 2012 4:41 pm

Just put the script on 4 animals and the human but do nothing in the update other than print a message displaying the ObjectReference. If it works, then your problem is in the function, if not, the problem is elsewhere. Better to rule out the sources as early as possible. Those Disable() Enable() calls at the end of your function look a little suspicious to me.

Still this same problem - script works correctly for my animals, but for human only once.
User avatar
Juan Suarez
 
Posts: 3395
Joined: Sun Nov 25, 2007 4:09 am

Post » Wed Jun 20, 2012 7:38 pm

First, I'd replace RegisterForUpdate with RegisterForSingleUpdate(10) and put another one at the END of the OnUpdate event. As it is, if all the code in your functions takes longer than 10 seconds to run (Probably will) you will wind up with multiple OnUpdates threading and interfering with each other.

I'm assuming the Disable() Enable() thing is to force the new values to "take hold?" But they'd only change when the character levels up, right? so you shouldn't have to do it very often, if at all.

Also ActorOwningScript is unnecessary. Replace it with "(Self as Actor)" in all cases.
User avatar
Madeleine Rose Walsh
 
Posts: 3425
Joined: Wed Oct 04, 2006 2:07 am

Post » Wed Jun 20, 2012 3:33 pm

I tested your script on Lydia, and it worked for me. I changed it to 'extends Actor' and used arrays instead of all those properties, but it shouldn't have made a difference.

Spoiler
Scriptname DivineGifts_LevelingStats_Script extends Actor{Script to auto-adjust the stats/skills of the actor carrying it};;;;;;;;;;;;;;;;;; Properties ;;;;;;;;;;;;;;;;;;String[] Property Stats Auto{Array of the stat names (Health, Magicka, Stamina)}String[] Property Skills Auto{Array of the skill names (Alchemy, Alteration, etc.)}Float[] Property StatWeights Auto{Array of the weights for the stats}Float[] Property SkillWeights Auto{Array of the weights for the skills}Float[] Property StartStats Auto{Array of the starting values for stats}Float[] Property StartSkills Auto{Array of the starting values of the skills}Int Property SkillMin = 1 Auto{The minumum for a skill level}Int Property SkillMax = 100 Auto{The maximum for a skill level}Int Property StatIncreasesPerLevel Auto Hidden{The total Health + Magicka + Stamina gain per level}Int Property SkillIncreasesPerLevel Auto Hidden{The total skill points gained per level}Float Property StatWeightsTotal Auto Hidden{The total of the stat weights}Float Property SkillWeightsTotal Auto Hidden{The total of the stat weights}Int Property Level_Current Auto Hidden{Used to track changes in the actor's level}Int Property StartLevel Auto{The actor's starting level};;;;;;;;;;;;;; Events ;;;;;;;;;;;;;;Event OnInit()	Debug.Notification("OnInit running.")	int index = 0	while (index < StatWeights.Length)		StatWeightsTotal += StatWeights[index]		index += 1	endwhile	index = 0	while (index < SkillWeights.Length)		SkillWeightsTotal += SkillWeights[index]		index += 1	endwhile	Level_Current = StartLevel	RegisterForSingleUpdate(10) ;use single update loop to prevent log spam if mod removed	Debug.Notification("OnInit completed.")endEventEvent OnUpdate()	Debug.Notification("OnUpdate running.")	if !(GetLevel() == Level_Current)		Level_Current = GetLevel()		UpdateActorValues()	endif	RegisterForSingleUpdate(10)	Debug.Notification("OnUpdate completed.")endEvent;;;;;;;;;;;;;;;;; Functions ;;;;;;;;;;;;;;;;;;/ Function SetDefaultStats()		;This whole function is unnecessary, set them in the propertiesEndFunction /;Function UpdateActorValues()	Debug.Notification("Updating Stats and Skills.")	StatIncreasesPerLevel = Game.GetGameSettingInt("iAVDHMSLevelUp")	SkillIncreasesPerLevel = Game.GetGameSettingInt("iAVDSkillsLevelUp")	int ModLevel = Level_Current - StartLevel	float NewValue = http://forums.bethsoft.com/topic/1365138-script-doesnt-work-for-actor/0.0	int index = 0	while (index < Stats.Length)		NewValue = StartStats[index] + ModLevel * StatWeights[index] / StatWeightsTotal * StatIncreasesPerLevel		SetActorValue(Stats[index], NewValue)		index += 1	endwhile	index = 0	while (index < Skills.Length)		NewValue = StartSkills[index] + ModLevel * SkillWeights[index] / SkillWeightsTotal * SkillIncreasesPerLevel		if (NewValue < SkillMin)			NewValue = SkillMin		elseif (NewValue> SkillMax)			NewValue = http://forums.bethsoft.com/topic/1365138-script-doesnt-work-for-actor/SkillMax		endif		SetActorValue(Skills[index], NewValue)		index += 1	endwhile	Debug.Notification("Stats and skills have been updated.")EndFunction
User avatar
FirDaus LOVe farhana
 
Posts: 3369
Joined: Thu Sep 13, 2007 3:42 am

Post » Wed Jun 20, 2012 8:52 pm

I'm assuming the Disable() Enable() thing is to force the new values to "take hold?" But they'd only change when the character levels up, right? so you shouldn't have to do it very often, if at all.
Disable() Enable() - I want to see that script is working - Notification prints up to 4 messages at once, Disable() and Enable() have no this restriction.

First, I'd replace RegisterForUpdate with RegisterForSingleUpdate(10) and put another one at the END of the OnUpdate event. As it is, if all the code in your functions takes longer than 10 seconds to run (Probably will) you will wind up with multiple OnUpdates threading and interfering with each other.

Also ActorOwningScript is unnecessary. Replace it with "(Self as Actor)" in all cases.

It is better - for human script works twice, so there is still some problem.



EDIT:
RandomNoob - I'll check it.


EDIT:
RandomNoob
Still nothing. Even this fragment doesn't work for human more than twice:
Event OnInit()RegisterForSingleUpdate(10)endEventEvent OnUpdate()Debug.Notification((Self as Actor).GetBaseActorValue("Health"))Debug.Notification("OK")RegisterForSingleUpdate(10)endEvent

This code doesn't work too (only once or twice for human):
Event OnInit()RegisterForSingleUpdate(10)endEventEvent OnUpdate()Debug.Notification((Self as Actor).GetBaseActorValue("Health"))Debug.Notification("OK")(Self as Actor).Disable()(Self as Actor).Enable()RegisterForSingleUpdate(10)endEvent
User avatar
Sherry Speakman
 
Posts: 3487
Joined: Fri Oct 20, 2006 1:00 pm

Post » Wed Jun 20, 2012 5:14 pm

Could be that there is another script on the people that is using an "UnRegisterForUpdate()"

After editing out all the comments, and getting rid of the properties and variables you don't actually use (and shortening the variable names so you can get everything a bit more on the screen) I get this:

Spoiler
Scriptname DivineGifts_LevelingStats_Script extends ObjectReferencebool property AlreadyUpdated = False Auto ; Only need to set the default values once.Float Property WO_Ht AutoFloat Property WO_Mna AutoFloat Property WO_Sta AutoFloat Property WO_1H AutoFloat Property WO_1H AutoFloat Property WO_Bow AutoFloat Property WO_Blk AutoFloat Property WO_Smi AutoFloat Property WO_HA AutoFloat Property WO_LA AutoFloat Property WO_PP AutoFloat Property WO_PL AutoFloat Property WO_Sne AutoFloat Property WO_Alch AutoFloat Property WO_Spe AutoFloat Property WO_Alt AutoFloat Property WO_Conj AutoFloat Property WO_Dest AutoFloat Property WO_Ill AutoFloat Property WO_Heal AutoFloat Property WO_Enc AutoFloat Property S_Ht AutoFloat Property S_Mna AutoFloat Property S_Sta AutoFloat Property S_1H AutoFloat Property S_1H AutoFloat Property S_Bow AutoFloat Property S_Blk AutoFloat Property S_Smi AutoFloat Property S_HA AutoFloat Property S_LA AutoFloat Property S_PP AutoFloat Property S_PL AutoFloat Property S_Sne AutoFloat Property S_Alc AutoFloat Property S_Spe AutoFloat Property S_Alt AutoFloat Property S_Conj AutoFloat Property S_Dest AutoFloat Property S_Ill AutoFloat Property S_Heal AutoFloat Property S_Enc AutoFloat Property HMS_PPL = 10.0 AutoFloat Property Skill_PPL = 8.0 AutoFloat Property SOW_HMS_Points = 0.0 AutoFloat Property SOW_SP = 0.0 AutoFloat Property NPC_HBonPL = 5.0 Auto ; If you want to make sure these keep their values, make them properties.Event OnInit()	RegisterForSingleUpdate(10) ;update co 10 sekund czasu rzeczywistegoendEventEvent OnUpdate()	CheckANDSetStats()	RegisterForSingleUpdate(10)endEventFunction SetDefaultStats()	If(!S_Ht)		S_Ht = 50.0	EndIf	If(!S_Mna)		S_Mna = 50.0	EndIf	If(!S_Sta)		S_Sta = 50.0	EndIf	If(!S_1H)		S_1H = 15.0	EndIf	If(!S_1H)		S_1H = 15.0	EndIf	If(!S_Bow)		S_Bow = 15.0	EndIf	If(!S_Blk)		S_Blk = 15.0	EndIf	If(!S_Smi)		S_Smi = 15.0	EndIf	If(!S_HA)		S_HA = 15.0	EndIf	If(!S_LA)		S_LA = 15.0	EndIf	If(!S_PP)		S_PP = 15.0	EndIf	If(!S_PL)		S_PL = 15.0	EndIf	If(!S_Sne)		S_Sne = 15.0	EndIf	If(!S_Alc)		S_Alc = 15.0	EndIf	If(!S_Spe)		S_Spe = 15.0	EndIf	If(!S_Alt)		S_Alt = 15.0	EndIf	If(!S_Conj)		S_Conj = 15.0	EndIf	If(!S_Dest)		S_Dest = 15.0	EndIf	If(!S_Ill)		S_Ill = 15.0	EndIf	If(!S_Heal)		S_Heal = 15.0	EndIf	If(!S_Enc)		S_Enc = 15.0	EndIfEndFunctionFunction CheckANDSetStats()	if !AlreadyUpdated		AlreadyUpdated = True		SetDefaultStats()	Endif	Float SOW_HMS_Points2 = WO_Ht + WO_Mna + WO_Sta	Float SOW_SP2 = WO_1H + WO_1H + WO_Bow + WO_Blk + WO_Smi + WO_HA + WO_LA + WO_PP + WO_PL + WO_Sne + WO_Alch + WO_Spe + WO_Alt + WO_Conj + WO_Dest + WO_Ill + WO_Heal + WO_EncFC	Float ActorLevel= ((Self As Actor).GetLevel() as float) - 1.0		Float N_Ht = S_Ht + ActorLevel * (NPC_HBonPL + (WOHt / SOW_HMS_Points2) *  HMS_PPL)	Float N_Mna = S_Mna + ActorLevel * (WOMna / SOW_HMS_Points2) *  HMS_PPL	Float N_Sta = S_Sta + ActorLevel * (WOSta / SOW_HMS_Points2) *  HMS_PPL	Float N_1H = S_1H + ActorLevel * (WO_1H / SOW_SP2) * Skill_PPL	Float N_1H = S_1H + ActorLevel * (WO_1H / SOW_SP2) * Skill_PPL	Float N_Bow = S_Bow + ActorLevel * (WOBow / SOW_SP2) * Skill_PPL	Float N_Blk = S_Blk + ActorLevel * (WOBlk / SOW_SP2) * Skill_PPL	Float N_Smi = S_Smi + ActorLevel * (WOSmi / SOW_SP2) * Skill_PPL	Float N_HA = S_HA + ActorLevel * (WO_HA / SOW_SP2) * Skill_PPL	Float N_LA = S_LA + ActorLevel * (WO_LA / SOW_SP2) * Skill_PPL	Float N_PP = S_PP + ActorLevel * (WOPP / SOW_SP2) * Skill_PPL	Float N_PL = S_PL + ActorLevel * (WOPL / SOW_SP2) * Skill_PPL	Float N_Sne = S_Sne + ActorLevel * (WOSne / SOW_SP2) * Skill_PPL	Float N_Alc = S_Alc + ActorLevel * (WOAlch / SOW_SP2) * Skill_PPL	Float N_Spe = S_Spe + ActorLevel * (WOSpe / SOW_SP2) * Skill_PPL	Float N_Alt = S_Alt + ActorLevel * (WOAlt / SOW_SP2) * Skill_PPL	Float N_Conj = S_Conj + ActorLevel * (WOConj / SOW_SP2) * Skill_PPL	Float N_Dest = S_Dest + ActorLevel * (WODest / SOW_SP2) * Skill_PPL	Float N_Ill = S_Ill + ActorLevel * (WOIll / SOW_SP2) * Skill_PPL	Float N_Heal = S_Heal + ActorLevel * (WOHeal / SOW_SP2) * Skill_PPL	Float N_Enc = S_Enc + ActorLevel * (WOEnc / SOW_SP2) * Skill_PPL	(Self As Actor).SetActorValue("Health", N_Ht)	(Self As Actor).SetActorValue("Magicka", N_Mna)	(Self As Actor).SetActorValue("Stamina", N_Sta)	(Self As Actor).SetActorValue("OneHanded", N_1H)	(Self As Actor).SetActorValue("TwoHanded", N_1H)	(Self As Actor).SetActorValue("Marksman", N_Bow)	(Self As Actor).SetActorValue("Block", N_Blk)	(Self As Actor).SetActorValue("Smithing", N_Smi)	(Self As Actor).SetActorValue("HeavyArmor", N_HA)	(Self As Actor).SetActorValue("LightArmor", N_LA)	(Self As Actor).SetActorValue("Pickpocket", N_PP)	(Self As Actor).SetActorValue("Lockpicking", N_PL)	(Self As Actor).SetActorValue("Sneak", N_Sne)	(Self As Actor).SetActorValue("Alchemy", N_Alc)	(Self As Actor).SetActorValue("Speechcraft", N_Spe)	(Self As Actor).SetActorValue("Alteration", N_Alt)	(Self As Actor).SetActorValue("Conjuration", N_Conj)	(Self As Actor).SetActorValue("Destruction", N_Dest)	(Self As Actor).SetActorValue("Illusion", N_Ill)	(Self As Actor).SetActorValue("Restoration", N_Heal)	(Self As Actor).SetActorValue("Enchanting", N_Enc)	(Self As Actor).Disable()	(Self As Actor).Enable() ; Not sure what these are supposed to be doing, other than making the script owner "blink out" for a moment.endFunction

You could skip the whole OnUpdate thing and just call a function like so:

Spoiler
Scriptname DivineGifts_LevelingStats_Script extends ObjectReferencebool property AlreadyUpdated = False Auto ; Only need to set the default values once.Bool Property AlreadyLooping = False Auto ; Prevents multiple threads if OnInit fires more than once..Float Property WO_Ht AutoFloat Property WO_Mna AutoFloat Property WO_Sta AutoFloat Property WO_1H AutoFloat Property WO_1H AutoFloat Property WO_Bow AutoFloat Property WO_Blk AutoFloat Property WO_Smi AutoFloat Property WO_HA AutoFloat Property WO_LA AutoFloat Property WO_PP AutoFloat Property WO_PL AutoFloat Property WO_Sne AutoFloat Property WO_Alch AutoFloat Property WO_Spe AutoFloat Property WO_Alt AutoFloat Property WO_Conj AutoFloat Property WO_Dest AutoFloat Property WO_Ill AutoFloat Property WO_Heal AutoFloat Property WO_Enc AutoFloat Property S_Ht AutoFloat Property S_Mna AutoFloat Property S_Sta AutoFloat Property S_1H AutoFloat Property S_1H AutoFloat Property S_Bow AutoFloat Property S_Blk AutoFloat Property S_Smi AutoFloat Property S_HA AutoFloat Property S_LA AutoFloat Property S_PP AutoFloat Property S_PL AutoFloat Property S_Sne AutoFloat Property S_Alc AutoFloat Property S_Spe AutoFloat Property S_Alt AutoFloat Property S_Conj AutoFloat Property S_Dest AutoFloat Property S_Ill AutoFloat Property S_Heal AutoFloat Property S_Enc AutoFloat Property HMS_PPL = 10.0 AutoFloat Property Skill_PPL = 8.0 AutoFloat Property SOW_HMS_Points = 0.0 AutoFloat Property SOW_SP = 0.0 AutoFloat Property NPC_HBonPL = 5.0 Auto ; If you want to make sure these keep their values, make them properties.Event OnInit()    if !AlreadyLooping	   AlreadyLooping = True       CheckAndSetStats()    endifendEventFunction SetDefaultStats()	If(!S_Ht)		S_Ht = 50.0	EndIf	If(!S_Mna)		S_Mna = 50.0	EndIf	If(!S_Sta)		S_Sta = 50.0	EndIf	If(!S_1H)		S_1H = 15.0	EndIf	If(!S_1H)		S_1H = 15.0	EndIf	If(!S_Bow)		S_Bow = 15.0	EndIf	If(!S_Blk)		S_Blk = 15.0	EndIf	If(!S_Smi)		S_Smi = 15.0	EndIf	If(!S_HA)		S_HA = 15.0	EndIf	If(!S_LA)		S_LA = 15.0	EndIf	If(!S_PP)		S_PP = 15.0	EndIf	If(!S_PL)		S_PL = 15.0	EndIf	If(!S_Sne)		S_Sne = 15.0	EndIf	If(!S_Alc)		S_Alc = 15.0	EndIf	If(!S_Spe)		S_Spe = 15.0	EndIf	If(!S_Alt)		S_Alt = 15.0	EndIf	If(!S_Conj)		S_Conj = 15.0	EndIf	If(!S_Dest)		S_Dest = 15.0	EndIf	If(!S_Ill)		S_Ill = 15.0	EndIf	If(!S_Heal)		S_Heal = 15.0	EndIf	If(!S_Enc)		S_Enc = 15.0	EndIfEndFunctionFunction CheckANDSetStats()   While True	if !AlreadyUpdated		AlreadyUpdated = True		SetDefaultStats()	Endif	Float SOW_HMS_Points2 = WO_Ht + WO_Mna + WO_Sta	Float SOW_SP2 = WO_1H + WO_1H + WO_Bow + WO_Blk + WO_Smi + WO_HA + WO_LA + WO_PP + WO_PL + WO_Sne + WO_Alch + WO_Spe + WO_Alt + WO_Conj + WO_Dest + WO_Ill + WO_Heal + WO_EncFC	Float ActorLevel= ((Self As Actor).GetLevel() as float) - 1.0		Float N_Ht = S_Ht + ActorLevel * (NPC_HBonPL + (WOHt / SOW_HMS_Points2) *  HMS_PPL)	Float N_Mna = S_Mna + ActorLevel * (WOMna / SOW_HMS_Points2) *  HMS_PPL	Float N_Sta = S_Sta + ActorLevel * (WOSta / SOW_HMS_Points2) *  HMS_PPL	Float N_1H = S_1H + ActorLevel * (WO_1H / SOW_SP2) * Skill_PPL	Float N_1H = S_1H + ActorLevel * (WO_1H / SOW_SP2) * Skill_PPL	Float N_Bow = S_Bow + ActorLevel * (WOBow / SOW_SP2) * Skill_PPL	Float N_Blk = S_Blk + ActorLevel * (WOBlk / SOW_SP2) * Skill_PPL	Float N_Smi = S_Smi + ActorLevel * (WOSmi / SOW_SP2) * Skill_PPL	Float N_HA = S_HA + ActorLevel * (WO_HA / SOW_SP2) * Skill_PPL	Float N_LA = S_LA + ActorLevel * (WO_LA / SOW_SP2) * Skill_PPL	Float N_PP = S_PP + ActorLevel * (WOPP / SOW_SP2) * Skill_PPL	Float N_PL = S_PL + ActorLevel * (WOPL / SOW_SP2) * Skill_PPL	Float N_Sne = S_Sne + ActorLevel * (WOSne / SOW_SP2) * Skill_PPL	Float N_Alc = S_Alc + ActorLevel * (WOAlch / SOW_SP2) * Skill_PPL	Float N_Spe = S_Spe + ActorLevel * (WOSpe / SOW_SP2) * Skill_PPL	Float N_Alt = S_Alt + ActorLevel * (WOAlt / SOW_SP2) * Skill_PPL	Float N_Conj = S_Conj + ActorLevel * (WOConj / SOW_SP2) * Skill_PPL	Float N_Dest = S_Dest + ActorLevel * (WODest / SOW_SP2) * Skill_PPL	Float N_Ill = S_Ill + ActorLevel * (WOIll / SOW_SP2) * Skill_PPL	Float N_Heal = S_Heal + ActorLevel * (WOHeal / SOW_SP2) * Skill_PPL	Float N_Enc = S_Enc + ActorLevel * (WOEnc / SOW_SP2) * Skill_PPL	(Self As Actor).SetActorValue("Health", N_Ht)	(Self As Actor).SetActorValue("Magicka", N_Mna)	(Self As Actor).SetActorValue("Stamina", N_Sta)	(Self As Actor).SetActorValue("OneHanded", N_1H)	(Self As Actor).SetActorValue("TwoHanded", N_1H)	(Self As Actor).SetActorValue("Marksman", N_Bow)	(Self As Actor).SetActorValue("Block", N_Blk)	(Self As Actor).SetActorValue("Smithing", N_Smi)	(Self As Actor).SetActorValue("HeavyArmor", N_HA)	(Self As Actor).SetActorValue("LightArmor", N_LA)	(Self As Actor).SetActorValue("Pickpocket", N_PP)	(Self As Actor).SetActorValue("Lockpicking", N_PL)	(Self As Actor).SetActorValue("Sneak", N_Sne)	(Self As Actor).SetActorValue("Alchemy", N_Alc)	(Self As Actor).SetActorValue("Speechcraft", N_Spe)	(Self As Actor).SetActorValue("Alteration", N_Alt)	(Self As Actor).SetActorValue("Conjuration", N_Conj)	(Self As Actor).SetActorValue("Destruction", N_Dest)	(Self As Actor).SetActorValue("Illusion", N_Ill)	(Self As Actor).SetActorValue("Restoration", N_Heal)	(Self As Actor).SetActorValue("Enchanting", N_Enc)	(Self As Actor).Disable()	(Self As Actor).Enable() ; Not sure what these are supposed to be doing, other than making the script owner "blink out" for a moment.	Utility.Wait(10)   EndWhileendFunction
User avatar
JUDY FIGHTS
 
Posts: 3420
Joined: Fri Jun 23, 2006 4:25 am

Post » Wed Jun 20, 2012 12:21 pm

It's very strange that you can't even get those script fragments to work... Are those the whole scripts? What happens if you use this:

Scriptname ExampleScript extends Actorint Count = 0Event OnInit()    RegisterForSingleUpdate(5)EndEventEvent OnUpdate()    Count += 1    Debug.Notification("This is update #" + Count + ".")    RegisterForSingleUpdate(5)EndEvent
User avatar
x a million...
 
Posts: 3464
Joined: Tue Jun 13, 2006 2:59 pm

Post » Wed Jun 20, 2012 11:30 pm

Could be that there is another script on the people that is using an "UnRegisterForUpdate()"

You are right. I have another script on this human:
Scriptname DivineGifts_EquipItemToNPC_Script extends ObjectReferenceActor Property ActorOwningThisScript  AutoFaction Property ThisFactionOfNPCMustBe_to_equip_items1  AutoInt Property RankOfFactionOfNPC_when_to_equip_item1  AutoArmor Property ArmorToEquip1  AutoArmor Property ArmorToEquip2  AutoArmor Property ArmorToEquip3  AutoEvent OnInit()RegisterForSingleUpdate(10) ;pojedynczy update po 10 sekundach czasu rzeczywistegoendEventEvent OnUpdate()If (ThisFactionOfNPCMustBe_to_equip_items1)  If (ActorOwningThisScript.GetFactionRank(ThisFactionOfNPCMustBe_to_equip_items1) == RankOfFactionOfNPC_when_to_equip_item1)   If (ActorOwningThisScript.GetItemCount(ArmorToEquip1) > 0)	ActorOwningThisScript.EquipItem(ArmorToEquip1)   EndIf   If (ActorOwningThisScript.GetItemCount(ArmorToEquip2) > 0)	ActorOwningThisScript.EquipItem(ArmorToEquip2)   EndIf   If (ActorOwningThisScript.GetItemCount(ArmorToEquip3) > 0)	ActorOwningThisScript.EquipItem(ArmorToEquip3)   EndIf   ;Debug.Notification("Correct rank")  EndIf  ;Debug.Notification("Faction")Else  If (ActorOwningThisScript.GetItemCount(ArmorToEquip1) > 0)   ActorOwningThisScript.EquipItem(ArmorToEquip1)  EndIf  If (ActorOwningThisScript.GetItemCount(ArmorToEquip2) > 0)   ActorOwningThisScript.EquipItem(ArmorToEquip2)  EndIf  If (ActorOwningThisScript.GetItemCount(ArmorToEquip3) > 0)   ActorOwningThisScript.EquipItem(ArmorToEquip3)  EndIf  ;Debug.Notification("NoFaction")EndIfIf (ActorOwningThisScript.IsEquipped(ArmorToEquip1) == true || ActorOwningThisScript.IsEquipped(ArmorToEquip2)== true II ActorOwningThisScript.IsEquipped(ArmorToEquip3)== true)  UnregisterForUpdate()EndIf;Debug.Notification("End")endEvent

I changed it on this:
Scriptname DivineGifts_EquipItemToNPC_Script extends ObjectReferenceActor Property ActorOwningThisScript  AutoFaction Property ThisFactionOfNPCMustBe_to_equip_items1  AutoInt Property RankOfFactionOfNPC_when_to_equip_item1  AutoArmor Property ArmorToEquip1  AutoArmor Property ArmorToEquip2  AutoArmor Property ArmorToEquip3  AutoEvent OnInit()RegisterForSingleUpdate(10) ;pojedynczy update po 10 sekundach czasu rzeczywistegoendEventEvent OnUpdate()If (ThisFactionOfNPCMustBe_to_equip_items1)  If (ActorOwningThisScript.GetFactionRank(ThisFactionOfNPCMustBe_to_equip_items1) == RankOfFactionOfNPC_when_to_equip_item1)   If (ActorOwningThisScript.GetItemCount(ArmorToEquip1) > 0)	ActorOwningThisScript.EquipItem(ArmorToEquip1)   EndIf   If (ActorOwningThisScript.GetItemCount(ArmorToEquip2) > 0)	ActorOwningThisScript.EquipItem(ArmorToEquip2)   EndIf   If (ActorOwningThisScript.GetItemCount(ArmorToEquip3) > 0)	ActorOwningThisScript.EquipItem(ArmorToEquip3)   EndIf   ;Debug.Notification("Correct rank")  EndIf  ;Debug.Notification("Faction")Else  If (ActorOwningThisScript.GetItemCount(ArmorToEquip1) > 0)   ActorOwningThisScript.EquipItem(ArmorToEquip1)  EndIf  If (ActorOwningThisScript.GetItemCount(ArmorToEquip2) > 0)   ActorOwningThisScript.EquipItem(ArmorToEquip2)  EndIf  If (ActorOwningThisScript.GetItemCount(ArmorToEquip3) > 0)   ActorOwningThisScript.EquipItem(ArmorToEquip3)  EndIf  ;Debug.Notification("NoFaction")EndIfIf (ActorOwningThisScript.IsEquipped(ArmorToEquip1) == false && ActorOwningThisScript.IsEquipped(ArmorToEquip2) == false && ActorOwningThisScript.IsEquipped(ArmorToEquip3) == false)  RegisterForSingleUpdate(10) ;pojedynczy update po 10 sekundach czasu rzeczywistegoEndIf;Debug.Notification("End")endEvent

Now both scripts work correctly on this human actor.

So it was my stupid mistake, because I was thinking, that "UnRegisterForUpdate()" is only for single script, not for whole object.

Everyone helped.
Thank you very much.
Problem is solved.
User avatar
Marquis deVille
 
Posts: 3409
Joined: Thu Jul 26, 2007 8:24 am


Return to V - Skyrim