Jump to content

Scripting is confusing.


revarost

Recommended Posts

I'm not sure which forum to post this in, so here we go...

 

I'm trying to have a script attached to a misc item, which will give the player an item when they click it in their inventory. Unfortunately, google is not helping, and every example script I can find is pointlessly confusing and adds nothing of value of my search. Can someone perhaps write a quick template script that I can then edit as needed?

Link to comment
Share on other sites

I don't know if it is the same as in Fallout, but if the CK is anything like the GECK, go to scripts, and try to find some object that does what you're thinking of, like the coin pouch, and look at the script for that, and replace the appropriate text where needed. Hope this helps, I'm an amateur, but if you need help I'll do so where I can.

Link to comment
Share on other sites

Thanks for the suggestion, I'll take a look at that.

 

What I'm trying to do is make a "Saltshaker" item that when used, gives the player a salt pile. Ideally, I'd like it to be something you "charge" with one salt pile, which you can then get ten from one at a time. Something to help with the lack of salt when using realism mods, that doesn't involve adding salt to stores or removing it from recipes. Instead, making the salt you do have go farther.

Link to comment
Share on other sites

I looked into it some more. There's no ideal way to do what you want to do from what I can tell, but a close method would be:

 

Create a MiscItem for the Salt Shaker. I don't deal with importing custom meshes so I can't help you there. I just duplicated the Flagon and used that.

 

Attach the following script to the item:

ScriptName SaltShakerScript extends ObjectReference
 
Ingredient Property SaltPile Auto
 
Event OnEquipped(Actor akActor)
If(akActor.GetItemCount(SaltPile) > 0)
akActor.RemoveItem(SaltPile, 1, False)
akActor.AddItem(SaltPile, 10, False)
EndIf
EndEvent
Attach the SaltPile Ingredient to the script's properties.
When the player clicks on the Salt Shaker in his or her inventory, the OnEquipped method will fire. Since you can't equip Misc Items, however, nothing will actually be equipped. The code in the script will still run, though. It will check to see if the player has any Salt Piles in his or her inventory and, if so, turn 1 Salt Pile into 10 Salt Piles (or whatever number you want). The only downside is that the "You cannot equip this item" message will still be displayed in the top left corner.
Note that this allows the player the ability to create an infinite number of salt piles from just one salt pile. If you wanted to add a day-long cooldown to this item, you could do something like:


ScriptName SaltShakerScript extends ObjectReference
 
Ingredient Property SaltPile Auto
GlobalVariable Property SaltShakerLastDayUsed Auto
 
Event OnEquipped(Actor akActor)
Float currentGameDay = Utility.GetCurrentGameTime()
If(currentGameDay > SaltShakerLastDayUsed.GetValue())
If(akActor.GetItemCount(SaltPile) > 0)
akActor.RemoveItem(SaltPile, 1, False)
akActor.AddItem(SaltPile, 10, False)
EndIf
SaltShakerLastDayUsed.SetValue(currentGameDay)
EndIf
EndEvent

You would have to go to Miscellaneous > Global in the Creation Kit and make a Global Variable and then add that variable to the script's properties.

 

Link to comment
Share on other sites

@revarost

 

Is your "saltshaker" an inventory item or a fixed static item placed on a shelf or table?

 

The answer to that determines how to proceed.

 

If an inventory item, the scripting would be fairly similar to what Maverick827 posted (I might have done some things differently)

If a fixed static item, then you'd create an activator with your mesh and apply a very similar script (as Maverick827's first script) but with the OnActivate event instead.

 

You could incorporate both methods if you were so inclined.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...