Jump to content

Menu scripting help


PSDaniel

Recommended Posts

Hello,

For a mod I'm making a menu, similar to the one used to repair ED-E. In-game it does work, but some buttons go to the wrong menu and when I want some items removed from the players inventory nothing happens. Can you guys please look into the code and tell me what I did wrong? Thanks in advance :D

 

scn HPAqscript

int iButton
int iMenu

begin OnActivate player
if HPArepaired == 0
showMessage HPAexamine00
endif
end

begin GameMode player
set iButton to GetButtonPressed
if iButton == 0
	set iMenu to 0
endif
if iMenu == 0			;HPAexamine00	
	if iButton == 1
		showMessage HPAexamine01
		set iMenu to 1
	elseif iButton == 2
		ShowMessage HPAexamine02
		set iMenu to 2
	endif
endif
if iMenu == 1			;HPAexamine01
	if iButton == 1
		showMessage HPAexamine00
		set iMenu to 0
	elseif iButton == 2
		removeItem SpareParts 3
		removeItem ScrapElectronics 3
		removeItem SensorModule 2
		addItem HardT51bArmorPrep 1
		addItem HardT51bHelmetPrep 1
		addNote HPAtofactory
		showMessage HPAexamine03
		set iMenu to 3
	endif
endif
if iMenu == 2			;HPAexamine02
	if iButton == 1
		showMessage HPAexamine00
		set iMenu to 0
	elseif iButton == 2
		addItem HardT51bArmorPrep 1
		addItem HardT51bHelmetPrep 1
		addNote HPAtofactory
		showMessage HPAexamine03
		set iMenu to 3
	endif
endif
if iMenu == 3
	if 	getStage HPAquest < 10
		setStage HPAquest 10
		set HPArepaired to 1
	endif
endif
end

Link to comment
Share on other sites

You're going to have several problems with this. To start, all variables in GECK script are initialized to 0, so there's no need to do it. This also means that anything that checks for a value of 0 will always return true when the script first starts running. The better way is to check for a 1 (which to a computer means true).

 

Now, not knowing what your message form looks like, I can only guess here, but generally the exit/cancel button is always the last one. I have found that it is best to go ahead and add all 10 buttons to your form, and then use a condition to keep the ones you don't need from showing up. Doing this means that if you add options later, you don't have to rewrite your entire code to add the new options.

 

I'm going to rewrite this a bit in the way I would do it that will make it easier to expand on later. It probably won't match your message form, but messages are easier to make than scripts.

 

scn HPAqscript

int iButton
int iMenuLevel

begin OnActivate player
       if HPArepaired == 0
	set iMenuLevel to 1
       showMessage HPAexamine00
       endif
end

begin GameMode player

if (iMenuLevel == 1)					;HPAexamine00
       set iButton to GetButtonPressed
	if (iButton == 0)				;Remember that buttons start at 0, not 1. To a computer, a value of 0 is still a number.
		set iMenuLevel to 2			;variables should be set before showing the message, to ensure the values are carried in properly
		showMessage HPAexamine01
	elseif (iButton == 1)
		set iMenuLevel to 3
		ShowMessage HPAexamine02
	elseif (iButton == 9) 			;This is the last number a button can be, this should be your exit button. You can change the number up to any other that fits for you though.
		set iMenuLevel to 0			;turn off the menu processing
		return						;exit the script
   elseif (iMenuLevel == 2)				;HPAexamine01
	set iButton to GetButtonPressed	;you need to get the button press on each menu level
	if (iButton == 0)				;Idealy this should NOT be your back button, as that varies from general GUI practices
		set iMenuLevel to 1
		showMessage HPAexamine00
	elseif (iButton == 1)
		removeItem SpareParts 3
		removeItem ScrapElectronics 3
		removeItem SensorModule 2
		addItem HardT51bArmorPrep 1
		addItem HardT51bHelmetPrep 1
		addNote HPAtofactory
		showMessage HPAexamine03
		set iMenuLevel to 4
	endif
elseif (iMenuLevel == 3)				;HPAexamine02
	set iButton to GetButtonPressed
	if iButton == 1
		set iMenuLevel to 0
		showMessage HPAexamine00
	elseif iButton == 2
		addItem HardT51bArmorPrep 1
		addItem HardT51bHelmetPrep 1
		addNote HPAtofactory
		showMessage HPAexamine03
		set iMenuLevel to 4
	endif
elseif (iMenuLevel == 4)
	if (getStage HPAquest < 10)
		setStage HPAquest 10
		set HPArepaired to 1
	endif
endif
end

This should be better. Again, not knowing your message forms, it's a best guess. Check and make sure that everything is still in the order you need it in.

 

If you need more help, Cipscis has made up some superb tutorials about how to do neat stuff with scripts. He covers all the basics, as well as some advanced topics at his website here.

Link to comment
Share on other sites

Thank you for your help :D The reason I put the return button on top is that some buttons only show up when you meet certain conditions, like a repair skill of 50. I thought the script would think resume is button 1 instead of 2 and run the wrong part of the script.
Link to comment
Share on other sites

  • 3 weeks later...
Not to hijack this thread but... it is related. Do conditions on buttons work for you in the message dialogue? Or are you setting button conditions somehow in script. I ask this because anytime I set a condition the button will not appear even if the condition is true. Say in the message dialogue I have a condition for a button that says (GetItemCount spareparts >= 1) and set that to run on target, even if my character has spareparts (Scrap Metal) the button will not appear. Am I doing this wrong? I've been trying to run this message from a script that is attached to an activator that is a persistent ref.
Link to comment
Share on other sites

  • Recently Browsing   0 members

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