Jump to content

Please help me get this simple script working


irswat

Recommended Posts

There could always be improvements made to the code up to a point. Ultimately, simpler would be less features.

 

Perhaps you could scrap the whole tempering idea and do what The Huntsman does with its upgrades. Replace the weapon with a different version. The Huntsman does it to change the mesh, but you could do it to change the stats (and even pre-apply the name change to include fine and what not, tho personally I prefer using +1, +2, etc instead of text)

the items really are tempered, you don't need to change the names at all. I included that in my original code for debugging purposes.

Link to comment
Share on other sites

  • Replies 135
  • Created
  • Last Reply

Top Posters In This Topic

Tip: In your SpawnTemperedWeapon function you are also using a variable of the same name. Might be a good idea to adjust the variable name just in case the script decides to flip out and get confused as to when to use the variable or when to use the function. Hate for you to end up with a function that keeps calling itself repeatedly.

 

Bored: Maybe the following will help with the function you need. An adjusted SpawnTemperedWeapon function (with suggested tip above), a couple added local variables and two functions to get whatever dawn or dusk variant the actor currently has.

 

 

 

Function SpawnTemperedWeapon(int rWeaponSwitch, float rgtempering, int rEquipHand)
	if (rWeaponSwitch==1)
		Form rTempWeapon=adventurerdawnfang
	elseif (rWeaponSwitch==2)
		Form rTempWeapon=tsasciduskblade
	endif
	
	;removes old weapon
	PlayerRef.RemoveItem(rTempWeapon,1,true)
	;tempers weapon
	ObjectReference SpawnTempWeapon = FangBladeSpawn.PlaceAtMe(rTempWeapon, 1, TRUE)
	SpawnTempWeapon.SetItemHealthPercent(btempering)
	;adds tempered weapon
	PlayerRef.AddItem(SpawnTempWeapon,1,false)
	;equips tempered weapon to proper hand
	PlayerRef.EquipItemEx(SpawnTempWeapon.GetBaseObject(),EH,false,true)
	
	if (rWeaponSwitch==1)
		TempDawn = SpawnTempWeapon
		if (!DawnfangTemperFormList.HasForm(SpawnTempWeapon.GetBaseObject()))
			DawnfangTemperFormList.AddForm(SpawnTempWeapon.GetBaseObject())
		endif
	elseif (rWeaponSwitch==2)
		TempDusk = SpawnTempWeapon
		if (!DuskfangTemperFormList.HasForm(SpawnTempWeapon.GetBaseObject()))
			DuskfangTemperFormList.AddForm(SpawnTempWeapon.GetBaseObject())
		endif
	endif		
endFUNCTION

ObjectReference TempDawn
ObjectReference TempDusk

Weapon property adventurerdawnfang auto
Weapon property tsasciduskblade auto

Weapon Function GetDawn(Actor TheP)
	Weapon Result = None
	If TheP.GetItemCount(adventurerdawnfang) >= 1
		Result = adventurerdawnfang
	ElseIf TheP.GetItemCount(TempDawn) >= 1
		Result = TempDawn as Weapon
	EndIf
	Return Result
EndFunction

Weapon Function GetDusk(Actor TheP)
	Weapon Result = None
	If TheP.GetItemCount(tsasciduskblade) >= 1
		Result = tsasciduskblade
	ElseIf TheP.GetItemCount(TempDusk) >= 1
		Result = TempDusk as Weapon
	EndIf
	Return Result
EndFunction 

The weapon properties are there simply so I could copy paste the proper names. No need to list 'em again on the script.

 

 

Link to comment
Share on other sites

The next part is going to be tricky. I need to create a function that returns a flag for whether the weapon equipped is a tempered version of dawnfang or duskfang. Right now I check if these base ids are equipped or in inventory, but this won't catch any of the tempered versions of the blade.

 

 

 

I don't think there is a good way to determine this from the object itself since most functions that work on items in inventory query against the base object. This prevents you from getting the actual Item health value that reflects that it is tempered. If I could make a suggestion, create a GlobalVariable for each sword to track how many times it has been tempered. Then simply increment the Global in the tempering function. This will allow you to determine how many times it has been improved and adjust the temper from there. It will also give you a good way to test if it is tempered. Given that a Global value of 0 is treated as false and anything larger than 0 is true, you can just do an if on the Global to see if it has been tempered.

Link to comment
Share on other sites

 

The next part is going to be tricky. I need to create a function that returns a flag for whether the weapon equipped is a tempered version of dawnfang or duskfang. Right now I check if these base ids are equipped or in inventory, but this won't catch any of the tempered versions of the blade.

 

 

 

I don't think there is a good way to determine this from the object itself since most functions that work on items in inventory query against the base object. This prevents you from getting the actual Item health value that reflects that it is tempered. If I could make a suggestion, create a GlobalVariable for each sword to track how many times it has been tempered. Then simply increment the Global in the tempering function. This will allow you to determine how many times it has been improved and adjust the temper from there. It will also give you a good way to test if it is tempered. Given that a Global value of 0 is treated as false and anything larger than 0 is true, you can just do an if on the Global to see if it has been tempered.

 

I'm not sure the implications but when I use placeatme with the persistent reference flag I am able to store and retrieve the base object reliably. When I temper the blade I store this base reference in a formlist.

 

For example suppose I get 12 kills with dawnfang, it becomes tempered to (fine). After it is tempered I store it in a formlist. The tempered blade is replaced at 6pm with duskfang. When 6 am rolls around again I am checking the highest tempered weapon in the formlist, in this case it is a (fine) dawnfang, and so I pass that base reference to the function SpawnTemperedBlade and it gives the player a (fine) dawnfang.

 

In order to check whether a tempered is blade is equipped or inventory I'm simply going to check the currently equipped weapon/inventory against both form lists of tempered blades. If it's in the list then it means it's tempered.

 

Your idea is a good idea, and I already have implemented it. It is the GlobalVariable DawnfangLevel and DuskfangLevel.

Edited by irswat
Link to comment
Share on other sites

Tip: In your SpawnTemperedWeapon function you are also using a variable of the same name. Might be a good idea to adjust the variable name just in case the script decides to flip out and get confused as to when to use the variable or when to use the function. Hate for you to end up with a function that keeps calling itself repeatedly.

 

Bored: Maybe the following will help with the function you need. An adjusted SpawnTemperedWeapon function (with suggested tip above), a couple added local variables and two functions to get whatever dawn or dusk variant the actor currently has.

 

 

 

Function SpawnTemperedWeapon(int rWeaponSwitch, float rgtempering, int rEquipHand)
	if (rWeaponSwitch==1)
		Form rTempWeapon=adventurerdawnfang
	elseif (rWeaponSwitch==2)
		Form rTempWeapon=tsasciduskblade
	endif
	
	;removes old weapon
	PlayerRef.RemoveItem(rTempWeapon,1,true)
	;tempers weapon
	ObjectReference SpawnTempWeapon = FangBladeSpawn.PlaceAtMe(rTempWeapon, 1, TRUE)
	SpawnTempWeapon.SetItemHealthPercent(btempering)
	;adds tempered weapon
	PlayerRef.AddItem(SpawnTempWeapon,1,false)
	;equips tempered weapon to proper hand
	PlayerRef.EquipItemEx(SpawnTempWeapon.GetBaseObject(),EH,false,true)
	
	if (rWeaponSwitch==1)
		TempDawn = SpawnTempWeapon
		if (!DawnfangTemperFormList.HasForm(SpawnTempWeapon.GetBaseObject()))
			DawnfangTemperFormList.AddForm(SpawnTempWeapon.GetBaseObject())
		endif
	elseif (rWeaponSwitch==2)
		TempDusk = SpawnTempWeapon
		if (!DuskfangTemperFormList.HasForm(SpawnTempWeapon.GetBaseObject()))
			DuskfangTemperFormList.AddForm(SpawnTempWeapon.GetBaseObject())
		endif
	endif		
endFUNCTION

ObjectReference TempDawn
ObjectReference TempDusk

Weapon property adventurerdawnfang auto
Weapon property tsasciduskblade auto

Weapon Function GetDawn(Actor TheP)
	Weapon Result = None
	If TheP.GetItemCount(adventurerdawnfang) >= 1
		Result = adventurerdawnfang
	ElseIf TheP.GetItemCount(TempDawn) >= 1
		Result = TempDawn as Weapon
	EndIf
	Return Result
EndFunction

Weapon Function GetDusk(Actor TheP)
	Weapon Result = None
	If TheP.GetItemCount(tsasciduskblade) >= 1
		Result = tsasciduskblade
	ElseIf TheP.GetItemCount(TempDusk) >= 1
		Result = TempDusk as Weapon
	EndIf
	Return Result
EndFunction 

The weapon properties are there simply so I could copy paste the proper names. No need to list 'em again on the script.

 

 

Thanks I may refer to this, or just use it, if that is ok.

Link to comment
Share on other sites

 

 

Function ItsDayTime()

	WeaponFlag=2 ;duskfang
	;is a tempered duskfang in the right hand?
	EquipHand=1 ;right
	WeaponEquipped=PlayerRef.GetEquippedWeapon()
	IsATempereredWeaponEquipped=(WeaponIsInTemperedFormList(WeaponFlag, WeaponEquipped, EquipHand))
	if IsATempereredWeaponEquipped==true
		gtempering=DawnFangLevel.GetValue()
		if (gtempering==1.0) ;the weapon to be equipped is not tempered
			WeaponSwap(WeaponEquipped,adventurerdawnfang,EquipHand)
		elseif (gtempering>1.0) ;the weapon to be equipped is tempered
			int WeaponSwitch=1 ;dawnfang
			SpawnTemperedBlade(WeaponSwitch, gtempering, EquipHand)
		endif
	endif
	
	
	WeaponFlag=2 ;duskfang
	;is a tempered duskfang in the left hand?
	EquipHand=2 ;left
	WeaponEquipped=PlayerRef.GetEquippedWeapon(true)
	IsATempereredWeaponEquipped=(WeaponIsInTemperedFormList(WeaponFlag, WeaponEquipped, EquipHand))
	if IsATempereredWeaponEquipped==true
		gtempering=DawnFangLevel.GetValue()
		if (gtempering==1.0) ;the weapon to be equipped is not tempered
			WeaponSwap(WeaponEquipped,adventurerdawnfang,EquipHand)
		elseif (gtempering>1.0) ;the weapon to be equipped is tempered
			int WeaponSwitch=1 ;dawnfang
			SpawnTemperedBlade(WeaponSwitch, gtempering, EquipHand)
		endif
	endif
	
	if(PlayerRef.GetEquippedWeapon()==tsasciduskblade);duskfang is equipped (right hand)
		gtempering=DawnFangLevel.GetValue()
		EquipHand=1 ;right
		if (gtempering==1.0) ;the weapon to be equipped is not tempered
			WeaponSwap(tsasciduskblade,adventurerdawnfang,EquipHand)
		elseif (gtempering>1.0) ;the weapon to be equipped is tempered
			int WeaponSwitch=1 ;dawnfang
			SpawnTemperedBlade(WeaponSwitch, gtempering, EquipHand)
		endif
	elseif  (PlayerRef.GetEquippedWeapon(true)==tsasciduskblade) ;duskfang is equipped (left hand)
		gtempering=DawnFangLevel.GetValue()
		EquipHand=2 ;left
		if (gtempering==1.0) ;the weapon to be equipped is not tempered
			WeaponSwap(tsasciduskblade,adventurerdawnfang,EquipHand)
		elseif (gtempering>1.0) ;the weapon to be equipped is tempered
			int WeaponSwitch=1 ;dawnfang
			SpawnTemperedBlade(WeaponSwitch, gtempering, EquipHand)
		endif
	elseif (PlayerRef.GetItemCount(tsasciduskblade)>0) ;duskfang is in inventory
		NumDuskfang=PlayerRef.GetItemCount(tsasciduskblade)	
		PlayerRef.RemoveItem(tsasciduskblade, NumDuskfang)
	endif
	
endFUNCTION


Function ItsNightTime()

	WeaponFlag=1 ;dawnfang
	;is a tempered dawnfang in the right hand?
	EquipHand=1 ;right
	WeaponEquipped=PlayerRef.GetEquippedWeapon()
	IsATempereredWeaponEquipped=(WeaponIsInTemperedFormList(WeaponFlag, WeaponEquipped, EquipHand))
	if IsATempereredWeaponEquipped==true
		gtempering=DawnFangLevel.GetValue()
		if (gtempering==1.0) ;the weapon to be equipped is not tempered
			WeaponSwap(WeaponEquipped, tsasciduskblade,EquipHand)
		elseif (gtempering>1.0) ;the weapon to be equipped is tempered
			int WeaponSwitch=2 ;duskfang
			SpawnTemperedBlade(WeaponSwitch, gtempering, EquipHand)
		endif
	endif
	
	WeaponFlag=1 ;dawnfang
	;is a tempered dawnfang in the left hand?
	EquipHand=2 ;left
	WeaponEquipped=PlayerRef.GetEquippedWeapon(true)
	IsATempereredWeaponEquipped=(WeaponIsInTemperedFormList(WeaponFlag, WeaponEquipped, EquipHand))
		if IsATempereredWeaponEquipped==true
		gtempering=DawnFangLevel.GetValue()
		if (gtempering==1.0) ;the weapon to be equipped is not tempered
			WeaponSwap(adventurerdawnfang, WeaponEquipped, EquipHand)
		elseif (gtempering>1.0) ;the weapon to be equipped is tempered
			int WeaponSwitch=2 ;duskfang
			SpawnTemperedBlade(WeaponSwitch, gtempering, EquipHand)
		endif
	endif

	;Night time
	if (PlayerRef.GetEquippedWeapon()==adventurerdawnfang) ;dawnfang is equipped (right hand)
		gtempering=DuskFangLevel.GetValue()
		EquipHand=1 ;right
		if (gtempering==1.0) ;the weapon to be equipped is not tempered
			WeaponSwap(adventurerdawnfang,tsasciduskblade,EquipHand)
		elseif (gtempering>1.0) ;the weapon to be equipped is tempered
			int WeaponSwitch=2 ;duskfang
			SpawnTemperedBlade(WeaponSwitch, gtempering, EquipHand)
		endif
	elseif (PlayerRef.GetEquippedWeapon(true)==adventurerdawnfang) ;dawnfang is equipped (left hand)
		gtempering=DuskFangLevel.GetValue()
		EquipHand=2 ;left
		if (gtempering==1.0) ;the weapon to be equipped is not tempered
			WeaponSwap(adventurerdawnfang,tsasciduskblade,EquipHand)
		elseif (gtempering>1.0) ;the weapon to be equipped is tempered
			int WeaponSwitch=2 ;duskfang
			SpawnTemperedBlade(WeaponSwitch, gtempering, EquipHand)
		endif
	elseif (PlayerRef.GetItemCount(adventurerdawnfang)>0) ;dawnfang is in inventory
		NumDawnfang=PlayerRef.GetItemCount(adventurerdawnfang)
		PlayerRef.RemoveItem(adventurerdawnfang, NumDawnfang)
	endif
		
endFunction

Function WeaponIsInTemperedFormList(int rWeaponFlag, Weapon rWeaponEquipped, int WeaponInHand)
	
	bool WeaponFound=false
	
	if rWeaponFlag==1 ;dawnfang
		if WeaponInHand==1 ;right hand
			if DawnfangTemperFormList.HasForm(rWeaponEquipped)
				WeaponFound=True
			else
				WeaponFound=False
			endif
		elseif WeaponInHand==2 ;left hand
			if DawnfangTemperFormList.HasForm(rWeaponEquipped)
				WeaponFound=True
			else
				WeaponFound=False
			endif
		endif
	elseif rWeaponFlag==2 ;duskfang
		if WeaponInHand==1 ;right hand
			if DuskfangTemperFormList.HasForm(rWeaponEquipped)
				WeaponFound=True
			else
				WeaponFound=False
			endif
		elseif WeaponInHand==2 ;left hand
			if DuskfangTemperFormList.HasForm(rWeaponEquipped)
				WeaponFound=True
			else
				WeaponFound=False
			endif
		endif
	endif

	return WeaponFound
	
endFUNCTION 

 



C:\Games\steamapps\common\skyrim\Data\Scripts\Source\DawnDuskTimerScript.psc(250,1): cannot return a bool from weaponisintemperedformlist, the function does not return a value

clearly I return WeaponFound in the function weaponisintemperedformlist. what is wrong here?

EDIT: Forgot to declare the function as bool

edit two:

C:\Games\steamapps\common\skyrim\Data\Scripts\Source\DawnDuskTimerScript.psc(250,1): cannot return a bool from weaponisintemperedformlist, the types do not match (cast missing or types unrelated)
Edited by irswat
Link to comment
Share on other sites

the script works!!!!!!!!!!!!!! It's basically done too I think. Unless some bugs emerge.

feel free to play with this beta and help me find bugs.

to install add with NMM or extract to skyrim folder.

to get blades open console and type 'bat "fang.bat"' without the single quotes.

for anyone interested here is the QuestScript

 

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

GlobalVariable property DawnfangFragCount Auto
GlobalVariable property DuskfangFragCount Auto
GlobalVariable property DawnFangLevel Auto
GlobalVariable property DuskFangLevel Auto
GlobalVariable property GameHour auto

;stores base id of persistent dynamically tempered blades
FormList Property DawnfangTemperFormList Auto
FormList Property DuskfangTemperFormList Auto

Weapon property adventurerdawnfang auto
Weapon property tsasciduskblade auto
Weapon property WeaponEquipped auto
Weapon property rTempWeapon auto

Form property rTempWeapInInv auto

ObjectReference property weaponRef auto


;credit to IsharaMeradin for this
ObjectReference Property FangBladeSpawn Auto
{assign CommonTable01 refID 0006F223 from cell 000161EB SkyHavenTemple }
 
Actor Property PlayerRef Auto

float TimeUntilUpdate
float tempering ;local tempering
float gtempering ;global tempering
float KillLevel ;KillLevel=number of kills/12
float DawnfangKillCount
float DuskfangKillCount
float StoreTemper

int EquipHand=0 ;1=right 2=left
int DayTime=0
int NumDawnfang=0 ;how many in inventory
int NumDuskfang=0 ;how many in inventory
int NumDuplicatesToRemove=0
int WeaponFlag=0
int WeaponSwitch2=0

bool IsATempereredWeaponEquipped=FALSE

string TemperedLevel=""

Event OnInit()
	Utility.Wait(3.0)
	Debug.Notification("Dawnfang and dustfang timer initialized.")
	
	float TimeofDay=GameHour.GetValue() ;thanks to tonycubed2 for this
	;daytime flag & time until update 	
	if (TimeofDay>=6.0 && TimeofDay<18.0)
		DayTime=1
		TimeUntilUpdate=18.0-TimeofDay
	elseif (TimeofDay>=18.0 && TimeofDay<=24.0)
		DayTime=0
		TimeUntilUpdate=24.0-TimeofDay
	elseif (TimeofDay<6.0)
		DayTime=0
		TimeUntilUpdate=6.0-TimeofDay
	endif
	
	RemoveDuplicates(DayTime)
	
	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()
	Main()
endEVENT

event OnUpdate()
	Main()
endEVENT

Function Main()
	Debug.Notification("Main Initialized")
	float TimeofDay=GameHour.GetValue() ;thanks to tonycubed2 for this
	
	;Day time flag & weaponswap
	if (TimeofDay>=6.0 && TimeofDay<18.0)
		DayTime=1
		ItsDayTime()
	elseif ((TimeofDay>=18.0 && TimeofDay<=24.0)||(TimeofDay<6.0))
		DayTime=0
		ItsNightTime()
	endif 
			
	GetUpdateTime()	
endFUNCTION

Function ItsDayTime()

	WeaponFlag=2 ;duskfang
	;is a tempered duskfang in the right hand?
	EquipHand=1 ;right
	WeaponEquipped=PlayerRef.GetEquippedWeapon()
	IsATempereredWeaponEquipped=(WeaponIsInTemperedFormList(WeaponFlag, WeaponEquipped, EquipHand))
	if IsATempereredWeaponEquipped==true
		gtempering=DawnFangLevel.GetValue()
		if (gtempering<=1.0) ;the weapon to be equipped is not tempered
			WeaponSwap(WeaponEquipped,adventurerdawnfang,EquipHand)
		elseif (gtempering>1.0) ;the weapon to be equipped is tempered
			int WeaponSwitch=1 ;dawnfang
			SpawnTemperedBlade(WeaponSwitch, gtempering, EquipHand)
		endif
	endif
	
	
	WeaponFlag=2 ;duskfang
	;is a tempered duskfang in the left hand?
	EquipHand=2 ;left
	WeaponEquipped=PlayerRef.GetEquippedWeapon(true)
	IsATempereredWeaponEquipped=(WeaponIsInTemperedFormList(WeaponFlag, WeaponEquipped, EquipHand))
	if IsATempereredWeaponEquipped==true
		gtempering=DawnFangLevel.GetValue()
		if (gtempering<=1.0) ;the weapon to be equipped is not tempered
			WeaponSwap(WeaponEquipped,adventurerdawnfang,EquipHand)
		elseif (gtempering>1.0) ;the weapon to be equipped is tempered
			int WeaponSwitch=1 ;dawnfang
			SpawnTemperedBlade(WeaponSwitch, gtempering, EquipHand)
		endif
	endif
	
	if(PlayerRef.GetEquippedWeapon()==tsasciduskblade);duskfang is equipped (right hand)
		gtempering=DawnFangLevel.GetValue()
		EquipHand=1 ;right
		if (gtempering<=1.0) ;the weapon to be equipped is not tempered
			WeaponSwap(tsasciduskblade,adventurerdawnfang,EquipHand)
		elseif (gtempering>1.0) ;the weapon to be equipped is tempered
			int WeaponSwitch=1 ;dawnfang
			SpawnTemperedBlade(WeaponSwitch, gtempering, EquipHand)
		endif
	elseif  (PlayerRef.GetEquippedWeapon(true)==tsasciduskblade) ;duskfang is equipped (left hand)
		gtempering=DawnFangLevel.GetValue()
		EquipHand=2 ;left
		if (gtempering<=1.0) ;the weapon to be equipped is not tempered
			WeaponSwap(tsasciduskblade,adventurerdawnfang,EquipHand)
		elseif (gtempering>1.0) ;the weapon to be equipped is tempered
			int WeaponSwitch=1 ;dawnfang
			SpawnTemperedBlade(WeaponSwitch, gtempering, EquipHand)
		endif
	elseif (PlayerRef.GetItemCount(tsasciduskblade)>0) ;duskfang is in inventory
		NumDuskfang=PlayerRef.GetItemCount(tsasciduskblade)	
		PlayerRef.RemoveItem(tsasciduskblade, NumDuskfang)
		PlayerRef.AddItem(adventurerdawnfang,1,false)
	endif
	
	;is a tempered duskfang blade in inventory? if so remove and replace with appropriate blade
	bool TempWeaponFoundInInvFlag=IsTemperedWeaponInInventory(2)
	if TempWeaponFoundInInvFlag
		;add tempered dawnfang if player has earned it'
		gtempering=DawnFangLevel.GetValue()
		if (gtempering<=1.0) ;the weapon to be equipped is not tempered
			PlayerRef.AddItem(adventurerdawnfang,1,false)
		elseif (gtempering>1.0) ;the weapon to be equipped is tempered
			int WeaponSwitch=1 ;dawnfang
			EquipHand=0
			SpawnTemperedBlade(WeaponSwitch, gtempering, EquipHand)
		endif
	endif
	
endFUNCTION


Function ItsNightTime()

	;Night time
	if (PlayerRef.GetEquippedWeapon()==adventurerdawnfang) ;dawnfang is equipped (right hand)
		gtempering=DuskFangLevel.GetValue()
		EquipHand=1 ;right
		if (gtempering<=1.0) ;the weapon to be equipped is not tempered
			WeaponSwap(adventurerdawnfang,tsasciduskblade,EquipHand)
		elseif (gtempering>1.0) ;the weapon to be equipped is tempered
			int WeaponSwitch=2 ;duskfang
			SpawnTemperedBlade(WeaponSwitch, gtempering, EquipHand)
		endif
	elseif (PlayerRef.GetEquippedWeapon(true)==adventurerdawnfang) ;dawnfang is equipped (left hand)
		gtempering=DuskFangLevel.GetValue()
		EquipHand=2 ;left
		if (gtempering<=1.0) ;the weapon to be equipped is not tempered
			WeaponSwap(adventurerdawnfang,tsasciduskblade,EquipHand)
		elseif (gtempering>1.0) ;the weapon to be equipped is tempered
			int WeaponSwitch=2 ;duskfang
			SpawnTemperedBlade(WeaponSwitch, gtempering, EquipHand)
		endif
	elseif (PlayerRef.GetItemCount(adventurerdawnfang)>0) ;dawnfang is in inventory
		NumDawnfang=PlayerRef.GetItemCount(adventurerdawnfang)
		PlayerRef.RemoveItem(adventurerdawnfang, NumDawnfang)
		PlayerRef.AddItem(tsasciduskblade,1,false)
	endif
	
	WeaponFlag=1 ;dawnfang
	;is a tempered dawnfang in the right hand?
	EquipHand=1 ;right
	WeaponEquipped=PlayerRef.GetEquippedWeapon()
	IsATempereredWeaponEquipped=(WeaponIsInTemperedFormList(WeaponFlag, WeaponEquipped, EquipHand))
	if IsATempereredWeaponEquipped==true
		gtempering=DuskFangLevel.GetValue()
		if (gtempering<=1.0) ;the weapon to be equipped is not tempered
			WeaponSwap(WeaponEquipped, tsasciduskblade,EquipHand)
		elseif (gtempering>1.0) ;the weapon to be equipped is tempered
			int WeaponSwitch=2 ;duskfang
			SpawnTemperedBlade(WeaponSwitch, gtempering, EquipHand)
		endif
	endif
	
	WeaponFlag=1 ;dawnfang
	;is a tempered dawnfang in the left hand?
	EquipHand=2 ;left
	WeaponEquipped=PlayerRef.GetEquippedWeapon(true)
	IsATempereredWeaponEquipped=(WeaponIsInTemperedFormList(WeaponFlag, WeaponEquipped, EquipHand))
	if IsATempereredWeaponEquipped==true
		gtempering=DuskFangLevel.GetValue()
		if (gtempering<=1.0) ;the weapon to be equipped is not tempered
			WeaponSwap(adventurerdawnfang, WeaponEquipped, EquipHand)
		elseif (gtempering>1.0) ;the weapon to be equipped is tempered
			int WeaponSwitch=2 ;duskfang
			SpawnTemperedBlade(WeaponSwitch, gtempering, EquipHand)
		endif
	endif
	
	;is a tempered dawnfang blade in inventory? if so remove and replace with appropriate blade
	bool TempWeaponFoundInInvFlag=IsTemperedWeaponInInventory(1)
	if TempWeaponFoundInInvFlag
		;add tempered duskfang if player has earned it'
		gtempering=DuskFangLevel.GetValue()
		if (gtempering<=1.0) ;the weapon to be equipped is not tempered
			PlayerRef.AddItem(tsasciduskblade,1,false)
		elseif (gtempering>1.0) ;the weapon to be equipped is tempered
			int WeaponSwitch=2 ;duskfang
			EquipHand=0
			SpawnTemperedBlade(WeaponSwitch, gtempering, EquipHand)
		endif
	endif
		
endFunction

bool Function IsTemperedWeaponInInventory(int rTempWeapInInvFlag)
	float DawnfangTempWeapInvCheck=DawnFangLevel.GetValue()
	float DuskfangTempWeapInvCheck=DuskFangLevel.GetValue()
	
	if rTempWeapInInvFlag==1 ;dawnfang
		if DawnfangTempWeapInvCheck>1.0
			rTempWeapInInv=DawnfangTemperFormList.GetAt(0)
			Int NumTempDawnfangInInvetory=PlayerRef.GetItemCount(rTempWeapInInv)
			if (NumTempDawnfangInInvetory>0)
				PlayerRef.RemoveItem(rTempWeapInInv, NumTempDawnfangInInvetory)
			endif
		endif
	elseif rTempWeapInInvFlag==2 ;duskfang
		if DuskfangTempWeapInvCheck>1.0
			rTempWeapInInv=DuskfangTemperFormList.GetAt(0)
			Int NumTempDuskfangInInvetory=PlayerRef.GetItemCount(rTempWeapInInv)
			if (NumTempDuskfangInInvetory>0)
				PlayerRef.RemoveItem(rTempWeapInInv, NumTempDuskfangInInvetory)
			endif
		endif
	endif
	
endFunction

bool Function WeaponIsInTemperedFormList(int rWeaponFlag, Form rWeaponEquipped, int WeaponInHand)
	
	bool WeaponFound=false
	
	if rWeaponFlag==1 ;dawnfang
		if WeaponInHand==1 ;right hand
			if DawnfangTemperFormList.HasForm(rWeaponEquipped)
				WeaponFound=True
			else
				WeaponFound=False
			endif
		elseif WeaponInHand==2 ;left hand
			if DawnfangTemperFormList.HasForm(rWeaponEquipped)
				WeaponFound=True
			else
				WeaponFound=False
			endif
		endif
	elseif rWeaponFlag==2 ;duskfang
		if WeaponInHand==1 ;right hand
			if DuskfangTemperFormList.HasForm(rWeaponEquipped)
				WeaponFound=True
			else
				WeaponFound=False
			endif
		elseif WeaponInHand==2 ;left hand
			if DuskfangTemperFormList.HasForm(rWeaponEquipped)
				WeaponFound=True
			else
				WeaponFound=False
			endif
		endif
	endif

	return WeaponFound
	
endFUNCTION

Function SpawnTemperedBlade(int rWeaponSwitch, float rgtempering, int rEquipHand)
	if (rWeaponSwitch==1)
		rTempWeapon=adventurerdawnfang
	elseif (rWeaponSwitch==2)
		rTempWeapon=tsasciduskblade
	endif
	
	;removes old weapon
	PlayerRef.RemoveItem(rTempWeapon,1,true)
	;tempers weapon
	ObjectReference SpawnTemperedWeapon = FangBladeSpawn.PlaceAtMe(rTempWeapon, 1, TRUE)
	SpawnTemperedWeapon.SetItemHealthPercent(rgtempering)
	;adds tempered weapon
	PlayerRef.AddItem(SpawnTemperedWeapon,1,false)
	;equips tempered weapon to proper hand
	if rEquipHand != 0
		PlayerRef.EquipItemEx(SpawnTemperedWeapon.GetBaseObject(),rEquipHand,false,true)
	endif
	
	if (rWeaponSwitch==1)
		if (!DawnfangTemperFormList.HasForm(SpawnTemperedWeapon.GetBaseObject()))
			DawnfangTemperFormList.AddForm(SpawnTemperedWeapon.GetBaseObject())
		endif
	elseif (rWeaponSwitch==2)
		if (!DuskfangTemperFormList.HasForm(SpawnTemperedWeapon.GetBaseObject()))
			DuskfangTemperFormList.AddForm(SpawnTemperedWeapon.GetBaseObject())
		endif
	endif		
endFUNCTION

Function GetUpdateTime()
	float TimeofDay=GameHour.GetValue() ;thanks to tonycubed2 for this
	
	;checks for how long until the script is registered for update	
	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
	
	RegisterForSingleUpdateGameTime(TimeUntilUpdate)
endFUNCTION
	

Function RemoveDuplicates(int TimeFlag)
	;Check for blades in inventory at wrong times, and for duplicates
	NumDawnfang=PlayerRef.GetItemCount(adventurerdawnfang)
	NumDuskfang=PlayerRef.GetItemCount(tsasciduskblade)	
	
	if (TimeFlag==1)
		PlayerRef.RemoveItem(tsasciduskblade, NumDuskfang)
		if (NumDawnfang>1)
			NumDawnfang-=1
			PlayerRef.RemoveItem(adventurerdawnfang, NumDawnfang)			
		endif
	elseif (TimeFlag==0)
		PlayerRef.RemoveItem(adventurerdawnfang, NumDawnfang)
		if NumDuskfang>1
			NumDuskfang-=1
			PlayerRef.RemoveItem(tsasciduskblade, NumDuskfang)
		endif	
	endif
endFunction

;weapon swap function by IsharaMeriden - much thanks
Function WeaponSwap(Form OldWeapon, Form NewWeapon, Int EH)
	PlayerRef.UnequipItem(OldWeapon,true,true)
	PlayerRef.RemoveItem(OldWeapon,1,true)
	PlayerRef.AddItem(NewWeapon,1,false)
	PlayerRef.EquipItemEx(NewWeapon,EH,false,true)
	;Debug.Notification(NewWeapon.GetName()+" has emerged") ;GetName requires SKSE!
EndFunction 

;KillCount function with help from FamilyFrank
Function IncrementKillCount(Bool bIdentity)
	Debug.Notification("Dawnfang and dustfang kill counter initiated")
	If bIdentity ; its dawnfang
		DawnfangFragCount.Mod(1)
		GetKillLevel(bIdentity)
	Else ; its duskfang
		DuskfangFragCount.Mod(1)
		GetKillLevel(bIdentity)
	Endif
EndFunction

;This gets the associated tempering level of the blase. One level per twelve kills, up to 144
Function GetKillLevel(Bool bIdentity)

	if bIdentity==true ;dawnfang
		WeaponSwitch2=1
	else ;duskfang
		WeaponSwitch2=2
	endif
	
	if PlayerRef.GetEquippedWeapon()==tsasciduskblade
		EquipHand=1 ;right hand
		KillLevel=(DuskfangFragCount.GetValue()/12)
		DuskfangKillCount=(DuskfangFragCount.GetValue())
		;Debug.Notification("Duskfang kill count:" + DuskfangKillCount + "Duskfang kill level:" + KillLevel)
		if (KillLevel==KillLevel As Int) && (DuskfangKillCount<=72)
			tempering=1+(KillLevel*0.1)
			DuskFangLevel.SetValue(tempering)
			SpawnTemperedBlade(WeaponSwitch2, tempering, EquipHand)
		endif
	elseif PlayerRef.GetEquippedWeapon(true)==tsasciduskblade
		EquipHand=2 ;left hand
		KillLevel=(DuskfangFragCount.GetValue()/12)
		DuskfangKillCount=DuskfangFragCount.GetValue()
		;Debug.Notification("Duskfang kill count:" + DuskfangKillCount + "Duskfang kill level:" + KillLevel)
		if (KillLevel==KillLevel As Int) && (DuskfangKillCount<=72)
			tempering=1+(KillLevel*0.1)
			DuskFangLevel.SetValue(tempering)
			SpawnTemperedBlade(WeaponSwitch2, tempering, EquipHand)
		endif
	elseif PlayerRef.GetEquippedWeapon()==adventurerdawnfang
		EquipHand=1 ;right hand
		KillLevel=(DawnfangFragCount.GetValue()/12)
		DawnfangKillCount=DawnfangFragCount.GetValue()
		;Debug.Notification("Dawnfang kill count:" + DawnfangKillCount + "Dawnfang kill level:" + KillLevel)
		if (KillLevel==KillLevel As Int) && (DawnfangKillCount<=72)
			tempering=1+(KillLevel*0.1)
			DawnFangLevel.SetValue(tempering)
			SpawnTemperedBlade(WeaponSwitch2, tempering, EquipHand)
		endif
	elseif PlayerRef.GetEquippedWeapon(true)==adventurerdawnfang
		EquipHand=2 ;left hand
		KillLevel=(DawnfangFragCount.GetValue()/12)
		DawnfangKillCount=DawnfangFragCount.GetValue()
		;Debug.Notification("Dawnfang kill count:" + DawnfangKillCount + "Dawnfang kill level:" + KillLevel)
		if (KillLevel==KillLevel As Int) && (DawnfangKillCount<=72)
			tempering=1+(KillLevel*0.1)
			DawnFangLevel.SetValue(tempering)
			SpawnTemperedBlade(WeaponSwitch2, tempering, EquipHand)
		endif
	endif
EndFunction

Function UpdateFangQuest()
	Debug.Notification("Item added. Fangblade updated")
	RegisterForSingleUpdate(1)
ENDFunction

 

 

 

459 lines. special thanks to paladingard, family frank, and IsharaMeriden. Without you guys I couldn't have done this.

My first skyrim script finished!

EDIT: Let me know if you notice severe performance issues with this. I personally didn't but the guy who created the mod - ZurinArctus, he reported severe HDD thrashing which he attributed to my script. I'm thinking the script maybe is being called too often. Perhaps the RefAlias script is the cause:

 

Scriptname FangBladeRefAliasScript extends ReferenceAlias  

;script with help from IsharaMeradin
DawnDuskTimerScript Property DDT Auto 
Weapon Property adventurerdawnfang Auto
Weapon Property tsasciduskblade Auto

FormList Property DawnfangTemperFormList Auto
FormList Property DuskfangTemperFormList Auto

Event OnInit()
    AddInventoryEventFilter(adventurerdawnfang) 
    AddInventoryEventFilter(tsasciduskblade)
	AddInventoryEventFilter(DawnfangTemperFormList)
	AddInventoryEventFilter(DuskfangTemperFormList)
	;Debug.Notification("Dawnfang and dustfang Event Filter initialized.")
EndEvent

Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
    If !akSourceContainer   ;picked up for the first time from the world space i.e. not from a container or npc
	Debug.Notification("Debug: ITEM ADDED: " + akBaseItem)
	Debug.Notification("Debug: ITEM ADDED: " + akItemReference.GetBaseObject().GetName())
        DDT.UpdateFangQuest(1)
    endif   
endEVENT

;make sure this is running on quest start

 



http://i66.tinypic.com/1y7tpz.jpg



maybe it's the references reserve or allow reuse flags?

Edited by irswat
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.

×
×
  • Create New...