Jump to content

Need Assistance with an Automat, Vending Machine Script


GeneralVarusII

Recommended Posts

Greetings, modders.

 

I'm working on a new mod that, among other things, will feature functioning vending machines a la Bioshock. So far, I've compiled a Nuka-Cola vending machine script built off of the HD01NukaVendingMachineScript, or the Megaton house's Pristine Nuka-Cola Vending Machine, and a script based off of that for the automat/Eat'o'tronic 3000.

 

I'll attach .txt files of both scripts to this post, but the basic feature of each is as follows:

 

Player activates the vending machine, the amount of pre-War money in his inventory is checked, and if he has 1 or more, he's given the option to use the machine. Otherwise, he can either hack the machine (access inventory on Nuka-Cola machine or open the automat) if he passes a Repair skill check or leave it alone. If he has money in his inventory, he can either have 1, 3, or 5 money removed in return for the equivalent amount of Nuka-Cola through a menu on the vending machine, or he can trade 1 money for 1 pre-War food item from a menu at the automat. The automat's displayed items are all referenced in the script attached to it (which I will customize for each automat in the mod) so that way, every time you make a transaction, another displayed item is disabled and the machine's "VendCount" is raised by 1. When the items are all gone, and the VendCount reflects that, trying to transact with the automat will show the message that the machine is depleted. I have not yet implemented a VendCount system for the Nuka-Cola machine.

 

My problem is that I cannot get the script to trigger upon activation. I have the scripts made, the messages written, the items in the automat named for their RefIDs, and the objects placed in the world and associated with the scripts. Still, though, in all my playthroughs, I can find the vending machines, try to use them, and nothing happens. I need help with getting my script to actually activate, and so far, nothing I've tried has fixed this. I've tried removing the " if ( ActionRef Player == 1 )" line from the script, I've tried making the machine and the playerref a linkedref, and I've tried giving both vending machines their own RefIDs. Any and all help with getting this script to run will be greatly appreciated, and if you would like, I will credit anyone that can help me fix this on my mod's page when it is complete.

Link to comment
Share on other sites

Update: Since going into my mod and testing a new script that I pulled bits and pieces of the original Nuka-Cola script into, I've found that so far, the script works without the hacking and Repair skill checks. My next question is how can I implement a hacking system into this script?
Link to comment
Share on other sites

For a hacking system one suggestion would be create a locked terminal, hide it and give an option to hack the vending machine from your first activator message. If the button corresponding to the hacking option is pressed then activate the hidden, locked terminal. If the player hacks the terminal then give them a option to do something to the vending machine. Here is my post in a New Vegas thread about hidden terminals, it should be mostly relevant for Fallout 3: http://forums.nexusmods.com/index.php?/topic/760248-geck-script-help/page__st__10__p__6076598&do=findComment&comment=6076598
Link to comment
Share on other sites

A few things I've noticed in your script (looking at the automat one). You have a lot of unnecessary stuff. There are some checks that don't need to be made. I've removed about 50 lines from the script, which will work if each machine only serves one type of food. You can make it any type, but they each would need to serve only one type. The plus side to that is you can use a single script on every machine. The tradeoff would be worth it to me, not sure how you feel about it.

 

You had a pointless check on the GoFood == 3 part. Besides being pointless, it was also messing up your button detection for that message. Fallout scripts run every frame. Every script runs every frame. So they're basically on a built in continuous loop. That means that any condition that needs to be checked for, that is continuous, cannot set its condition as passed until it is done. What this means for your script is, as soon as you set GoFood to 3, you would not be able to do anything with the buttons pressed on that menu.

 

As for the single script part, I rewrote the disable section to instead use Linked Refs. They're very nice and make things like this a lot easier. You basically make each food item a persistent ref (you already have, so no big deal). You then link each one to to the next in a chain, and link the machine into the first one. The machine will check its linked ref, which will be the first food item. Upon purchase it should disable that item, and set the linked variable to the item linked from the first (the second item), and so on until you run out. I put in a check to make sure the item in the variable is valid first, just in case.

 

However, because of this, you would have to use a single food item for each machine. A way around that would be if you instead made new activator objects for each food you want to use. Each of those would have a script on it that would be something like:

scn PotatoCrispActivatorSCRIPT

BEGIN OnActivate
Player.AddItem PotatoCrisps 1
END

Just change the script for each food type. A fast way to make activators of vanilla objects is to extract them to your Data folder (FOMM can do this) in the EXACT same path they have in the BSA. Then just select them all, and drag them into the Object Window in GECK in the Activator section under World Objects. That will create all new activator objects with the food meshes, no need to include the meshes in your mod.

 

Here's the changes to the script I made. Without the message forms and other information about what you're doing, I can't do any more than this. It should work, but if it doesn't, send me a PM and we can try to work through it.

scn ArborAutomatScript01

int doOnce
int iMenu
short Button
short opened
short GoFood
short VendCount
ref rLinked

BEGIN OnActivate Player
if (Player.GetItemCount PreWarMoney >= 1) && (opened == 0)
	ShowMessage ArborAutomatMachineWith
	set iMenu to 1
	set GoFood to 2
elseif (Player.GetItemCount PreWarMoney < 1) && (opened == 0)
	ShowMessage ArborAutomatMachineWithout	;This is with no money, correct?
	set GoFood to 1
endif
if (doOnce == 0)
	set rLinked to GetLinkedRef
	set doOnce to 1
endif
END

BEGIN GameMode

if iMenu		;if checks for true, 1=true, setting the variable to 1=true and the if will run, it's a shortcut
	set Button to GetButtonPressed
	;I assume that the first button is the Hack option?
	if (Button == 0) && (GoFood >= 1) && (player.getav repair >= 40)
		set opened to 1
		activate
		setDestroyed 1		
		set GoFood to 0
	elseif (Button == 0) && (GoFood >=1) && (player.getav repair < 40)
		ShowMessage ArborAutomatMachineNoHack
		set GoFood to 0
	elseif (Button == 1) && (GoFood == 2)	;When you set GoFood to 3 lower down, this block won't run again.
		ShowMessage ArborAutomatMachineMenu01
		;set GoFood to 3		
		if (Button == 1) ;&& (GoFood == 3)	;You just set GoFood to 3, it can't not be 3 here, this is a pointless check.
			if (VendCount < 10)								;Less than whatever number of items the machine should have.
				if (rLinked != 0)								;Checks to make sure the ref is valid first.
					player.removeitem PreWarMoney 1
					player.additem PotatoCrisps 1
					;rLinked.Activate Player 		;use this if you use the alternate method I talked about.
					if (rLinked.GetDisabled == 0)				;Link the machine to the first food item via a linked ref.
						rLinked.Disable							;Link each subsequent food item to the previous one.
						set rLinked to rLinked.GetLinkedRef		;The script will walk through each one and disable them
					endif										;one at a time for each purchase.
				endif
				set GoFood to 0
				set VendCount to VendCount + 1
			else
				ShowMessage ArborAutomatMachineNoStuff
			endif
		elseif (Button == 2) ;&& (GoFood == 3) 
			;Do Nothing
			set GoFood to 0
		endif
	elseif (Button == 1) && (GoFood == 1)
		;Do Nothing
		set GoFood to 0
	elseif (Button == 2) && (GoFood == 2)
		;Do Nothing
		set GoFood to 0
	endif
endif
	
END

Link to comment
Share on other sites

My apologies for not checking this thread sooner; real life has a nasty habit of piling up on one, and I've been chipping away at construction and other scripts in the mod. But, I'll definitely see if I can't work in the hacking option that viennacalling mentioned and take your script, Gribbleshnibit8, and get to testing them this week. Again, my apologies for not getting back to the both of you on this sooner!
Link to comment
Share on other sites

As a side note, Gribbleshnibit8 probably just forgot.

If you guys and gals are going to run code in GameMode or even MenuMode blocks, please try to use the return command as early and often as possible in order to minimize the cost proceeding your scripts.

 

Like so:


BEGIN OnActivate Player
       if (Player.GetItemCount PreWarMoney >= 1) && (opened == 0)
               ShowMessage ArborAutomatMachineWith
               set iMenu to 1		;a variable set to define if your menu should run or not, 1=yes, 0=not
...                

       endif
END
   


BEGIN GameMode

if iMenu == 0			;checks if your menu should run or not
	return			;cancels the script right here
else				;proceeds the script since "if iMenu == 0" is untrue

	set Button to GetButtonPressed


	if iButton == -1	;set another return here, -1 means that no button has been pressed yet
		return		;while the script is still running up to here, we don't need the code below

	elseif (Button == 0) && (GoFood >= 1) && (player.getav repair >= 40)	;a button has been pressed now we can do stuff
		set opened to 1
		activate
		setDestroyed 1		
		set GoFood to 0
		set iMenu to 0	;if you chose a menu entry which exits the menu, set the iMenu variable back to 0 to prevent the menu code from running
				;remember you defined the menu entry point in your OnActivate block

	elseif (Button == 0) && (GoFood >=1) && (player.getav repair < 40)
		;some code you want to run
		set iMenu to 0

	...

	endif

endif
	
END

 

 

This are just some lines which help a bunch to make your scripts more efficient.

Edited by tortured Tomato
Link to comment
Share on other sites

  • 3 weeks later...
As a side note, Gribbleshnibit8 probably just forgot.

If you guys and gals are going to run code in GameMode or even MenuMode blocks, please try to use the return command as early and often as possible in order to minimize the cost proceeding your scripts.

 

 

Huh... Looks like I may have finally found out why my my mod won't get past Fallout 3 starting up for some people, on account of a container sorting script being called when it shouldn't be. Didn't realise it did that until I read the old entries on it for Morrowind and Oblivion. The only clue I had was this that kept on coming up via the console:

 

GetVATSValue 6, 15 -> 0.00

I found it rather puzzling as I couldn't understand what my script had to do with VATS. I take it that this is actually a debug message to do with frame-rate performance.

 

Hopefully this tweak to the code will put this mysterious problem to rest finally, as it isn't something I experience so can't test to see if it is fixed.

 

Edited by sELFiNDUCEDcOMA
Link to comment
Share on other sites

As a side note, Gribbleshnibit8 probably just forgot.

If you guys and gals are going to run code in GameMode or even MenuMode blocks, please try to use the return command as early and often as possible in order to minimize the cost proceeding your scripts.

 

 

Huh... Looks like I may have finally found out why my my mod won't get past Fallout 3 starting up for some people, on account of a container sorting script being called when it shouldn't be. Didn't realise it did that until I read the old entries on it for Morrowind and Oblivion. The only clue I had was this that kept on coming up via the console:

 

GetVATSValue 6, 15 -> 0.00

I found it rather puzzling as I couldn't understand what my script had to do with VATS. I take it that this is actually a debug message to do with frame-rate performance.

 

Hopefully this tweak to the code will put this mysterious problem to rest finally, as it isn't something I experience so can't test to see if it is fixed.

 

I only know about that function what I just read on the GECK Wiki.

http://geck.bethsoft.com/index.php/GetVATSValue

 

On startup the MenuMode would be active.

And maybe more important, references get being checked.

The latter can take really long on slow computer. For example, I made a mod for FO3 which translates every written word from English to German (Germanator). On my old rig (AMD Athlon 3200+) it took round about one minute to get behind the very first startup screen. It may appear to be frozen. On my new rig (Core i7 2600k) I just don't get any delay.

 

The older the computer, the more you may experience lags.

Edited by tortured Tomato
Link to comment
Share on other sites

  • 3 weeks later...

I created my own vending machines for my FNV mod Vault 105 using the crafting system, based around the vault currency of "Vault Tokens"...could easily swap out for prewar money instead. It was functionally the same as the Sierra Madre vending machines apart from the different model and currency.

 

If this is for F3 though then I don't really know, sounds like it'll be a hell of a lot of work to set up more than a few purchasables.

 

My original prototype for the V105 vending machines involved heavy use of terminals and categories, but it was a total pain to work with. The overall technique was that clicking the button for something in the machine would result in either an error message or money being removed from the player while the object was placed in a container linked to the terminal. trouble being that it was limited to about three or four items on screen at any time out of something like 20 or 30 that I intended to have available.

 

Your system being a message-box system has a good few more available button slots, just less of an interface to work with in setting it up.

Link to comment
Share on other sites

We actually solved the problem via PM. Took a little bit of work, but we got it worked out.

 

Yes, the system that General Varus II wanted was for Fallout 3, so using the crafting menu was out (I've done that in my own mod before). What we wound up doing was a system of linked refs being added to a list of items to be sold. Using a few predefined data values, it was possible to relatively easily have a single script that could account for every machine, given a bit of setup on each one. Unless General Varus II posts the script, it'll have to wait until next week when I can get back on my computer to post it.

 

 

However, doing this for General Varus II inspired me to work on a similar system for FNV, that uses some of the new NVSE functions. Specifically it makes use of MessageBoxEX, which allows for script created message forms that can take the NVSE format specifiers for things like object name. This allows the buttons of the message to be set dynamically from a list of items to sell. This allows for a single script, with no message forms to deal with, that can handle any items. Using a message generation section borrowed from Project Nevada Cyberware, which does something similar for implants.

 

The end result is that the machine does a ref walk through the cell looking for items that are within 64 units of the machine, it adds the found items to a list, and the base items to another list. The message display uses the list of base items, so that only one of each item is displayed. All of this is done upon activation, meaning that it only runs when used, and has no additional overhead.

 

The end result can be viewed in my Vending Machines of the Wastes mod, which has several examples of the system for different types of object. If anyone is interested in what I did there, feel free to PM me with questions, as well as use any scripts in that, or any, of my mods.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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