Jump to content

Crafting Script - Pull items from a Container


Recommended Posts

Looking for a script to add to a workbench, etc. that uses a container to pull ingredients from and puts whatever is made back into that container. Any suggestions?

scn BlackbriarArmoryCraftingRecipesScript
; Launches crafting interface for recipes in the "BlackbriarArmorerRecipes" category.
Ref User
Begin OnActivate
Set User to GetActionRef
If GetActionRef != Player
User.Activate
Elseif GetActionRef == Player
player.showrecipemenu BlackbriarArmorerRecipes
Endif
End
Link to comment
Share on other sites

I haven't seen such a script, although I hardly get out much. Were I to make one from scratch, anyhow, I'd probably do it with three components.

 

1. The bench.

2. The container.

3. The sniffer.

 

Stick the bench and the sniffer (activator) near each other, put a simple gamemode script on the sniffer so that it sniffs out token items.

 

Then, make a token item, like, let's say you're making a rifle. So, you put the RifleToken as the craftable item, you let the player craft it. Sniffer runs a GetItemCount Rifletoken check, then it goes ahead and removes the token, adding the Rifle to the ContainerRef.

 

That's for adding craftables into the container, anyhow. Sniffers are excellent for things like that.

 

As for pulling the ingredients, that's a hard one. Very hard. For that I'd probably have to maybe give the player weightless unplayable armour tokens that won't show up in the inventory to use as crafting ingredients, and some kind of global to abridge the tokencount and the ContainerRef item count?

 

Could be tricky, I've never undertaken such a project before, but I really like doing things that are impossible to do.

Link to comment
Share on other sites

Sounds tricky... :/ Fee510 had a portable tent mod that I believe had the ability to pull ingredients from a container while you were in the tent (instead of from your personal inventory)... I took a look at the code (which relies on NVSE I think) and it is just beyond me and my very limited skills.

My thing is that right now, I have it set up in my mod that anything you construct around the base/player home (only while you're on it) can be pulled from this single storage container. And what I'm really trying to get away from is (while still keeping some sense of immersion) is : I need to make a gun, then I grab the stuff out of the container, run to the workbench, ...sh*t, I missed a metal and a sprocket.. Let me run back. Grab the metal and sprocket and come back... Cool. Wait, no ammo. Damn, need to craft some...run back to the container grab a pinch of this, a dash of that...run back to the bench. Oh, well, you're missing two units of X but you remember, you have 5 boxes of Y which be converted to X. Back to the container...Grab a bunch of Y and a little of Z for good measure. How much do you need, who knows? Let's grab a lot.. Run back to the bench, start converting Y into X and you're just shy of enough. Z will work but you need more. Wait, N can be converted to Z which can be converted to Y and down to X...

See.... stupid. Inventory management in FNV has always sucked. Micro managing inventory in your player home - of all places is dumb. Other options - do god mode, grab everything and convert away and then go through the nonsense of sorting it all out again.

Really trying to find an easy approach around it. And I can't understand why you couldn't make an activator that would run a recipe script but check a persistent ref (container) for the ingredients rather than the player? You know?

Either way, beyond me. Still trying to make my timer/building script work right. :/

My friend, any help on an impossible project like this would be greatly appreciated. Thanks again for the reply.

Link to comment
Share on other sites

You know what? Consider using a terminal. They are perfect for these kinds of things. I am making a mod myself where the player has a commune for his faction, and it has upgrades made from a global SupplyCount value. It has all kinds of upgrades, and recruitment of NPCs. Worker NPCs will even generate SupplyCount overtime, and the player can recycle items to increase the SupplyCount as well.

 

Using items in a container would be just as easy. Here's how an upgrade looks like:

 

Edited by Thumblesteen
Link to comment
Share on other sites

Surprisingly enough, it would not. The scripts are executed within each terminal button, and actually require less coding than regular scripts.

 

You just add a condition for the items in the container to the button, and then use an additem command to add the crafted item, and a removeitem command to remove the components.

 

It is three lines of code per schematic, give or take the components.

Link to comment
Share on other sites

But wouldnt I have to do three for literally a hundred items or more? I know you know a lot more than me about this...just curious how that would work?!

Another question... If I'm using a script like the one below... .what would I need to add so it deletes the particular reference? For example I have 50 trees in an area that share the same script. But when you chop down each tree - how would you go about deleting only the tree you chopped... without having to write the reference for every single tree you plant? Or to have it put a stump in the same place and regrows itself in 20 game days or something like that?

Thanks again!


scn BlackbriarOakTreeScript

;Modifed to allow respawn in zones that don't reset

int State
float Day

begin onActivate
	if State == 0 && GetActionRef == player
		player.additem BlackbriarResourceTimber 12
		player.additem BlackbriarOakSeeds 2
		set State to 1
		playGroup Forward 1
		setdestroyed 1
		Set Day to GameDaysPassed
		Set Day to Day + 20
	endif
end

begin GameMode

If Day <= GameDaysPassed && State == 1
	Set State to 0
	SetDestroyed 0
	PlayGroup Backward 1
endif
end
begin onReset
	if State == 1
		playgroup Backward 1
		set State to 0
		setdestroyed 0
	endif
end

Edited by Guest
Link to comment
Share on other sites

Hello Namaskar.

 

To do what you want to do (crafting with items from a container instead of items from the players inventory) you need a "dummy" NPC.

 

Usually you open the crafting menu with the command:

Player.ShowRecipeMenu WorkbenchRecipes

This will show the crafting menu. It will use source items from the players inventory, enable recipes according to the players skills and spawn the crafted item back into the players inventory. Everybody knows how this goes.

 

A little know fact is that this same command can also be used on a NPC references instead of the player. In this case, everything that would normally be taken from the player is instead taken from that NPC. Both inventory and crafting skills (and possibly perks.)

Imagine you have a "dummy" NPC reference called MyDummyREF and you use the following script command:

MyDummyREF.ShowRecipeMenu WorkbenchRecipes

This will show the crafting menu like normal but now you are crafting as if MyDummyREF were the player. You use his inventory and his skills, rather than your own. The crafted item is put into the NPCs inventory, not yours.

 

--

 

To "fake" crafting from a container, you need to do the following things:

 

1.) Adjust the crafting dummy NPCs skills to match the skills of the player.

2.) Move all items from the container into the crafting dummy NPCs inventory.

3.) Open the crafting menu, using the dummy NPC reference.

4.) Move all items from the crafting dummy back into the original container.

 

--

 

This whole process can be a bit "finicky" because you need to give the game some time (at least one frame) to do its magic between steps. Moving items between containers and adjusting NPC skills doesn't actually work instantaneously, so you cannot do it in one single step.

 

Here is the script I am using for the reloading bench in my own player home. I hope it isn't too confusing.

 

If you activate the bench, a message box will open and ask you if you want to craft ammo from your own inventory (0) or the ammo storage box (1) or abort (2). The ammo storage box reference is called TMHAmmoStorageREF and my crafting dummy NPC is called TMHCraftingREF. The dummy NPC is stored in a dummy cell different than the player home cell, the NPC doesn't actually have to be loaded for this to work.

 

Feel free to ask if you have any questions. I hope this helps you and good luck.

ScriptName TMHAmmoPressScript
 
Short active
Short key
Short stage
Short skill
 
Begin OnActivate
   If GetActionRef != Player
      Activate
   Else
      Set active To 1
      ShowMessage TMHAmmoPressMenuMessage
   EndIf
End
 
Begin MenuMode 1001 ;Message box is open
   If active == 0
      Return
   EndIf
   Set key To GetButtonPressed
   If key >= 0
      If key == 0
         Set stage To 10
      ElseIf key == 1
         Set stage To 20
      ElseIf key == 2
         Set active To 0
      EndIf
   EndIf
End
 
Begin MenuMode 1077 ;Crafting menu is open
   If active == 0
      Return
   EndIf
   Set stage To 50
End
 
Begin GameMode
   If active == 0
      Return
   EndIf
   If stage == 10
      Player.ShowRecipeMenu ReloadingBenchRecipes
      Set active To 0
      Return
   ElseIf stage == 20
      Set skill To Player.GetActorValue Barter
      TMHCraftingREF.ForceActorValue Barter skill
      Set skill To Player.GetActorValue Guns
      TMHCraftingREF.ForceActorValue Guns skill
      Set skill To Player.GetActorValue EnergyWeapons
      TMHCraftingREF.ForceActorValue EnergyWeapons skill
      Set skill To Player.GetActorValue Explosives
      TMHCraftingREF.ForceActorValue Explosives skill
      Set skill To Player.GetActorValue Lockpick
      TMHCraftingREF.ForceActorValue Lockpick skill
      Set skill To Player.GetActorValue Medicine
      TMHCraftingREF.ForceActorValue Medicine skill
      Set skill To Player.GetActorValue MeleeWeapons
      TMHCraftingREF.ForceActorValue MeleeWeapons skill
      Set skill To Player.GetActorValue Repair
      TMHCraftingREF.ForceActorValue Repair skill
      Set skill To Player.GetActorValue Science
      TMHCraftingREF.ForceActorValue Science skill
      Set skill To Player.GetActorValue Sneak
      TMHCraftingREF.ForceActorValue Sneak skill
      Set skill To Player.GetActorValue Speech
      TMHCraftingREF.ForceActorValue Speech skill
      Set skill To Player.GetActorValue Survival
      TMHCraftingREF.ForceActorValue Survival skill
      Set skill To Player.GetActorValue Unarmed
      TMHCraftingREF.ForceActorValue Unarmed skill
      TMHAmmoStorageREF.RemoveAllItems TMHCraftingREF
      Set stage To 30
   ElseIf stage == 30
      Set stage To 40
      TMHCraftingREF.ShowRecipeMenu ReloadingBenchRecipes
   ElseIf stage == 40
      Return
   ElseIf stage == 50
      TMHCraftingREF.RemoveAllItems TMHAmmoStorageREF
      Set active To 0
   EndIf
End
Link to comment
Share on other sites

I had no idea the crafting menu could be called with a DummyRef. That changes everything.

 

And, namaskar:

 

Try this:

 

int State
float Day

ref rSelf

begin onActivate

set rSelf to GetSelf
if State == 0 && GetActionRef == player
player.additem BlackbriarResourceTimber 12
player.additem BlackbriarOakSeeds 2
set State to 1
playGroup Forward 1
setdestroyed 1
Set Day to GameDaysPassed
Set Day to Day + 20

rSelf.disable
endif
end

begin GameMode

If Day <= GameDaysPassed && State == 1
Set State to 0
SetDestroyed 0
PlayGroup Backward 1

rSelf.enable
endif
end
begin onReset
if State == 1
playgroup Backward 1
set State to 0
setdestroyed 0

rSelf.enable
endif
end

 

EDIT:

Oh, and, no offence, but your timer looks iffy. I don't think you can use the GameDaysPassed as a timer condition, I'm not entirely sure, though.
I have written hundreds of scripts from scratch, but, that won't change the fact that I'm a bit of a savant, really.

Edited by Thumblesteen
Link to comment
Share on other sites

 

Hello Namaskar.

 

To do what you want to do (crafting with items from a container instead of items from the players inventory) you need a "dummy" NPC.

 

Usually you open the crafting menu with the command:

Player.ShowRecipeMenu WorkbenchRecipes

This will show the crafting menu. It will use source items from the players inventory, enable recipes according to the players skills and spawn the crafted item back into the players inventory. Everybody knows how this goes.

 

A little know fact is that this same command can also be used on a NPC references instead of the player. In this case, everything that would normally be taken from the player is instead taken from that NPC. Both inventory and crafting skills (and possibly perks.)

Imagine you have a "dummy" NPC reference called MyDummyREF and you use the following script command:

MyDummyREF.ShowRecipeMenu WorkbenchRecipes

This will show the crafting menu like normal but now you are crafting as if MyDummyREF were the player. You use his inventory and his skills, rather than your own. The crafted item is put into the NPCs inventory, not yours.

 

--

 

To "fake" crafting from a container, you need to do the following things:

 

1.) Adjust the crafting dummy NPCs skills to match the skills of the player.

2.) Move all items from the container into the crafting dummy NPCs inventory.

3.) Open the crafting menu, using the dummy NPC reference.

4.) Move all items from the crafting dummy back into the original container.

 

--

 

This whole process can be a bit "finicky" because you need to give the game some time (at least one frame) to do its magic between steps. Moving items between containers and adjusting NPC skills doesn't actually work instantaneously, so you cannot do it in one single step.

 

Here is the script I am using for the reloading bench in my own player home. I hope it isn't too confusing.

 

If you activate the bench, a message box will open and ask you if you want to craft ammo from your own inventory (0) or the ammo storage box (1) or abort (2). The ammo storage box reference is called TMHAmmoStorageREF and my crafting dummy NPC is called TMHCraftingREF. The dummy NPC is stored in a dummy cell different than the player home cell, the NPC doesn't actually have to be loaded for this to work.

 

Feel free to ask if you have any questions. I hope this helps you and good luck.

ScriptName TMHAmmoPressScript
 
Short active
Short key
Short stage
Short skill
 
Begin OnActivate
   If GetActionRef != Player
      Activate
   Else
      Set active To 1
      ShowMessage TMHAmmoPressMenuMessage
   EndIf
End
 
Begin MenuMode 1001 ;Message box is open
   If active == 0
      Return
   EndIf
   Set key To GetButtonPressed
   If key >= 0
      If key == 0
         Set stage To 10
      ElseIf key == 1
         Set stage To 20
      ElseIf key == 2
         Set active To 0
      EndIf
   EndIf
End
 
Begin MenuMode 1077 ;Crafting menu is open
   If active == 0
      Return
   EndIf
   Set stage To 50
End
 
Begin GameMode
   If active == 0
      Return
   EndIf
   If stage == 10
      Player.ShowRecipeMenu ReloadingBenchRecipes
      Set active To 0
      Return
   ElseIf stage == 20
      Set skill To Player.GetActorValue Barter
      TMHCraftingREF.ForceActorValue Barter skill
      Set skill To Player.GetActorValue Guns
      TMHCraftingREF.ForceActorValue Guns skill
      Set skill To Player.GetActorValue EnergyWeapons
      TMHCraftingREF.ForceActorValue EnergyWeapons skill
      Set skill To Player.GetActorValue Explosives
      TMHCraftingREF.ForceActorValue Explosives skill
      Set skill To Player.GetActorValue Lockpick
      TMHCraftingREF.ForceActorValue Lockpick skill
      Set skill To Player.GetActorValue Medicine
      TMHCraftingREF.ForceActorValue Medicine skill
      Set skill To Player.GetActorValue MeleeWeapons
      TMHCraftingREF.ForceActorValue MeleeWeapons skill
      Set skill To Player.GetActorValue Repair
      TMHCraftingREF.ForceActorValue Repair skill
      Set skill To Player.GetActorValue Science
      TMHCraftingREF.ForceActorValue Science skill
      Set skill To Player.GetActorValue Sneak
      TMHCraftingREF.ForceActorValue Sneak skill
      Set skill To Player.GetActorValue Speech
      TMHCraftingREF.ForceActorValue Speech skill
      Set skill To Player.GetActorValue Survival
      TMHCraftingREF.ForceActorValue Survival skill
      Set skill To Player.GetActorValue Unarmed
      TMHCraftingREF.ForceActorValue Unarmed skill
      TMHAmmoStorageREF.RemoveAllItems TMHCraftingREF
      Set stage To 30
   ElseIf stage == 30
      Set stage To 40
      TMHCraftingREF.ShowRecipeMenu ReloadingBenchRecipes
   ElseIf stage == 40
      Return
   ElseIf stage == 50
      TMHCraftingREF.RemoveAllItems TMHAmmoStorageREF
      Set active To 0
   EndIf
End

THat is awesomeness. Absolute awesomeness. A couple of questions: in making the dummy...what kind of npc would I use? Would I put him in a cell that no one can access and to which there is no exit (or does that matter)?

 

Could this also be activated from a terminal (giving the player the option to either do hands on crating or using a terminal?)

 

That is a wicked awesome script. Do you have your player home as a mod for others or is it for personal use?

 

Thanks so much for the help. Let me try making that work.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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