Jump to content

Shortening script


bencebence

Recommended Posts

I could make it a bit shorter if I used arrays and rewrote it completely. But otherwise there's not much I can do about the length.

 

EDIT: And oh, those functions I wrote wouldn't be useful to you. They take an array of objects and then display each of those objects as a separate button.

Edited by fg109
Link to comment
Share on other sites

I'm going to take ONE segment, and try to apply a little common sense to reduce it down. Don't assume I've got this correct, work through it and check as I'm working on notepad at 6am :( - check the code still does the same as you expect it to.

 

 

if (menulevel == 21)

set button to getbuttonpressed

if (button > -1)

if (button == 0)

messagebox "Choose material.", "Copper, "Bronze", "Iron", "Steel", "Dwarfite", "Alyiite", "Crystalite", "Mithril", "Ebony", "Daedric", "Cancel"

set menulevel to 31

elseif (button == 1)

messagebox "Choose material.", "Copper, "Bronze", "Iron", "Steel", "Dwarfite", "Alyiite", "Crystalite", "Mithril", "Ebony", "Daedric", "Cancel"

set menulevel to 32

elseif (button == 2)

message "Crafting cancelled."

else

message "Your Armorer skill is too low."

endif

endif

endif

 

 

 

Now, what jumps out at me in your code generally is that you repeat LOTS of REPEATED messageboxes, so try splitting the messageboxes away from the menu codes:-

 

 

if (menulevel == 21)

set button to getbuttonpressed

if (button > -1)

;Sort out your messages:-

if (button < 2)

messagebox "Choose material.", "Copper, "Bronze", "Iron", "Steel", "Dwarfite", "Alyiite", "Crystalite", "Mithril", "Ebony", "Daedric", "Cancel"

elseif (button == 2)

message "Crafting cancelled."

else

message "Your Armorer skill is too low."

endif

 

;Now do the menu stuff:-

if (button == 0)

set menulevel to 31

elseif (button == 1)

set menulevel to 32

endif

endif

endif

 

 

In that particular code segment the difference is next to nothing, other than in readability. But when you hit one of your "Select a chunk of armor" sections, you'll lose nine or ten lines of code. ALWAYS comment the splits in the code so that when you come back to it you'll remember WHY you did it.

 

See if that approach helps you

 

EDIT: BTW, which text format tags are you using to post indented code? I tried "Code" and it screwed up the carriage returns and put the lot on one line

Edited by MarkInMKUK
Link to comment
Share on other sites

I post code by copying from notepad and then pasting inside the code tags.

 

I've re-written the whole menu, but I haven't tested it out (I don't have any of the items in my game after all).

 

This is the version that requires OBSE:

 

 

This is a script for a function. It only runs once the first time you use the activator. Use object script for the script type. You don't need to put the script on anything.

scriptname BuildSmithingArray

array_var Output

short eqtype	;0 = armor, 1 = weapons
short mattype	;0 = copper, 1 = bronze, 2 = iron, 3 = steel, 4 = dwarfite, 5 = ayliite, 6 = crystalite, 7 = mithril, 8 = ebony, 9 = daedric
short piece		;for armor: 0 = boots, 1 = cuirass, 2 = gauntlets, 3 = greaves, 4 = helmet, 5 = shield
			;for weapons: 0 = dagger, 1 = arrow tips, 2 = short sword, 3 = long sword, 4 = claymore, 5 = war axe, 6 = war hammer

Begin Function {}

let Output := ar_Construct Array
let eqtype := 0
while (eqtype < 2)
	let Output[eqtype] := ar_Construct Array
	let mattype := 0
	while (mattype < 10)
		let Output[eqtype][mattype] := ar_Construct Array
		let piece := 0
		while (piece < 7)
			let Output[eqtype][mattype][piece] := ar_Construct StringMap
			if (mattype == 0)
				let Output[eqtype][mattype][piece]["MatID"] := CopperBar
			elseif (mattype == 1)
				let Output[eqtype][mattype][piece]["MatID"] := BronzeBar
			elseif (mattype == 2)
				let Output[eqtype][mattype][piece]["MatID"] := IronBar
			elseif (mattype == 3)
				let Output[eqtype][mattype][piece]["MatID"] := SteelBar
			elseif (mattype == 4)
				let Output[eqtype][mattype][piece]["MatID"] := DwarfiteBar
			elseif (mattype == 5)
				let Output[eqtype][mattype][piece]["MatID"] := AyliiteBar
			elseif (mattype == 6)
				let Output[eqtype][mattype][piece]["MatID"] := CrystaliteBar
			elseif (mattype == 7)
				let Output[eqtype][mattype][piece]["MatID"] := MithrilBar
			elseif (mattype == 8)
				let Output[eqtype][mattype][piece]["MatID"] := EbonyBar
			elseif (mattype == 9)
				let Output[eqtype][mattype][piece]["MatID"] := DaedriteBar
			endif
			if (piece == 5) && (eqtype == 0)
				Break
			endif
			let piece +=1
		loop
		let mattype += 1
	loop
	let eqtype += 1
loop

let mattype := 0
while (mattype < 10)
	let Output[0][mattype][0]["MatCost"] := 3
	let Output[0][mattype][1]["MatCost"] := 5
	let Output[0][mattype][2]["MatCost"] := 2
	let Output[0][mattype][3]["MatCost"] := 4
	let Output[0][mattype][4]["MatCost"] := 2
	let Output[0][mattype][5]["MatCost"] := 3
	let Output[1][mattype][0]["MatCost"] := 1
	let Output[1][mattype][1]["MatCost"] := 1
	let Output[1][mattype][2]["MatCost"] := 2
	let Output[1][mattype][3]["MatCost"] := 3
	let Output[1][mattype][4]["MatCost"] := 3
	let Output[1][mattype][5]["MatCost"] := 3
	let Output[1][mattype][6]["MatCost"] := 4
	let mattype += 1
loop

let Output[0][0][0]["ProductID"] := CopperBoots
let Output[0][0][1]["ProductID"] := CopperCuirass
let Output[0][0][2]["ProductID"] := CopperGauntlets
let Output[0][0][3]["ProductID"] := CopperGreaves
let Output[0][0][4]["ProductID"] := CopperHelmet
let Output[0][0][5]["ProductID"] := CopperShield
let Output[0][1][0]["ProductID"] := BronzeBoots
let Output[0][1][1]["ProductID"] := BronzeCuirass
let Output[0][1][2]["ProductID"] := BronzeGauntlets
let Output[0][1][3]["ProductID"] := BronzeGreaves
let Output[0][1][4]["ProductID"] := BronzeHelmet
let Output[0][1][5]["ProductID"] := BronzeShield
let Output[0][2][0]["ProductID"] := IronBoots
let Output[0][2][1]["ProductID"] := IronCuirass
let Output[0][2][2]["ProductID"] := IronGauntlets
let Output[0][2][3]["ProductID"] := IronGreaves
let Output[0][2][4]["ProductID"] := IronHelmet
let Output[0][2][5]["ProductID"] := IronShield
let Output[0][3][0]["ProductID"] := SteelBoots
let Output[0][3][1]["ProductID"] := SteelCuirass
let Output[0][3][2]["ProductID"] := SteelGauntlets
let Output[0][3][3]["ProductID"] := SteelGreaves
let Output[0][3][4]["ProductID"] := SteelHelmet
let Output[0][3][5]["ProductID"] := SteelShield
let Output[0][4][0]["ProductID"] := DwarvenBoots
let Output[0][4][1]["ProductID"] := DwarvenCuirass
let Output[0][4][2]["ProductID"] := DwarvenGauntlets
let Output[0][4][3]["ProductID"] := DwarvenGreaves
let Output[0][4][4]["ProductID"] := DwarvenHelmet
let Output[0][4][5]["ProductID"] := DwarvenShield
let Output[0][5][0]["ProductID"] := ElvenBoots
let Output[0][5][1]["ProductID"] := ElvenCuirass
let Output[0][5][2]["ProductID"] := ElvenGauntlets
let Output[0][5][3]["ProductID"] := ElvenGreaves
let Output[0][5][4]["ProductID"] := ElvenHelmet
let Output[0][5][5]["ProductID"] := ElvenShield
let Output[0][6][0]["ProductID"] := GlassBoots
let Output[0][6][1]["ProductID"] := GlassCuirass
let Output[0][6][2]["ProductID"] := GlassGauntlets
let Output[0][6][3]["ProductID"] := GlassGreaves
let Output[0][6][4]["ProductID"] := GlassHelmet
let Output[0][6][5]["ProductID"] := GlassShield
let Output[0][7][0]["ProductID"] := MithrilBoots
let Output[0][7][1]["ProductID"] := MithrilCuirass
let Output[0][7][2]["ProductID"] := MithrilGauntlets
let Output[0][7][3]["ProductID"] := MithrilGreaves
let Output[0][7][4]["ProductID"] := MithrilHelmet
let Output[0][7][5]["ProductID"] := MithrilShield
let Output[0][8][0]["ProductID"] := EbonyBoots
let Output[0][8][1]["ProductID"] := EbonyCuirass
let Output[0][8][2]["ProductID"] := EbonyGauntlets
let Output[0][8][3]["ProductID"] := EbonyGreaves
let Output[0][8][4]["ProductID"] := EbonyHelmet
let Output[0][8][5]["ProductID"] := EbonyShield
let Output[0][9][0]["ProductID"] := DaedricBoots
let Output[0][9][1]["ProductID"] := DaedricCuirass
let Output[0][9][2]["ProductID"] := DaedricGauntlets
let Output[0][9][3]["ProductID"] := DaedricGreaves
let Output[0][9][4]["ProductID"] := DaedricHelmet
let Output[0][9][5]["ProductID"] := DaedricShield

let Output[1][0][0]["ProductID"] := CopperDagger
let Output[1][0][1]["ProductID"] := CopperArrowTips
let Output[1][0][2]["ProductID"] := CopperShortSword
let Output[1][0][3]["ProductID"] := CopperLongSword
let Output[1][0][4]["ProductID"] := CopperClaymore
let Output[1][0][5]["ProductID"] := CopperWarAxe
let Output[1][0][6]["ProductID"] := CopperWarHammer
let Output[1][1][0]["ProductID"] := BronzeDagger
let Output[1][1][1]["ProductID"] := BronzeArrowTips
let Output[1][1][2]["ProductID"] := BronzeShortSword
let Output[1][1][3]["ProductID"] := BronzeLongSword
let Output[1][1][4]["ProductID"] := BronzeClaymore
let Output[1][1][5]["ProductID"] := BronzeWarAxe
let Output[1][1][6]["ProductID"] := BronzeWarHammer
let Output[1][2][0]["ProductID"] := WeapIronDagger
let Output[1][2][1]["ProductID"] := IronArrowTips
let Output[1][2][2]["ProductID"] := WeapIronShortSword
let Output[1][2][3]["ProductID"] := WeapIronLongSword
let Output[1][2][4]["ProductID"] := WeapIronClaymore
let Output[1][2][5]["ProductID"] := WeapIronWarAxe
let Output[1][2][6]["ProductID"] := WeapIronWarHammer
let Output[1][3][0]["ProductID"] := WeapSteelDagger
let Output[1][3][1]["ProductID"] := SteelArrowTips
let Output[1][3][2]["ProductID"] := WeapSteelShortSword
let Output[1][3][3]["ProductID"] := WeapSteelLongSword
let Output[1][3][4]["ProductID"] := WeapSteelClaymore
let Output[1][3][5]["ProductID"] := WeapSteelWarAxe
let Output[1][3][6]["ProductID"] := WeapSteelWarHammer
let Output[1][4][0]["ProductID"] := WeapDwarvenDagger
let Output[1][4][1]["ProductID"] := DwarvenArrowTips
let Output[1][4][2]["ProductID"] := WeapDwarvenShortSword
let Output[1][4][3]["ProductID"] := WeapDwarvenLongSword
let Output[1][4][4]["ProductID"] := WeapDwarvenClaymore
let Output[1][4][5]["ProductID"] := WeapDwarvenWarAxe
let Output[1][4][6]["ProductID"] := WeapDwarvenWarHammer
let Output[1][5][0]["ProductID"] := WeapElvenDagger
let Output[1][5][1]["ProductID"] := ElvenArrowTips
let Output[1][5][2]["ProductID"] := WeapElvenShortSword
let Output[1][5][3]["ProductID"] := WeapElvenLongSword
let Output[1][5][4]["ProductID"] := WeapElvenClaymore
let Output[1][5][5]["ProductID"] := WeapElvenWarAxe
let Output[1][5][6]["ProductID"] := WeapElvenWarHammer
let Output[1][6][0]["ProductID"] := WeapGlassDagger
let Output[1][6][1]["ProductID"] := GlassArrowTips
let Output[1][6][2]["ProductID"] := WeapGlassShortSword
let Output[1][6][3]["ProductID"] := WeapGlassLongSword
let Output[1][6][4]["ProductID"] := WeapGlassClaymore
let Output[1][6][5]["ProductID"] := WeapGlassWarAxe
let Output[1][6][6]["ProductID"] := WeapGlassWarHammer
let Output[1][7][0]["ProductID"] := MithrilDagger
let Output[1][7][1]["ProductID"] := MithrilArrowTips
let Output[1][7][2]["ProductID"] := MithrilShortSword
let Output[1][7][3]["ProductID"] := MithrilLongSword
let Output[1][7][4]["ProductID"] := MithrilClaymore
let Output[1][7][5]["ProductID"] := MithrilWarAxe
let Output[1][7][6]["ProductID"] := MithrilWarHammer
let Output[1][8][0]["ProductID"] := WeapEbonyDagger
let Output[1][8][1]["ProductID"] := EbonyArrowTips
let Output[1][8][2]["ProductID"] := WeapEbonyShortSword
let Output[1][8][3]["ProductID"] := WeapEbonyLongSword
let Output[1][8][4]["ProductID"] := WeapEbonyClaymore
let Output[1][8][5]["ProductID"] := WeapEbonyWarAxe
let Output[1][8][6]["ProductID"] := WeapEbonyWarHammer
let Output[1][9][0]["ProductID"] := WeapDaedricDagger
let Output[1][9][1]["ProductID"] := DaedricArrowTips
let Output[1][9][2]["ProductID"] := WeapDaedricShortSword
let Output[1][9][3]["ProductID"] := WeapDaedricLongSword
let Output[1][9][4]["ProductID"] := WeapDaedricClaymore
let Output[1][9][5]["ProductID"] := WeapDaedricWarAxe
let Output[1][9][6]["ProductID"] := WeapDaedricWarHammer

SetFunctionValue ar_DeepCopy Output

End

 

This is the code you actually put on your activator.

ScriptName 0ebmArmourAnvil

array_var Equipment

ref product
ref material

short eqtype	;0 = armor, 1 = weapons
short mattype	;0 = copper, 1 = bronze, 2 = iron, 3 = steel, 4 = dwarfite, 5 = ayliite, 6 = crystalite, 7 = mithril, 8 = ebony, 9 = daedric
short piece		;for armor: 0 = boots, 1 = cuirass, 2 = gauntlets, 3 = greaves, 4 = helmet, 5 = shield
			;for weapons: 0 = dagger, 1 = arrow tips, 2 = short sword, 3 = long sword, 4 = claymore, 5 = war axe, 6 = war hammer
short armorerskill
short menu
short choice
short matcost
short smithing

Begin OnActivate

if (Equipment == 0)
	let Equipment := Call BuildSmithingArray
endif

if (Player.GetEquipped BlackSmithHammer)
	let menu := 1
	let armorerskill := Player.GetAV Armorer
else
	Message "Not wearing suitable gear."
endif

End

Begin GameMode

if (menu == 0) && (smithing == 0)

	Return

elseif (menu == 9999)

	let menu := 0
	Message "Smithing cancelled."
	Return

elseif (menu == 1)

	let menu := -1
	MessageBoxEX "Would you like to smith armor or weapons?|Armor >|Weapons >|Cancel"

elseif (menu == -1)

	let choice := GetButtonPressed
	if (choice < 0)
		Return
	elseif (choice == 2)
		let menu := 9999
		Return
	else
		let menu := 10
		let eqtype := choice
	endif

elseif (menu == 10)

	let menu := -10
	MessageBoxEX "Choose material:|Copper >|Bronze >|Iron >|Steel >|Dwarfite >|Ayliite >|Crystalite >|Next Page >|< Back|Cancel"

elseif (menu == -10)

	let choice := GetButtonPressed
	if (choice < 0)
		Return
	elseif (choice == 9)
		let menu := 9999
		Return
	elseif (choice == 8)
		let menu := 1
		Return
	elseif (choice == 7)
		let menu := 11
		Return
	else
		let mattype := choice
		let menu := 100
	endif

elseif (menu == 11)

	let menu := -11
	MessageBoxEX "Choose material:|Mithril >|Ebony >|Daedrite >|< Last Page|< Back|Cancel"

elseif (menu == -11)

	let choice := GetButtonPressed
	if (choice < 0)
		Return
	elseif (choice == 5)
		let menu := 9999
		Return
	elseif (choice == 4)
		let menu := 1
		Return
	elseif (choice == 3)
		let menu := 10
		Return
	else
		let mattype := choice + 7
		let menu := 100
	endif

elseif (menu == 100)

	if ((mattype == 0) && (armorerskill < 1)) || ((mattype == 1) && (armorerskill < 5)) || ((mattype == 2) && (armorerskill < 10)) || ((mattype == 3) && (armorerskill < 15))
		let menu := -100
		MessageBoxEX "You don't have high enough armorer skill to smith this item!|< Back|Cancel"
	elseif ((mattype == 4) && (armorerskill < 25)) || ((mattype == 5) && (armorerskill < 30)) || ((mattype == 6) && (armorerskill < 35)) || ((mattype == 7) && (armorerskill < 45))
		let menu := -100
		MessageBoxEX "You don't have high enough armorer skill to smith this item!|< Back|Cancel"
	elseif ((mattype == 8) && (armorerskill < 55)) || ((mattype == 9) && (armorerskill < 70))
		let menu := -100
		MessageBoxEX "You don't have high enough armorer skill to smith this item!|< Back|Cancel"
	else
		let menu := -101
		if (eqtype == 0)
			MessageBoxEX "Choose armor piece:|Boots|Cuirass|Gauntlets|Greaves|Helmet|Shield|Full Set of Armor|< Back|Cancel"
		elseif (eqtype == 1)
			MessageBoxEX "Choose weapon type:|Dagger|Arrow Tips|Shortsword|Longsword|Claymore|Waraxe|Warhammer|< Back|Cancel"
		endif
	endif

elseif (menu == -100)

	let choice := GetButtonPressed
	if (choice < 0)
		Return
	elseif (choice == 0)
		let menu := 10
		Return
	elseif (choice == 1)
		let menu := 9999
		Return
	endif

elseif (menu == -101)

	let choice := GetButtonPressed
	if (choice < 0)
		Return
	elseif (choice == 8)
		let menu := 9999
		Return
	elseif (choice == 7)
		let menu := 10
		Return
	elseif (eqtype == 0) && (choice == 6)
		let smithing := 2
		let material := Equipment[eqtype][mattype][0]["MatID"]
		let matcost := 19
		let menu := 1000
	else
		let smithing := 1
		let piece := choice
		let product := Equipment[eqtype][mattype][piece]["ProductID"]
		let material := Equipment[eqtype][mattype][piece]["MatID"]
		let matcost := Equipment[eqtype][mattype][piece]["MatCost"]
		let menu := 1000
	endif

elseif (menu == 1000)
	
	if (Player.GetItemCount material < matcost)
		let menu := -1000
		let smithing := 0
		MessageBoxEX "Not enough materials.|< Back|Cancel"
	else
		let menu := 0
	endif

elseif (menu == -1000)

	let choice := GetButtonPressed
	if (choice < 0)
		Return
	elseif (choice == 0)
		let menu := 100
		Return
	elseif (choice == 1)
		let menu := 9999
		Return
	endif

endif

if (smithing > 0) && (menu == 0)
	if (smithing == 1)
		let smithing := 0
		Player.RemoveItem material matcost
		Player.AddItem product 1
		Message "Smithing success."
	elseif (smithing == 2)
		let smithing := 0
		Player.RemoveItem material matcost
		let piece := 0
		while (piece < ar_Size Equipment[eqtype][mattype])
			let product := Equipment[eqtype][mattype]["ProductID"]
			Player.AddItem product 1
			let piece += 1
		loop
		Message "Smithing success."
	endif
endif

End

 

 

This is the version that doesn't require OBSE:

 

ScriptName 0ebmArmourAnvil

ref product
ref material

short eqtype	;0 = armor, 1 = weapons
short piece		;for armor: 0 = boots, 1 = cuirass, 2 = gauntsets, 3 = greaves, 4 = helmet, 5 = shield
			;for weapons: 0 = dagger, 1 = arrow tips, 2 = short sword, 3 = long sword, 4 = claymore, 5 = war axe, 6 = war hammer
short armorerskill
short menu
short choice
short matcost
short smithing

Begin OnActivate

if (Player.GetEquipped BlackSmithHammer)
	set menu to 1
	set armorerskill to Player.GetAV Armorer
else
	Message "Not wearing suitable gear."
endif

End

Begin GameMode

if (menu == 0) && (smithing == 0)
	Return
endif

if (menu == 1)
	set menu to -1
	MessageBox "Would you like to smith armor or weapons?" "Armor >" "Weapons >" "Cancel"
endif

if (menu == -1)
	set choice to GetButtonPressed
	if (choice == 2)
		set menu to 0
		Message "Smithing cancelled."
	elseif (choice >= 0)
		set menu to 10
		set eqtype to choice
	endif
	Return
endif

if (menu == 10)
	set menu to -10
	MessageBox "Choose material:" "Copper >" "Bronze >" "Iron >" "Steel >" "Dwarfite >" "Ayliite >" "Crystalite >" "Next Page >" "< Back" "Cancel"
endif

if (menu == -10)
	set choice to GetButtonPressed
	if (choice == 9)
		set menu to 0
		Message "Smithing cancelled."
	elseif (choice == 8)
		set menu to 1
	elseif (choice == 7)
		set menu to 11
	elseif (choice >= 0)
		if (choice == 0)
			set material to CopperBar
		elseif (choice == 1)
			set material to BronzeBar
		elseif (choice == 2)
			set material to IronBar
		elseif (choice == 3)
			set material to SteelBar
		elseif (choice == 4)
			set material to DwarfiteBar
		elseif (choice == 5)
			set material to AyliiteBar
		elseif (choice == 6)
			set material to CrystaliteBar
		endif
		set menu to 100
	endif
	Return
endif

if (menu == 11)
	set menu to -11
	MessageBox "Choose material:" "Mithril >" "Ebony >" "Daedrite >" "< Last Page" "< Back" "Cancel"
endif

if (menu == -11)
	set choice to GetButtonPressed
	if (choice == 5)
		set menu to 0
		Message "Smithing cancelled."
		Return
	elseif (choice == 4)
		set menu to 1
		Return
	elseif (choice == 3)
		set menu to 10
		Return
	elseif (choice >= 0)
		if (choice == 0)
			set material to MithrilBar
		elseif (choice == 1)
			set material to EbonyBar
		elseif (choice == 2)
			set material to DaedriteBar
		endif
		set menu to 100
	endif
	Return
endif

if (menu == 100)
	if ((material == CopperBar) && (armorerskill < 1)) || ((material == BronzeBar) && (armorerskill < 5)) || ((material == IronBar) && (armorerskill < 10)) || ((material == SteelBar) && (armorerskill < 15))
		set menu to -100
		MessageBox "You don't have high enough armorer skill to smith this item!" "< Back" "Cancel"
	elseif ((material == DwarfiteBar) && (armorerskill < 25)) || ((material == AyliiteBar) && (armorerskill < 30)) || ((material == CrystaliteBar) && (armorerskill < 35)) || ((material == MithrilBar) && (armorerskill < 45))
		set menu to -100
		MessageBox "You don't have high enough armorer skill to smith this item!" "< Back" "Cancel"
	elseif ((material == EbonyBar) && (armorerskill < 55)) || ((material == DaedricBar) && (armorerskill < 70))
		set menu to -100
		MessageBox "You don't have high enough armorer skill to smith this item!" "< Back" "Cancel"
	else
		set menu to -101
		if (eqtype == 0)
			MessageBox "Choose armor piece:" "Boots" "Cuirass" "Gauntsets" "Greaves" "Helmet" "Shield" "Full Set of Armor" "< Back" "Cancel"
		elseif (eqtype == 1)
			MessageBox "Choose weapon type:" "Dagger" "Arrow Tips" "Shortsword" "Longsword" "Claymore" "Waraxe" "Warhammer" "< Back" "Cancel"
		endif
	endif
endif

if (menu == -100)
	set choice to GetButtonPressed
	if (choice == 0)
		set menu to 10
	elseif (choice == 1)
		set menu to 0
		Message "Smithing cancelled."
	endif
	Return
endif

if (menu == -101)
	set choice to GetButtonPressed
	if (choice == 8)
		set menu to 0
		Message "Smithing cancelled."
	elseif (choice == 7)
		set menu to 10
	elseif (eqtype == 0) && (choice == 6)
		set smithing to 2
		set matcost to 19
		set menu to 1000
	elseif (choice >= 0)
		set smithing to 1
		set piece to choice
		if (eqtype == 0)
			if (piece == 0)
				set matcost to 3
			elseif (piece == 1)
				set matcost to 5
			elseif (piece == 2)
				set matcost to 2
			elseif (piece == 3)
				set matcost to 4
			elseif (piece == 4)
				set matcost to 2
			elseif (piece == 5)
				set matcost to 3
			endif
		elseif (eqtype == 1)
			if (piece == 0)
				set matcost to 1
			elseif (piece == 1)
				set matcost to 1
			elseif (piece == 2)
				set matcost to 2
			elseif (piece == 3)
				set matcost to 3
			elseif (piece == 4)
				set matcost to 4
			elseif (piece == 5)
				set matcost to 3
			elseif (piece == 6)
				set matcost to 4
			endif
		endif
		set menu to 1000
	endif
	Return
endif

if (menu == 1000)
	if (Player.GetItemCount material < matcost)
		set menu to -1000
		set smithing to 0
		MessageBox "Not enough materials." "< Back" "Cancel"
	else
		set menu to 0
	endif
endif

if (menu == -1000)
	set choice to GetButtonPressed
	if (choice == 0)
		set menu to 100
	elseif (choice == 1)
		set menu to 0
		Message "Smithing cancelled."
	endif
	Return
endif

if (smithing > 0) && (menu == 0)
	if (smithing == 1)
		set smithing to 0
		if (eqtype == 0)
			if (material == CopperBar)
				if (piece == 0)
					set product to CopperBoots
				elseif (piece == 1)
					set product to CopperCuirass
				elseif (piece == 2)
					set product to CopperGauntlets
				elseif (piece == 3)
					set product to CopperGreaves
				elseif (piece == 4)
					set product to CopperHelmet
				elseif (piece == 5)
					set product to CopperShield
				endif
			elseif (material == BronzeBar)
				if (piece == 0)
					set product to BronzeBoots
				elseif (piece == 1)
					set product to BronzeCuirass
				elseif (piece == 2)
					set product to BronzeGauntlets
				elseif (piece == 3)
					set product to BronzeGreaves
				elseif (piece == 4)
					set product to BronzeHelmet
				elseif (piece == 5)
					set product to BronzeShield
				endif
			elseif (material == IronBar)
				if (piece == 0)
					set product to IronBoots
				elseif (piece == 1)
					set product to IronCuirass
				elseif (piece == 2)
					set product to IronGauntlets
				elseif (piece == 3)
					set product to IronGreaves
				elseif (piece == 4)
					set product to IronHelmet
				elseif (piece == 5)
					set product to IronShield
				endif
			elseif (material == SteelBar)
				if (piece == 0)
					set product to SteelBoots
				elseif (piece == 1)
					set product to SteelCuirass
				elseif (piece == 2)
					set product to SteelGauntlets
				elseif (piece == 3)
					set product to SteelGreaves
				elseif (piece == 4)
					set product to SteelHelmet
				elseif (piece == 5)
					set product to SteelShield
				endif
			elseif (material == DwarfiteBar)
				if (piece == 0)
					set product to DwarvenBoots
				elseif (piece == 1)
					set product to DwarvenCuirass
				elseif (piece == 2)
					set product to DwarvenGauntlets
				elseif (piece == 3)
					set product to DwarvenGreaves
				elseif (piece == 4)
					set product to DwarvenHelmet
				elseif (piece == 5)
					set product to DwarvenShield
				endif
			elseif (material == AyliiteBar)
				if (piece == 0)
					set product to ElvenBoots
				elseif (piece == 1)
					set product to ElvenCuirass
				elseif (piece == 2)
					set product to ElvenGauntlets
				elseif (piece == 3)
					set product to ElvenGreaves
				elseif (piece == 4)
					set product to ElvenHelmet
				elseif (piece == 5)
					set product to ElvenShield
				endif
			elseif (material == CrystaliteBar)
				if (piece == 0)
					set product to GlassBoots
				elseif (piece == 1)
					set product to GlassCuirass
				elseif (piece == 2)
					set product to GlassGauntlets
				elseif (piece == 3)
					set product to GlassGreaves
				elseif (piece == 4)
					set product to GlassHelmet
				elseif (piece == 5)
					set product to GlassShield
				endif
			elseif (material == MithrilBar)
				if (piece == 0)
					set product to MithrilBoots
				elseif (piece == 1)
					set product to MithrilCuirass
				elseif (piece == 2)
					set product to MithrilGauntlets
				elseif (piece == 3)
					set product to MithrilGreaves
				elseif (piece == 4)
					set product to MithrilHelmet
				elseif (piece == 5)
					set product to MithrilShield
				endif
			elseif (material == EbonyBar)
				if (piece == 0)
					set product to EbonyBoots
				elseif (piece == 1)
					set product to EbonyCuirass
				elseif (piece == 2)
					set product to EbonyGauntlets
				elseif (piece == 3)
					set product to EbonyGreaves
				elseif (piece == 4)
					set product to EbonyHelmet
				elseif (piece == 5)
					set product to EbonyShield
				endif
			elseif (material == DaedriteBar)
				if (piece == 0)
					set product to DaedricBoots
				elseif (piece == 1)
					set product to DaedricCuirass
				elseif (piece == 2)
					set product to DaedricGauntlets
				elseif (piece == 3)
					set product to DaedricGreaves
				elseif (piece == 4)
					set product to DaedricHelmet
				elseif (piece == 5)
					set product to DaedricShield
				endif
			endif
		elseif (eqtype == 1)
			if (material == CopperBar)
				if (piece == 0)
					set product to CopperDagger
				elseif (piece == 1)
					set product to CopperArrowTips
				elseif (piece == 2)
					set product to CopperShortsword
				elseif (piece == 3)
					set product to CopperLongsword
				elseif (piece == 4)
					set product to CopperClaymore
				elseif (piece == 5)
					set product to CopperWarAxe
				elseif (piece == 6)
					set product to CopperWarHammer
				endif
			elseif (material == BronzeBar)
				if (piece == 0)
					set product to BronzeDagger
				elseif (piece == 1)
					set product to BronzeArrowTips
				elseif (piece == 2)
					set product to BronzeShortsword
				elseif (piece == 3)
					set product to BronzeLongsword
				elseif (piece == 4)
					set product to BronzeClaymore
				elseif (piece == 5)
					set product to BronzeWarAxe
				elseif (piece == 6)
					set product to BronzeWarHammer
				endif
			elseif (material == IronBar)
				if (piece == 0)
					set product to WeapIronDagger
				elseif (piece == 1)
					set product to IronArrowTips
				elseif (piece == 2)
					set product to WeapIronShortsword
				elseif (piece == 3)
					set product to WeapIronLongsword
				elseif (piece == 4)
					set product to WeapIronClaymore
				elseif (piece == 5)
					set product to WeapIronWarAxe
				elseif (piece == 6)
					set product to WeapIronWarHammer
				endif
			elseif (material == SteelBar)
				if (piece == 0)
					set product to WeapSteelDagger
				elseif (piece == 1)
					set product to SteelArrowTips
				elseif (piece == 2)
					set product to WeapSteelShortsword
				elseif (piece == 3)
					set product to WeapSteelLongsword
				elseif (piece == 4)
					set product to WeapSteelClaymore
				elseif (piece == 5)
					set product to WeapSteelWarAxe
				elseif (piece == 6)
					set product to WeapSteelWarHammer
				endif
			elseif (material == DwarfiteBar)
				if (piece == 0)
					set product to WeapDwarvenDagger
				elseif (piece == 1)
					set product to DwarvenArrowTips
				elseif (piece == 2)
					set product to WeapDwarvenShortsword
				elseif (piece == 3)
					set product to WeapDwarvenLongsword
				elseif (piece == 4)
					set product to WeapDwarvenClaymore
				elseif (piece == 5)
					set product to WeapDwarvenWarAxe
				elseif (piece == 6)
					set product to WeapDwarvenWarHammer
				endif
			elseif (material == AyliiteBar)
				if (piece == 0)
					set product to WeapElvenDagger
				elseif (piece == 1)
					set product to ElvenArrowTips
				elseif (piece == 2)
					set product to WeapElvenShortsword
				elseif (piece == 3)
					set product to WeapElvenLongsword
				elseif (piece == 4)
					set product to WeapElvenClaymore
				elseif (piece == 5)
					set product to WeapElvenWarAxe
				elseif (piece == 6)
					set product to WeapElvenWarHammer
				endif
			elseif (material == CrystaliteBar)
				if (piece == 0)
					set product to WeapGlassDagger
				elseif (piece == 1)
					set product to GlassArrowTips
				elseif (piece == 2)
					set product to WeapGlassShortsword
				elseif (piece == 3)
					set product to WeapGlassLongsword
				elseif (piece == 4)
					set product to WeapGlassClaymore
				elseif (piece == 5)
					set product to WeapGlassWarAxe
				elseif (piece == 6)
					set product to WeapGlassWarHammer
				endif
			elseif (material == MithrilBar)
				if (piece == 0)
					set product to MithrilDagger
				elseif (piece == 1)
					set product to MithrilArrowTips
				elseif (piece == 2)
					set product to MithrilShortsword
				elseif (piece == 3)
					set product to MithrilLongsword
				elseif (piece == 4)
					set product to MithrilClaymore
				elseif (piece == 5)
					set product to MithrilWarAxe
				elseif (piece == 6)
					set product to MithrilWarHammer
				endif
			elseif (material == EbonyBar)
				if (piece == 0)
					set product to WeapEbonyDagger
				elseif (piece == 1)
					set product to EbonyArrowTips
				elseif (piece == 2)
					set product to WeapEbonyShortsword
				elseif (piece == 3)
					set product to WeapEbonyLongsword
				elseif (piece == 4)
					set product to WeapEbonyClaymore
				elseif (piece == 5)
					set product to WeapEbonyWarAxe
				elseif (piece == 6)
					set product to WeapEbonyWarHammer
				endif
			elseif (material == DaedriteBar)
				if (piece == 0)
					set product to WeapDaedricDagger
				elseif (piece == 1)
					set product to DaedricArrowTips
				elseif (piece == 2)
					set product to WeapDaedricShortsword
				elseif (piece == 3)
					set product to WeapDaedricLongsword
				elseif (piece == 4)
					set product to WeapDaedricClaymore
				elseif (piece == 5)
					set product to WeapDaedricWarAxe
				elseif (piece == 6)
					set product to WeapDaedricWarHammer
				endif
			endif
		endif
		Player.RemoveItem material matcost
		Player.AddItem product 1
		Message "Smithing success."
		Return
	elseif (smithing == 2)
		set smithing to 0
		Player.RemoveItem material matcost
		if (material == CopperBar)
			Player.AddItem CopperBoots 1
			Player.AddItem CopperCuirass 1
			Player.AddItem CopperGauntlets 1
			Player.AddItem CopperGreaves 1
			Player.AddItem CopperHelmet 1
			Player.AddItem CopperShield 1
		elseif (material == BronzeBar)
			Player.AddItem BronzeBoots 1
			Player.AddItem BronzeCuirass 1
			Player.AddItem BronzeGauntlets 1
			Player.AddItem BronzeGreaves 1
			Player.AddItem BronzeHelmet 1
			Player.AddItem BronzeShield 1
		elseif (material == IronBar)
			Player.AddItem IronBoots 1
			Player.AddItem IronCuirass 1
			Player.AddItem IronGauntlets 1
			Player.AddItem IronGreaves 1
			Player.AddItem IronHelmet 1
			Player.AddItem IronShield 1
		elseif (material == SteelBar)
			Player.AddItem SteelBoots 1
			Player.AddItem SteelCuirass 1
			Player.AddItem SteelGauntlets 1
			Player.AddItem SteelGreaves 1
			Player.AddItem SteelHelmet 1
			Player.AddItem SteelShield 1
		elseif (material == DwarfiteBar)
			Player.AddItem DwarvenBoots 1
			Player.AddItem DwarvenCuirass 1
			Player.AddItem DwarvenGauntlets 1
			Player.AddItem DwarvenGreaves 1
			Player.AddItem DwarvenHelmet 1
			Player.AddItem DwarvenShield 1
		elseif (material == AyliiteBar)
			Player.AddItem ElvenBoots 1
			Player.AddItem ElvenCuirass 1
			Player.AddItem ElvenGauntlets 1
			Player.AddItem ElvenGreaves 1
			Player.AddItem ElvenHelmet 1
			Player.AddItem ElvenShield 1
		elseif (material == CrystaliteBar)
			Player.AddItem GlassBoots 1
			Player.AddItem GlassCuirass 1
			Player.AddItem GlassGauntlets 1
			Player.AddItem GlassGreaves 1
			Player.AddItem GlassHelmet 1
			Player.AddItem GlassShield 1
		elseif (material == MithrilBar)
			Player.AddItem MithrilBoots 1
			Player.AddItem MithrilCuirass 1
			Player.AddItem MithrilGauntlets 1
			Player.AddItem MithrilGreaves 1
			Player.AddItem MithrilHelmet 1
			Player.AddItem MithrilShield 1
		elseif (material == EbonyBar)
			Player.AddItem EbonyBoots 1
			Player.AddItem EbonyCuirass 1
			Player.AddItem EbonyGauntlets 1
			Player.AddItem EbonyGreaves 1
			Player.AddItem EbonyHelmet 1
			Player.AddItem EbonyShield 1
		elseif (material == DaedriteBar)
			Player.AddItem DaedricBoots 1
			Player.AddItem DaedricCuirass 1
			Player.AddItem DaedricGauntlets 1
			Player.AddItem DaedricGreaves 1
			Player.AddItem DaedricHelmet 1
			Player.AddItem DaedricShield 1
		endif
		Message "Smithing success."
	endif
endif

End

 

 

The OBSE version is ~400 lines the first time you run it, then ~200 lines every time afterwards. The non OBSE version is ~600 lines.

Link to comment
Share on other sites

EDIT: And oh, those functions I wrote wouldn't be useful to you. They take an array of objects and then display each of those objects as a separate button.

 

fg, your solution is impressive, of course, but I still don't understand why you can't use user-defined functions after all. You even can avoind this lengthy array assignments. Just pass the IDs as function parameters. :)

Link to comment
Share on other sites

Indeed, but menus are just unavoidably long. Something to take into account when scripting is it's efficiency instead just it's length.

 

If a certain condition is satisfied which makes the remaining flow superfluous, consider using "Return" to force the script to terminate this passing, skipping everything else in it. For example in your menu processing for level 4x and above, once the level is processed and no other level is set, all those "If"s are granted to fail the test and could be skipped using return, which is like sending the flow directly to the End of the Begin Block. The same is not valid for level 3x where the next level to be verified is set, but could be considered in those cases where the script could terminate without problem (lack material? goodby, no need to test every other condition).

 

Just make sure there is no needed housekeeping in the end of the script (or putting one there later, forgetting it would never be reached because the return).

 

Actually that is not so important in menu scripts because the impact is negligible face the slow nature. But it can make a huge difference in long gamemode scripts running each frame in actual gaming environment.

Link to comment
Share on other sites

fg, your solution is impressive, of course, but I still don't understand why you can't use user-defined functions after all. You even can avoind this lengthy array assignments. Just pass the IDs as function parameters. :)

 

I did use a user-defined function. :huh:

 

If you meant I should have used a function for the other parts, there's really not much of a way to do so. The whole menu is in order to figure out the keys in the array so that the game can retrieve the form ID of the item to be "made". The only part that could be changed to using a function would be the 16 line "smithing" part at the end of the script.

 

Indeed, but menus are just unavoidably long. Something to take into account when scripting is it's efficiency instead just it's length.If a certain condition is satisfied which makes the remaining flow superfluous, consider using "Return" to force the script to terminate this passing, skipping everything else in it. For example in your menu processing for level 4x and above, once the level is processed and no other level is set, all those "If"s are granted to fail the test and could be skipped using return, which is like sending the flow directly to the End of the Begin Block. The same is not valid for level 3x where the next level to be verified is set, but could be considered in those cases where the script could terminate without problem (lack material? goodby, no need to test every other condition).Just make sure there is no needed housekeeping in the end of the script (or putting one there later, forgetting it would never be reached because the return).Actually that is not so important in menu scripts because the impact is negligible face the slow nature. But it can make a huge difference in long gamemode scripts running each frame in actual gaming environment.

 

Yes, I realized while adapting the OBSE based script into non-OBSE that I shouldn't have used a huge if block with many elseif's. I changed that into many smaller blocks with return statements instead. But I got lazy and didn't bother to go back and change the OBSE version the same way.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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