Jump to content

Please help me get this simple script working


irswat

Recommended Posts

What is that update for? Re-checking for your weapon(s) to be equipped and swapping if necessary? If so, that could work. Just double check if possible at the extreme ends. I'm not sure if 17:59 would round up to 18 or down to 17. The game can be fickle with how it converts floats to ints. Hopefully, you'll keep it all floats and it should be fine.

 

You are lacking an = 6 as well as an = 18. Should the player hit precisely at 6 or 18, your code will fail.

Link to comment
Share on other sites

  • Replies 135
  • Created
  • Last Reply

Top Posters In This Topic

What is that update for? Re-checking for your weapon(s) to be equipped and swapping if necessary? If so, that could work. Just double check if possible at the extreme ends. I'm not sure if 17:59 would round up to 18 or down to 17. The game can be fickle with how it converts floats to ints. Hopefully, you'll keep it all floats and it should be fine.

 

You are lacking an = 6 as well as an = 18. Should the player hit precisely at 6 or 18, your code will fail.

Yes that update is in case the weapon is equipped and the player waits, or sleeps, etc. It seems OnEquipped only triggers when a weapon is equipped, and updates very slowly otherwise. Thanks for all the help peoples!

Link to comment
Share on other sites

I found a neat function so I don't need to convert to real time. It should also avoid any problems with real time if a person waits, uses the menu, etc in game.

RegisterForSingleUpdateGameTime()

Edited by irswat
Link to comment
Share on other sites

For some reason it won't dynamically update meaning if I have the sword equipped at 5:55 and the script registers for a single update in 5 minutes, and I hold onto until it turns 6 the sword is not automatically being swapped out for the other. It is only when I try to re equip the sword that the sword changes.

Link to comment
Share on other sites

that fixed it! sweet! This should be optimally efficient now right? thanks again!

 

Scriptname DawnDuskTimerScript extends Quest  
{Prevents dawnfang and duskfang from being equipped at wrong times}

Weapon property adventurerdawnfang auto
Weapon property tsasciduskblade auto

GlobalVariable property GameHour auto
 
Actor Property PlayerRef Auto

float TimeUntilUpdate
int EquipHand=0 ;1=right 2=left

Event OnInit()

	Debug.Notification("Dawnfang and dustfang timer initiated")
	float TimeofDay=GameHour.GetValue() ;thanks to tonycubed2 for this
		
	if (TimeofDay>=6.0 && TimeofDay<18.0)
		TimeUntilUpdate=18.0-TimeofDay
	elseif (TimeofDay>=18.0 && TimeofDay<=24.0)
		TimeUntilUpdate=24.0-TimeofDay
	elseif (TimeofDay<6.0)
		TimeUntilUpdate=6.0-TimeofDay
	endif
	if ((TimeuntilUpdate<=1.0) || TimeofDay==6.0 || TimeofDay==18.0)
		RegisterForSingleUpdateGameTime(1)
	endif
	Debug.Notification("Quest:Gametime until update" + TimeUntilUpdate)
	;TimeUntilUpdate=(TimeUntilUpdate/timescale.GetValue())
	;Debug.Notification("Realtime until update" + TimeUntilUpdate)
	RegisterForSingleUpdateGameTime(TimeUntilUpdate)
	
EndEVENT

EVENT OnUpdateGameTime()
	
	float TimeofDay=GameHour.GetValue() ;thanks to tonycubed2 for this
	PlayerRef=Game.GetPlayer()

		if (TimeofDay>=6.0 && TimeofDay<18.0)
			if ((PlayerRef.GetEquippedWeapon()==tsasciduskblade)||(PlayerRef.GetEquippedWeapon(true)==tsasciduskblade))
				;gets hand the sword is equipped in
				if PlayerRef.GetEquippedWeapon()==tsasciduskblade
					EquipHand=1 ;right hand
				elseif PlayerRef.GetEquippedWeapon(true)==tsasciduskblade
					EquipHand=2 ;left hand
				endif
				PlayerRef.UnequipItem(tsasciduskblade,true,true)
				;PlayerRef.RemoveItem(tsasciduskblade)
				;Debug.Notification("You cannot equip Duskfang during the day")
				PlayerRef.EquipItemEx(adventurerdawnfang, EquipHand, false,true)
				Debug.Notification("Dawnfang has emerged")
			endif
		elseif ((TimeofDay>=18.0 && TimeofDay<24.0)||(TimeofDay<6))
			if ((PlayerRef.GetEquippedWeapon()==adventurerdawnfang)||(PlayerRef.GetEquippedWeapon(true)==adventurerdawnfang))
				;gets hand the sword is equipped in
				if PlayerRef.GetEquippedWeapon()==adventurerdawnfang
					EquipHand=1 ;right hand
				elseif PlayerRef.GetEquippedWeapon(true)==adventurerdawnfang
					EquipHand=2 ;left hand
				endif
				PlayerRef.UnequipItem(adventurerdawnfang,true,true)
				;PlayerRef.RemoveItem(adventurerdawnfang)
				;Debug.Notification("You cannot equip Dawnfang during the night")
				PlayerRef.EquipItemEx(tsasciduskblade, EquipHand, false,true)
				Debug.Notification("Duskfang has emerged")
			endif
		endif
	
	
	if (TimeofDay>=6.0 && TimeofDay<18.0)
		TimeUntilUpdate=18.0-TimeofDay
	elseif (TimeofDay>=18.0 && TimeofDay<=24.0)
		TimeUntilUpdate=24.0-TimeofDay
	elseif (TimeofDay<6.0)
		TimeUntilUpdate=6.0-TimeofDay
	endif
	if TimeuntilUpdate<=0.0
		RegisterForSingleUpdateGameTime(1)
	endif
	Debug.Notification("Quest Update: Gametime until update" + TimeUntilUpdate)
	;TimeUntilUpdate=(TimeUntilUpdate/timescale.GetValue())
	;Debug.Notification("Realtime until update" + TimeUntilUpdate)
	RegisterForSingleUpdateGameTime(TimeUntilUpdate)
endEVENT 

 



Next: is there a way to dynamically temper weapons, or can I only manually change base damage? mod author wants the swords to upgrade for every 12 kills up to legendary.

Edited by irswat
Link to comment
Share on other sites

This part of your script has duplication of code which could be simplified by calling a function and passing in the desired parameters. As a result it can be shortened.

Your posted code:

 

 

;first part of event
		if (TimeofDay>=6.0 && TimeofDay<18.0)
			if ((PlayerRef.GetEquippedWeapon()==tsasciduskblade)||(PlayerRef.GetEquippedWeapon(true)==tsasciduskblade))
				;gets hand the sword is equipped in
				if PlayerRef.GetEquippedWeapon()==tsasciduskblade
					EquipHand=1 ;right hand
				elseif PlayerRef.GetEquippedWeapon(true)==tsasciduskblade
					EquipHand=2 ;left hand
				endif
				PlayerRef.UnequipItem(tsasciduskblade,true,true)
				;PlayerRef.RemoveItem(tsasciduskblade)
				;Debug.Notification("You cannot equip Duskfang during the day")
				PlayerRef.EquipItemEx(adventurerdawnfang, EquipHand, false,true)
				Debug.Notification("Dawnfang has emerged")
			endif
		elseif ((TimeofDay>=18.0 && TimeofDay<24.0)||(TimeofDay<6))
			if ((PlayerRef.GetEquippedWeapon()==adventurerdawnfang)||(PlayerRef.GetEquippedWeapon(true)==adventurerdawnfang))
				;gets hand the sword is equipped in
				if PlayerRef.GetEquippedWeapon()==adventurerdawnfang
					EquipHand=1 ;right hand
				elseif PlayerRef.GetEquippedWeapon(true)==adventurerdawnfang
					EquipHand=2 ;left hand
				endif
				PlayerRef.UnequipItem(adventurerdawnfang,true,true)
				;PlayerRef.RemoveItem(adventurerdawnfang)
				;Debug.Notification("You cannot equip Dawnfang during the night")
				PlayerRef.EquipItemEx(tsasciduskblade, EquipHand, false,true)
				Debug.Notification("Duskfang has emerged")
			endif
		endif
;rest of event 

 

 

Can be changed to:

 

 

;first part of event
		if (TimeofDay>=6.0 && TimeofDay<18.0)
			if PlayerRef.GetEquippedWeapon()==tsasciduskblade
				EquipHand=1 ;right hand
				WeaponSwap(tsasciduskblade,adventurerdawnfang,EquipHand)
			elseif PlayerRef.GetEquippedWeapon(true)==tsasciduskblade
				EquipHand=2 ;left hand
				WeaponSwap(tsasciduskblade,adventurerdawnfang,EquipHand)
			endif
		elseif ((TimeofDay>=18.0 && TimeofDay<24.0)||(TimeofDay<6))
			if PlayerRef.GetEquippedWeapon()==adventurerdawnfang
				EquipHand=1 ;right hand
				WeaponSwap(adventurerdawnfang,tsasciduskblade,EquipHand)
			elseif PlayerRef.GetEquippedWeapon(true)==adventurerdawnfang
				EquipHand=2 ;left hand
				WeaponSwap(adventurerdawnfang,tsasciduskblade,EquipHand)
			endif
		endif
;rest of event

;function to handle weapon swapping -- goes outside of the event
Function WeaponSwap(Form OldWeapon, Form NewWeapon, Int EH)
	PlayerRef.UnequipItem(OldWeapon,true,true)
	PlayerRef.EquipItemEx(NewWeapon,EH,false,true)
	Debug.Notification(NewWeapon.GetName()+" has emerged")
EndFunction 

GetName() requires SKSE. If you don't want to use that, you'll have to move the notification back to where it was.

 

 

 

Also, there is no need to check for the player's equipped weapon to be in either hand and then check again for the specific hand. A single check per hand with processing for that hand is sufficient. Such change is demonstrated above.

 

I'm not sure about tempering. You can change just about any stat you want including the name. But the game might not recognize it as having been tempered.

Link to comment
Share on other sites

Is there a function GetIsInt that returns whether a variable is an integer or not?

will this work:

;function with help from FamilyFrank
Function IncrementKillCount(Bool bIdentity)
 If bIdentity ; its dawnfang
	DawnfangFragCount.Mod(1)
	KillLevel=(DawnfangFragCount.GetValue()/12)
	if (KillLevel==KillLevel.GetValue() As Int)
		tempering=KillLevel*0.1
		TemperWeapon(tempering,adventurerdawnfang)
	endif
 Else ; its duskfang
	DuskfangFragCount.Mod(1)
	KillLevel=(DuskfangFragCount.GetValue()/12)
	if (KillLevel==KillLevel.GetValue() As Int)
		tempering=KillLevel*0.1
		TemperWeapon(tempering,tsasciduskblade)
	endif
 Endif
EndFunction
;function taken from http://www.creationkit.com/index.php?title=SetItemHealthPercent_-_ObjectReference
Function TemperWeapon(float btempering, Form weaponRef)
	weaponref.SetItemHealthPercent(1 +btempering)
EndFunction

The hope is that there are 6 levels of tempering for each weapon, so 72 kills to make each weapon legendary.

Edited by irswat
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.

×
×
  • Create New...