Jump to content

Please help me get this simple script working


irswat

Recommended Posts

ak for Actor

b for bool

i for int

s for string

 

You do not have to follow that convention. All that matters is that you know what you are using for what.

 

 

Here is one solution:

 

Add this script to the container that is holding the weapons

 

 

ScriptName	WeaponHoldingBagScript	Extends	ObjectReference

Weapon 			Property 	myDayWeapon		Auto
Weapon 			Property 	myNightWeapon	Auto
Actor 			Property 	PlayerRef		Auto
GlobalVariable 	Property 	GameHour 		Auto

Bool 	PlayerTook = false

Function AddCorrectWeapon()
	float TimeofDay = GameHour.GetValue()
	if (TimeofDay>=6.0 && TimeofDay<18.0)
		;remove the weapon for opposite time frame and check to make sure that the correct is present
		;if not present add a new one
		(Self as ObjectReference).RemoveItem(myNightWeapon,1)
		If (Self as ObjectReference).GetItemCount(myDayWeapon) <= 0
			(Self as ObjectReference).AddItem(myDayWeapon,1)
		EndIf
	elseif (TimeofDay>=18.0 && TimeofDay<=24.0) || (TimeofDay<6.0)
		;remove the weapon for opposite time frame and check to make sure that the correct is present
		;if not present add a new one
		(Self as ObjectReference).RemoveItem(myDayWeapon,1)
		If (Self as ObjectReference).GetItemCount(myNightWeapon) <= 0
			(Self as ObjectReference).AddItem(myNightWeapon,1)
		EndIf
	endif
EndFunction

Event OnCellAttach()
	If PlayerTook == false
		AddCorrectWeapon()
	EndIf
EndIf

Event OnActivate(ObjectReference akActionRef)
	If akActionRef == PlayerRef && PlayerTook == false
		AddCorrectWeapon()
	EndIf
EndEvent

Event OnItemRemoved(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)
	If (akBaseItem == myDayWeapon || akBaseItem == myNightWeapon) && (akDestContainer == PlayerRef) && (PlayerTook == false)
		PlayerTook = true
	EndIf
EndEvent 

 

 

You don't have to do it that way either. You can use OnContainerChanged which FrankFamily linked to which would be on the weapon itself.

 

You can also use OnItemAdded event on a player alias script with the akSourceContainer being equal to the container that the weapons come in.

 

 

EDIT: grammar change for clarity

Edited by IsharaMeradin
Link to comment
Share on other sites

  • Replies 135
  • Created
  • Last Reply

Top Posters In This Topic

I think this should do it:

 

Scriptname FangContainerScript extends ObjectReference  

GlobalVariable property GameHour auto

Weapon property adventurerdawnfang auto
Weapon property tsasciduskblade auto

ObjectReference property weaponRef auto

Actor Property PlayerRef Auto

int DayTime=0
int NumDawnFang=0
int NumDuskFang=0

event OnCellLoad()
	
		RegisterForSingleUpdateGameTime(1)
	
endEVENT

event OnUpdate()
	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
	
	;Check for blades in inventory at wrong times, and for duplicates
	NumDawnfang=(self as ObjectReference).GetItemCount(adventurerdawnfang)
	NumDuskfang=(self as ObjectReference).GetItemCount(tsasciduskblade)	
	
	if (DayTime==1)
		(self as ObjectReference).RemoveItem(tsasciduskblade, NumDuskfang)
		if (NumDawnfang>1)
			NumDawnfang-=1
			(self as ObjectReference).RemoveItem(adventurerdawnfang, NumDawnfang)
		elseif (NumDawnfang==0)
			(self as ObjectReference).AddItem(adventurerdawnfang,1)
		endif
	elseif (DayTime==0)
		(self as ObjectReference).RemoveItem(adventurerdawnfang, NumDawnfang)
		if NumDuskfang>1
			NumDuskfang-=1
			(self as ObjectReference).RemoveItem(tsasciduskblade, NumDuskfang)
		elseif (NumDuskfang==0)
			(self as ObjectReference).AddItem(tsasciduskblade,1)
		endif	
	endif
	
	if ((TimeuntilUpdate<=1.0) || TimeofDay==6.0 || TimeofDay==18.0)
		RegisterForSingleUpdateGameTime(1)
	endif
	
	RegisterForSingleUpdateGameTime(TimeUntilUpdate)
endEVENT

Event OnItemRemoved(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)

	if (akBaseItem==adventurerdawnfang) || (akBaseItem==tsasciduskblade)
		UnregisterForUpdate()
	endif		
	
endEVENT

Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)

	if (akBaseItem==adventurerdawnfang) || (akBaseItem==tsasciduskblade)
		RegisterForSingleUpdate(1)
	endif		
	
endEVENT

event OnUnload()
	UnregisterForUpdate()
endEVENT 

 

 

Edited by irswat
Link to comment
Share on other sites

Just keep in mind that OnCellLoad isn't called all the time. As I understand it, it is only called when the cell is first loaded and not called again until the cell has been reset. OnCellAttach may be the better choice in this instance. At least it might be worth testing. Unless that is what you are doing with the call to update, but if that is the case, where is the OnUpdate event? Also, you'll want some way to stop it once the player has taken the weapon. After all, the container doesn't need to keep swapping weapons once the player has gotten theirs.

Link to comment
Share on other sites

sorry I have a tendency to realize I did stupid stuff and change the post underneath your feet. :-)

I will make the revision regarding OnCellAttach() as opposed to OnCellLoad(). Although I'm wondering if I need to with the OnUpdate() now that you mention it.

I'll just change it. Better to be safe than sorry.

Edited by irswat
Link to comment
Share on other sites

random question: will the 64 bit remaster up the limit on the number of plugins we're allowed to use?

another random question: I'm thinking it might be cool to do a signature weapon mod, and have something like the perk tree just for the signature weapon.

How hard is it to duplicate the perk tree? If impossible could I create a weapon perk tree off the side of the current perk tree, but make it so the weapon perk tree can not be accessed via the normal perk tree menu, and the normal perk tree via the weapon perk tree menu?

Link to comment
Share on other sites

just noticed that. I must have added that by accident. The file is updated and that script removed. I also removed the duplicate playerref=game.getplayer

modifying that script was my first attempt at skyrim modding. wanted to make the wispmother wear a crown when she conjured summons to make it easy to tell them apart. Apparently that isn't possible because it's a creature not an NPC. :-/

I'm done for the day. Thank you so much for taking an interest in this little project. I can't imagine how annoying it must be.

Edited by irswat
Link to comment
Share on other sites

disregard the container script. neither your nor mine works, and I suspect it is the events we are using. Nevertheless it doesn't matter because the method of acquiring the blade is now more immersive and lore friendly.

I do have a small problem.

After the script tempers the blade, and adds it to the players inventory, which seems to work wonderfully btw (thanks), I call EquipItemEx with it, but this function is not working. The reason I presume is because it is expecting a base object and I'm passing an ObjectReference. Is there a work around like (weaponRef as Form) so that I can use EquipItemEx on the tempered weapon?

recall the function:

 

Function TemperWeapon(float btempering, Form myWeapon, bool WeapRef, int EH)
	ObjectReference tweaponRef = FangBladeSpawn.PlaceAtMe(myWeapon, 1)
	tweaponRef.SetItemHealthPercent(1 +btempering)
	Debug.Notification(tweaponRef.GetBaseObject().GetName() + " tempering level" + (1 + btempering))
	if (btempering==0.1)
		TemperedLevel="Fine "
	elseif (btempering==0.2)
		TemperedLevel="Superior "
	elseif (btempering==0.3)
		TemperedLevel="Exquisite "
	elseif (btempering==0.4)
		TemperedLevel="Flawless "
	elseif (btempering==0.5)
		TemperedLevel="Epic "
	elseif (btempering==0.6)
		TemperedLevel="Legendary "
	endif
	if (WeapRef== true) ;true=dawnfang false=duskfang
		PlayerRef.RemoveItem(adventurerdawnfang)
		PlayerRef.AddItem(tweaponRef,1,false)
		PlayerRef.EquipItemEx(tweaponRef,EH,false,true)
		Debug.Notification(TemperedLevel + tweaponRef.GetBaseObject().GetName() + " has been added!")
	else
		PlayerRef.RemoveItem(tsasciduskblade)
		PlayerRef.AddItem(tweaponRef,1,false)
		PlayerRef.EquipItemEx(tweaponRef,EH,false,true)
		Debug.Notification(TemperedLevel + tweaponRef.GetBaseObject().GetName() + " has been added!")
	endif
	
EndFunction  

 

 

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.

×
×
  • Create New...