Jump to content

Please help me get this simple script working


irswat

Recommended Posts

yes that's what I meant. :-) I thought declaring the property with the same name as the form was enough for it to autofill going by cipscis tutorial. Now I need to do the killcounter which i think will be something like:

GlobalVariable Property DawnfangFragCount Auto
GlobalVariable Property DuskfangFragCount Auto
 
if PlayerRef.IsInCombat()
string combatTarget=PlayerRef.GetCombatTarget()
if (combatTarget.IsDead() && victim==combatTarget && killer==PlayerRef)
DuskfangFragCount+=1
endif
endif

And then divide by 12 to see if bloodlust is satisfied.
Link to comment
Share on other sites

  • Replies 135
  • Created
  • Last Reply

Top Posters In This Topic

Scriptname DawnDuskTimerScript extends Quest  
{Prevents dawnfang and duskfang from being equipped at wrong times}
;;special thanks to IsharaMeradin && FamilyFrank for their patience and support!
import utility
import debug
import sound

Weapon property adventurerdawnfang auto
Weapon property tsasciduskblade auto

Actor Property PlayerRef Auto
Actor Property combatTarget Auto
Actor Property victim Auto
Actor Property killer Auto


GlobalVariable property GameHour auto
GlobalVariable property DawnfangFragCount Auto
GlobalVariable property DuskfangFragCount Auto



EVENT OnInit()
	Debug.Notification("Dawnfang and dustfang timer initiated")
	RegisterForUpdate(2)
	
endEVENT

EVENT OnUpdate()
	float TimeofDay=GameHour.GetValue()
	PlayerRef=Game.GetPlayer()
	;Debug.Notification("Dawnfang and dustfang timer update check " + TimeofDay)
		if (TimeofDay>=6.0 && TimeofDay<18.0)
			if ((PlayerRef.GetEquippedWeapon()==tsasciduskblade)||(PlayerRef.GetEquippedWeapon(true)==tsasciduskblade))
				PlayerRef.UnequipItem(tsasciduskblade,true,true)
				;Debug.Notification("You cannot equip Duskfang during the day")
				PlayerRef.EquipItem(adventurerdawnfang,false,true)
				;\Debug.Notification("Dawnfang has emerged")
				if PlayerRef.IsInCombat()
					combatTarget=PlayerRef.GetCombatTarget()
					if (combatTarget.IsDead() && victim==combatTarget && killer==PlayerRef)
						DawnfangFragCount.SetValue(DawnfangFragCount.GetValue() + 1)
					endif
				endif
					
			endif
		elseif ((TimeofDay>=18.0 && TimeofDay<24.0)||(TimeofDay<6))
			if ((PlayerRef.GetEquippedWeapon()==adventurerdawnfang)||(PlayerRef.GetEquippedWeapon(true)==adventurerdawnfang))
				PlayerRef.UnequipItem(adventurerdawnfang,true,true)
				;Debug.Notification("You cannot equip Dawnfang during the night")
				PlayerRef.EquipItem(tsasciduskblade,false,true)
				Debug.Notification("Duskfang has emerged")
				if PlayerRef.IsInCombat()
					combatTarget=PlayerRef.GetCombatTarget()
					if (combatTarget.IsDead() && victim==combatTarget && killer==PlayerRef)
						DuskfangFragCount.SetValue(DuskfangFragCount.GetValue() + 1)
					endif
				endif
			endif
		endif
endEVENT

I got this to compile, but am I using killer and victim correctly? Do I declare these as properties? Do I need to pass them to OnUpdate as actors?

Edited by irswat
Link to comment
Share on other sites

Why are you even using killer and victim? Unless you want it to work with a specific NPC, I see no reason to go to the trouble of using them.

 

And anything that is defined in the empty state is available to every event and function on the script.

how else could I accomplish this? Killcount should only go up if the actor is killed by player equipped with dawnfang or duskfang. Is there another way? Is there a downside to doing it this way?

 

I just put some debug code in there and it doesn't appear to be working. So how would you suggest I achieve this?

Edited by irswat
Link to comment
Share on other sites

You do have a problem with your script. You are using RegisterForUpdate. This particular update will never stop unless you properly un-register. This means if the user uninstalls your mod without the un-register being able to be called it will still try to run. In the long run it would cause excess bloating to the papyrus log and possibly even the save game. It is better to use RegisterForSingleUpdate and re-register when needed.

 

******

In the long run, I think you'd be better off with a multi-script approach. Use a player alias script to handle which weapon is supposed to be equipped and set a global variable that can be used to indicate which is equipped to other scripts. Then dynamically attach scripts to enemy combat actors which can use the OnDeath and OnHit events to rack up the kill counts.

Link to comment
Share on other sites

Wiki says it will automatically unregister if the quest is stopped properly i.e. calling Stop() on that quest.. But if the user should just decide to remove the mod, it won't be properly stopped. The way to unregister when you no longer need to use it is with UnRegisterForUpdate().

 

Just be sure that you are aware of the warnings for RegisterForUpdate: http://www.creationkit.com/index.php?title=RegisterForUpdate_-_Form#Important_Warning

Link to comment
Share on other sites

I did read it and am thinking about how I can achieve the same perpetual vigilance without needing to use OnUpdate. Maybe I can get rid of the quest script. I only added it because the script wasn't working when I had the script attached to the weapon in OnEquipped. Then I found out I needed to manually register the properties in CK, and that my logic was incorrect, and so perhaps the quest script is an unnecessary redundancy. Thanks for the heads up.

Can I use OnDeath and OnHit from an object reference script attached to a weapon?

Link to comment
Share on other sites

I got an idea!

        if (TimeofDay>6 && TimeofDay<18)
		TimeUntilUpdate=18-TimeofDay
	elseif (TimeofDay>18 && TimeofDay<=24)
		TimeUntilUpdate=24-TimeofDay
	elseif (TimeofDay<6)
		TimeUntilUpdate=6-TimeofDay
	endif
	Debug.Notification("Gametime until update" + TimeUntilUpdate)
	TimeUntilUpdate=TimeUntilUpdate/timescale.GetValue()
	Debug.Notification("Realtime until update" + TimeUntilUpdate)
	RegisterForSingleUpdate(TimeUntilUpdate)
Edited by irswat
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.

×
×
  • Create New...