Scripting Help - Referencing the Player

Post » Sat Nov 17, 2012 9:54 am

Background: I know how to write scripts and code, but am unfamiliar with the CreationKit. I'm trying to write a realistic encumbrance mod which will require the player to use backpacks, bags, pouches, and bandoliers in order to carry items that they do not have equipped. The goal is to limit the amount of weight of items that can be carried (but not of items that are equipped). In order to do this, I need to adjust the player's maximum carryweight depending upon the total weight of equipped items.

Problem: I need to utilize several Actor script Events as they occur on the Player (OnInit, OnPlayerLoadGame, OnObjectEquipped, OnObjectUnequipped). However, I have the feeling that attaching the script directly to the Player actor in the Creation Kit is not the correct way to do this. Can someone please tell me what the correct method of accomplishing what I intend would be done in the CreationKit?

Example Script:
Scriptname CarryWeightScript extends ActorGlobalVariable Property EquippedItemWeightTracker AutoEvent OnOnit  Game.GetPlayer().UnequipAll()  EquippedItemWeightTracker.SetValue( 0.0 )  UpdateCarryWeight()EndEventEvent OnPlayerLoadGame()  UpdateCarryWeight()EndEventEvent OnObjectEquipped(Form akBaseObject, ObjectReference akReference)  Float ItemWeight = akBaseObject.GetWeight() as Float  EquippedItemWeightTracker.Mod( ItemWeight )  UpdateCarryWeight()EndEventEvent OnObjectEquipped(Form akBaseObject, ObjectReference akReference)  Float ItemWeight = akBaseObject.GetWeight() as Float  ItemWeight *= -1.0  EquippedItemWeightTracker.Mod( ItemWeight )  UpdateCarryWeight()EndEventFuntion UpdateCarryWeight()  Float CarryWeight = EquippedItemWeightTracker.GetValue() as Float  CarryWeight += 10.0 ; Allow only 10 units of items to be carried beyond what is equipped.  Game.GetPlayer().SetActorValue("CarryWeight", CarryWeight )EndFunction
User avatar
M!KkI
 
Posts: 3401
Joined: Sun Jul 16, 2006 7:50 am

Post » Sat Nov 17, 2012 12:06 pm

I'm pretty sure the correct way is adding a script to a ReferenceAlias that points the player character. You're right that adjusting the player is not recommended, because if everyone would do that a lot of mods would conflict.

http://www.creationkit.com/Alias

I haven't worked much yet with Alias stuff but this should get you going.
User avatar
Jordan Moreno
 
Posts: 3462
Joined: Thu May 10, 2007 4:47 pm

Post » Sat Nov 17, 2012 11:46 pm

So, I created a Quest and a GlobalVariable in the CreationKit.

The Quest is set with Start Game Enabled, Run Once, and Warn On Alias Fill Failure.

I then created a Quest Alias with the Fill Type of Specific Reference. Cell: [any], Ref: PlayerRef ( 'Player' ).

I then attached the following script to the Reference Alias:
Scriptname SkyRealismCarryweightPlayerScript extends ObjectReference  GlobalVariable Property SkyRealismEquippedItemsWeight  Auto  Function UpdateCarryWeight()  Float CarryWeight = SkyRealismEquippedItemsWeight.GetValue() as Float  CarryWeight += 10.0 ; Allow only 10 units of items to be carried beyond what is equipped.  Game.GetPlayer().SetActorValue("CarryWeight", CarryWeight )EndFunctionEvent OnOnit()  Game.GetPlayer().UnequipAll()  SkyRealismEquippedItemsWeight.SetValue( 0.0 )  UpdateCarryWeight()EndEventEvent OnPlayerLoadGame()  UpdateCarryWeight()EndEventEvent OnObjectEquipped(Form akBaseObject, ObjectReference akReference)  Float ItemWeight = akBaseObject.GetWeight() as Float  SkyRealismEquippedItemsWeight.Mod( ItemWeight )  UpdateCarryWeight()EndEventEvent OnObjectUnequipped(Form akBaseObject, ObjectReference akReference)  Float ItemWeight = akBaseObject.GetWeight() as Float  ItemWeight *= -1.0  SkyRealismEquippedItemsWeight.Mod( ItemWeight )  UpdateCarryWeight()EndEvent

Everything compiled. I saved the plugin and then activated it in my data files list.

However, nothing is happening in Skyrim. Anyone have a clue as to why?
User avatar
BlackaneseB
 
Posts: 3431
Joined: Sat Sep 23, 2006 1:21 am

Post » Sat Nov 17, 2012 5:48 pm

Aha, solved it.

The script must extend ReferenceAlias in order to correctly reference the Player.
User avatar
Beast Attire
 
Posts: 3456
Joined: Tue Oct 09, 2007 5:33 am

Post » Sat Nov 17, 2012 7:13 pm

Scripts attached to Reference Aliases must extend ReferenceAlias in order to function.

You won't need to change anything save the extension declaration, ReferenceAlias scripts inherit all events and functions from the ObjectReference and Actor scripts.
User avatar
FABIAN RUIZ
 
Posts: 3495
Joined: Mon Oct 15, 2007 11:13 am


Return to V - Skyrim