Jump to content

Please help me get this simple script working


irswat

Recommended Posts

next update: Must get 12 kills every 12 hours to keep blade tempered. This should be fun.

there is another version of the dawn/dusk fang made by teh masterer, and after working on this so much I broke his on the first try. :-)

Edited by irswat
Link to comment
Share on other sites

  • Replies 135
  • Created
  • Last Reply

Top Posters In This Topic

UPDATE:

patched up a potential "memory leak" in the ref alias inventory filter script. (palingard foresaw this and warned me but I didn't take his warning serious.)

 

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

int WeapFlag

Bool TempDawnfangWeapFound=false
Bool TempDuskfangWeapFound=false

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)

	TempDawnfangWeapFound=DDT.IsTemperedWeaponInInventory(1)
	TempDuskfangWeapFound=DDT.IsTemperedWeaponInInventory(2)
	
	if (akBaseItem==adventurerdawnfang) || (akBaseItem==tsasciduskblade) || TempDawnfangWeapFound || TempDuskfangWeapFound
		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   
	endif
endEVENT

;make sure this is running on quest start

 



New function that will hopefully achieve the effect of removing the tempered blade if 12 kills are not achieved every 12 hours. I think I am going to write an MCM menu for this with a complex dynamic scaling for these blades that can be toggled for increased difficulty. However, the mod author doesn't want this to be the default setting so I will forgo it for now.

New function removes tempered blades if 12 kills are not achieved:

 

Function RevokeTemperedBlade()

	float TimeofDay=GameHour.GetValue() ;thanks to tonycubed2 for this
	
	;Day time flag & weaponswap
	if (TimeofDay>=6.0 && TimeofDay<18.0)
		DayTime=1
	elseif ((TimeofDay>=18.0 && TimeofDay<=24.0)||(TimeofDay<6.0))
		DayTime=0
	endif 
			
	if Daytime==1 && NighttimeFragCount.GetValue()<12
		DawnFangLevel.SetValue(0)
		DaytimeFragCount.SetValue(0)
		DawnfangTemperFormList.Revert()
	elseif Daytime==0 && DaytimeFragCount.GetValue()<12
		DuskFangLevel.SetValue(0)
		DaytimeFragCount.SetValue(0)
		DuskfangTemperFormList.Revert()
	endif
	
endFunction

 



I thought it was an efficient and novel approach to achieving the intended results that leverages the current dynamic of the script to keep this function simple.

 

 

;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
	
	RevokeTemperedBlade()
	
	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

 



I'm calling this new function from the GetKillLevel function before tempering is calculated.

Edited by irswat
Link to comment
Share on other sites

Out of curiosity...

Are the weapons supposed to lose all tempering if there aren't enough kills? I'd be a bit upset if I'd worked hard to get it to one step away from max and for whatever reason wasn't able to get that 12th kill in. Might be trickier to achieve but a gradual decrease in temper level may be worth considering.

Link to comment
Share on other sites

I agree with Ishara, you could probably just implement the reverse tempering to drop the temper down incrementally for every 12 hours that doesn't achieve the proper kills. This is extremely important for players that play with mods like Living Takes Time, you can lose 12 hours just creating a couple of pieces of armor.

Link to comment
Share on other sites

Like I said the mod author wants it a specific way and that's how I'm going to script it, but I think I will include an MCM menu with some options. It will give me a chance to learn how to make MCM mods too. Thanks for your help guys.

If this works I'm going to be very excited because I feel like it was a clever and efficient way to tackle the problem of implementing the feature post facto.

basically during the day it checks the number of kills you got the night before, and at night it checks the number of kills you got the day before. If not at least twelve it simply resets those variables. Although I will need to call the function somewhere else because the getkilllevel function is only called after a kill, so for example if the player simply has the blade in their inventory for days on end, the function to revoke the tempered blade will never trigger.

Link to comment
Share on other sites

 

 

EVENT OnUpdateGameTime()
	Main()
endEVENT

event OnUpdate()
	Main()
endEVENT

Function Main()
	Debug.Notification("Main Initialized")
	float TimeofDay=GameHour.GetValue() ;thanks to tonycubed2 for this
	
	RevokeTemperedBlade()
	
	;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

 



that's basically what I did. Still need to test it.

Edited by irswat
Link to comment
Share on other sites

I love when I break a script that was formerly working.

It was the case that I could take the dawnfang throw it on the ground, wait until night time, pick it up, and it would trigger the OnItemAdded event update causing the dawnfang to be removed and replaced with the duskfang. I received a report of hard drive thrashing by ZurinArctus which I guessed was caused by some sort OnItemAdded event loop, so I added a conditional statement to prevent the script from firing unless it is possible that the item added was one of the fang blades (either dawnfang, duskfang, or one of the tempered variants.) Since I added this conditional statement the OnItemAdded the script is no longer detecting when a fangblade is added to inventory, as such in the above described test the incorrect blade is not removed and replaced with the correct blade.

Also. I am concerned that the function I wrote to check a players whether a persistent temperedblade reference is in the players inventory. When I goto fill the property in the CK I have these two options:

http://i67.tinypic.com/11ag6x5.jpg



I'm not sure which option to choose, or whether I should choose none.

My concern is that palingard was correct earlier when he suspected this method would not work even though I am using the persistent reference flag for the tempered blade. I have a trick up my sleeve if this is the case, it involves moving the blades and putting them in a hidden container somewhere when they are removed, but I could use some help.

Here are the OnItemAdded ref alias script, and the function that determines whether a tempered blade is in the players inventory

 

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

int WeapFlag

Bool TempDawnfangWeapFound=false
Bool TempDuskfangWeapFound=false

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)

	TempDawnfangWeapFound=DDT.IsTemperedWeaponInInventory(1)
	TempDuskfangWeapFound=DDT.IsTemperedWeaponInInventory(2)
	
	if (akBaseItem==adventurerdawnfang) || (akBaseItem==tsasciduskblade) || (TempDawnfangWeapFound==true) || (TempDuskfangWeapFound==true)
		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()
		endif   
	endif
endEVENT

;make sure this is running on quest start 

 


bool Function IsTemperedWeaponInInventory(int rTempWeapInInvFlag)

float DawnfangTempWeapInvCheck=DawnFangLevel.GetValue()
float DuskfangTempWeapInvCheck=DuskFangLevel.GetValue()
bool TemperedWeaponFoundInInv=false
if rTempWeapInInvFlag==1 ;dawnfang
if DawnfangTempWeapInvCheck>1.0
rTempWeapInInv=DawnfangTemperFormList.GetAt(0)
Int NumTempDawnfangInInvetory=PlayerRef.GetItemCount(rTempWeapInInv)
if (NumTempDawnfangInInvetory>0)
TemperedWeaponFoundInInv=true
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)
TemperedWeaponFoundInInv=true
PlayerRef.RemoveItem(rTempWeapInInv, NumTempDuskfangInInvetory)
endif
endif
endif
return TemperedWeaponFoundInInv

endFunction

 

Edited by irswat
Link to comment
Share on other sites

If you will be assigning a variable with a value in script, you do not need to set it up as a property

 

i.e. Instead of

Form Property SomeForm Auto

you can do

Form SomeForm

 

If you are needing to reference that variable on another script, you will need to set it up as a property but you can hide it so that the CK doesn't see it.

i.e.

Form Property SomeForm Auto Hidden

 

That might help with the property question you had. As far as the other stuff, I'm not sure. I'm not seeing anything at the moment.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.

×
×
  • Create New...