Jump to content

Please help me get this simple script working


irswat

Recommended Posts

  • Replies 135
  • Created
  • Last Reply

Top Posters In This Topic

;this function adds persistent tempered blade forms to a form list for inventory filtering
Function AddTemperedBladeToFormList(bool WeapSwitch,float temperinglevel,ObjectReference WhichBlade)
	if WeapSwitch==true
		; BladeIndexSize=DawnfangTemperFormList.GetSize()
		DawnfangTemperFormList.AddForm(WhichBlade.GetBaseObject())
	else
		;int BlaseIndexSize=DuskfangTemperFormList.GetSize()
		DuskfangTemperFormList.AddForm(WhichBlade.GetBaseObject())
	endif	
endFunction


here is the refalias script

 

 

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)
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
        DDT.UpdateFangQuest(1)
    endif   
endEVENT

;make sure this is running on quest start
Link to comment
Share on other sites

If I add a formlist to an inventoryeventfilter do I need a loop to call AddInventoryEventFilter(Formlist(index)) for every form in the list, or can I simply call AddInventoryEventFilter(FormList()) and papyrus handles the rest?

You can simply call the formlist in the inventory event filter. But since that is what you have in your code posted after the above quoted post, you probably already figured that out. :P

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

I have cleaned the code up much.

 

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

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

bool

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()
	if(PlayerRef.GetEquippedWeapon()==tsasciduskblade) ;duskfang is equipped (right hand)
		gtempering=DawnFangLevel.GetValue()
		EquipHand=1
		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
			SpawnTemperedWeapon(WeaponSwitch, gtempering, EquipHand)
		endif
	elseif  (PlayerRef.GetEquippedWeapon(true)==tsasciduskblade) ;duskfang is equipped (left hand)
		gtempering=DawnFangLevel.GetValue()
		EquipHand=2
		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
			SpawnTemperedWeapon(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()
	;Night time
	if (PlayerRef.GetEquippedWeapon()==adventurerdawnfang) ;dawnfang is equipped (right hand)
		gtempering=DuskFangLevel.GetValue()
		EquipHand=1
		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
			SpawnTemperedWeapon(WeaponSwitch, gtempering, EquipHand)
		endif
	elseif (PlayerRef.GetEquippedWeapon(true)==adventurerdawnfang) ;dawnfang is equipped (left hand)
		gtempering=DuskFangLevel.GetValue()
		EquipHand=2
		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
			SpawnTemperedWeapon(WeaponSwitch, gtempering, EquipHand)
		endif
	elseif (PlayerRef.GetItemCount(adventurerdawnfang)>0) ;dawnfang is in inventory
		NumDawnfang=PlayerRef.GetItemCount(adventurerdawnfang)
		PlayerRef.RemoveItem(adventurerdawnfang, NumDawnfang)
endFunction

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 SpawnTemperedWeapon = FangBladeSpawn.PlaceAtMe(rTempWeapon, 1, TRUE)
	SpawnTemperedWeapon.SetItemHealthPercent(btempering)
	;adds tempered weapon
	PlayerRef.AddItem(SpawnTemperedWeapon,1,false)
	;equips tempered weapon to proper hand
	PlayerRef.EquipItemEx(SpawnTemperedWeapon.GetBaseObject(),EH,false,true)
	
	if (rWeaponSwitch==1)
		if (!DawnfangTemperFormList.HasForm(SpawnTemperedWeapon.GetBaseObject()))
			DawnfangTemperFormList.AddForm(SpawnTemperedWeapon.GetBaseObject())
		endif
	elseif (rWeaponSwitch==2)
		if (!DuskfangTemperFormList.HasForm(SpawnTemperedWeapon.GetBaseObject()))
			DuskfangTemperFormList.AddForm(pawnTemperedWeapon.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
		int WeaponSwitch2=1
	else ;duskfang
		int 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)
			SpawnTemperedWeapon(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)
			SpawnTemperedWeapon(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)
			SpawnTemperedWeapon(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)
			SpawnTemperedWeapon(WeaponSwitch2, tempering, EquipHand)
		endif
	endif
EndFunction

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

 

 



Still haven't gotten the OnItemAdded functionality working because I had some weird logical loopholes going on that was preventing conditional statements from triggering. Thus why I had to rewrite the code.

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.

Edited by irswat
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.

×
×
  • Create New...