Workshop Script tutorial
Written by The Guild Master   
Thursday, 16 July 2009 13:03

Workshop Script tutorial

Introduction:

This is an old tutorial I wrote a few years back to explain how the Kvatch Aftermath Workshop worked. It is very useful for turning a number of items in to something else. In this case it allows you to produce armour from raw ore. But you could use it to make potions from ingredients or anything like that. 

The Script.

Heres a little script to add extra gameplay to Oblivion. It does for silver what alchemy does for plants and has option skill increases commented out in here (if anybody knows how to get 1/10 of a point let me know, 0.1 does not work in the editor.

Im going to explain this one as well as posting it so those learning to script can see why it works the way it works. First a run down for those who want the script but dont want to learn how it works.

Usage
Add the script to an object that can be used, a repair hammer is good, just copy the repair hammer entry in the editor and give it a new ID name. Then rename the label to say something like Armour Maker or what ever. Add the script to the "Armour maker" hammer and place the hammer on an Anvil somewhere and the player will be presented with a menu of various mithril armour components he can make if he has the right number of silver nuggets and his armourer skill allows him to make it.

The script will always remove the required nuggets even if the attempt to make the armour fails. Also most of the armour costs more than the nuggets so its possible to become an armour manufactor with this script.


;Usage
; Add to an object the player would use to make armour such as a copied and edited Repair hammer.
; Do not use the default repair hammers, always copy, change the name, then add the script.
scn WorkshopScript

short button
short chance

begin OnActivate
if ( IsActionRef Player == 1 )
Messagebox "What piece of Mithril Armour do you wish to forge","Boots", "Cuirass","Gauntlets","Greaves","Helmet","Shield"
set chance to GetRandomPercent + 20
endif
end

begin gamemode

set button to getbuttonpressed

if button > -1

if button == 0
if (chance < player.GetActorValue Armorer) && (player.GetItemCount Gem0SilverNugget >= 2)
Playsound UIArmorWeaponRepair
player.additem MithrilBoots 1
Player.RemoveItem Gem0SilverNugget 2
;ModPCSkill Armorer 1
else
if (player.GetItemCount Gem0SilverNugget >= 2)
Message "You try and make a pair of boots but end up with a mangled mess."
Player.RemoveItem Gem0SilverNugget 2
else
Message "2 Silver Nuggets needed to make a pair of boots."
endif
endif
endif

if button == 1
if (chance < player.GetActorValue Armorer) && (player.GetItemCount Gem0SilverNugget >= 5)
Playsound UIArmorWeaponRepair
player.additem MithrilCuirass 1
Player.RemoveItem Gem0SilverNugget 5
;ModPCSkill Armorer 1
else
if (player.GetItemCount Gem0SilverNugget >= 5)
Message "You try and make a Cuirass but end up with a mangled mess."
Player.RemoveItem Gem0SilverNugget 5
else
Message "5 Silver Nuggets needed to make a Cuirass. "
endif
endif
endif

if button == 2
if (chance < player.GetActorValue Armorer) && (player.GetItemCount Gem0SilverNugget >= 2)
Playsound UIArmorWeaponRepair
player.additem MithrilGauntlets 1
Player.RemoveItem Gem0SilverNugget 2
;ModPCSkill Armorer 1
else
if (player.GetItemCount Gem0SilverNugget >= 2)
Message "You try and make a pair of Gauntlets but end up with a mangled mess."
Player.RemoveItem Gem0SilverNugget 2
else
Message "2 Silver Nuggets needed to make a pair of Gauntlets."
endif
endif
endif

if button == 3
if (chance < player.GetActorValue Armorer) && (player.GetItemCount Gem0SilverNugget >= 4)
Playsound UIArmorWeaponRepair
player.additem MithrilGreaves 1
Player.RemoveItem Gem0SilverNugget 4
;ModPCSkill Armorer 1
else
if (player.GetItemCount Gem0SilverNugget >= 4)
Message "You try and make a set of Greaves but end up with a mangled mess."
Player.RemoveItem Gem0SilverNugget 4
else
Message "4 Silver Nuggets needed to make a set of Greaves. "
endif
endif
endif

if button == 4
if (chance < player.GetActorValue Armorer) && (player.GetItemCount Gem0SilverNugget >= 2)
Playsound UIArmorWeaponRepair
player.additem MithrilHelmet 1
Player.RemoveItem Gem0SilverNugget 2
;ModPCSkill Armorer 1
else
if (player.GetItemCount Gem0SilverNugget >= 2)
Message "You try and make a Helmet but end up with a mangled mess."
Player.RemoveItem Gem0SilverNugget 2
else
Message "2 Silver Nuggets needed to make a Helmet"
endif
endif
endif

if button == 5
if (chance < player.GetActorValue Armorer) && (player.GetItemCount Gem0SilverNugget >= 3)
Playsound UIArmorWeaponRepair
player.additem MithrilShield 1
Player.RemoveItem Gem0SilverNugget 3
;ModPCSkill Armorer 1
else
if (player.GetItemCount Gem0SilverNugget >= 3)
Message "You try and make a Shield but end up with a mangled mess."
Player.RemoveItem Gem0SilverNugget 3
else
Message "3 Silver Nuggets needed to make a Shield"
endif
endif
endif


endif

end


Heres a much simpler ring script which is the same as above but easier to explain for those who want to know how it works.


scn koablacksmithringsScript

short button
short chance

begin OnActivate
if ( IsActionRef Player == 1 )
Messagebox "What type of item do you wish to forge","Silver Ring", "Gold Ring"
set chance to GetRandomPercent
endif
end

begin gamemode

set button to getbuttonpressed

if button > -1

if button == 0
if (chance < player.GetActorValue Armorer) && (player.GetItemCount Gem0SilverNugget >= 1)
Playsound UIArmorWeaponRepair
player.additem JewelryRing4Silver 1
Player.RemoveItem Gem0SilverNugget 1
;ModPCSkill Armorer 1
else
if (player.GetItemCount Gem0SilverNugget >= 1)
Message "You try and make Silver Ring but end up with a mangled mess."
Player.RemoveItem Gem0SilverNugget 1
else
Message "1 Silver Nugget needed to make Silver Rings"
endif
endif
endif

if button == 1
if (chance < player.GetActorValue Armorer) && (player.GetItemCount Gem0GoldNugget >= 1)
Playsound UIArmorWeaponRepair
player.additem JewelryRing5Gold 1
Player.RemoveItem Gem0GoldNugget 1
;ModPCSkill Armorer 1
else
if (player.GetItemCount Gem0GoldNugget >= 1)
Message "You try and make Gold Ring but end up with a mangled mess."
Player.RemoveItem Gem0GoldNugget 1
else
Message "1 Gold Nugget needed to make Gold Rings"
endif
endif
endif

endif

end



scn koablacksmithringsScript

short button
short chance


The above stuff is the name of the script, in this case its for my kingdom of almar mod or KOA for short and its a blacksmith ring script. Hense the name koablacksmithringsScript.

The short XXXX stuff is vars i use in the script below, they must be declared before use so ive shout out, hay im using these short vars in this script. Short is a command that identifes your own vars and a var can be name word or anything that best scribes what data the var will hold. You can have a "myfatpig" var or a "Manchesterunitiedsuck" var, the actual name doesnt matter, it just helps us mortals know what its for if it describes what it does.


begin OnActivate
if ( IsActionRef Player == 1 )
Messagebox "What type of item do you wish to forge","Silver Ring", "Gold Ring"
set chance to GetRandomPercent
endif
end


What happens when its used, thats what OnActivate does.

This "if ( IsActionRef Player == 1 )" means Is the player the one activing it.
If so, display the messagebox text and ask if the player wants a silver ring or a gold ring by presenting them as buttons he can click on, then set chance to GetRandomPercent.

GetRandomPercent just chooses a number between 0 and 99. Nothing more complex than that. You may notice on the armour script i have the following line here instead.

set chance to GetRandomPercent + 20

This says pick a number between 0 and 99 then add 20 to the result.
Why do i do that ?

Well in order for the player to make anything, the chance var must be less than the players armour skill. So if i add 20 to the result and the lowest number chance can return is 0, then the lowest Armorer skill needed to make any piece of armour is going to be 20, so at skill 20, a player as a 1 in 100 chance of making some armour. The rings dont have +20 so the player has a chance equal to his own armour skill out of 100 to make a ring. Starting small is often easier and it makes sense for rings to be easier to make than suits of armour.

begin gamemode


This causes the script run multiple times a second or something along those lines, the END command at the end, finishes this gamemode block. Everything in between is what actually does the job.


set button to getbuttonpressed

if button > -1


Set the button to an unused state and wait for the player to press something. First entry is button 0 eg silver ring, second is button 1 eg gold ring. If there was a third entry it would be button 2 and so on.



if button == 0
if (chance < player.GetActorValue Armorer) && (player.GetItemCount Gem0SilverNugget >= 1)
Playsound UIArmorWeaponRepair
player.additem JewelryRing4Silver 1
Player.RemoveItem Gem0SilverNugget 1
;ModPCSkill Armorer 1
else
if (player.GetItemCount Gem0SilverNugget >= 1)
Message "You try and make Silver Ring but end up with a mangled mess."
Player.RemoveItem Gem0SilverNugget 1
else
Message "1 Silver Nugget needed to make Silver Rings"
endif
endif
endif


I only need to explain 1 button to explain them all, so im going to not explain the buttons below here but i'll leave them in and quoted so not to confuse anybody.

Translation "if button == 0" actually means IF silver ring was selected because silver ring was the first option in the messagebox text above.



if (chance < player.GetActorValue Armorer) && (player.GetItemCount Gem0SilverNugget >= 1)


This says if "chance", chance being the random number between 1 and 100 is less than (thats what < means, eg less than) the players armour skill value thats the "player.GetActorValue Armorer" part, and (&&) player has at least (player.GetItemCount) 1 or more (>= 1) silver nuggets (Gem0SilverNugget) then you can run the next bit, but if he does not, then skip to the ELSE part instead and do that.


;ModPCSkill Armorer 1


If the ; part was removed, each time the player made a ring, he would earn him self 1 point on his armourer skill, but 1 pt is too much and i dont know how to make it less than 1 so ive commented this out.



else


Everything after the ELSE is what happens if player does not have the right armour skill or has not nuggets. In otherwords, if the player is being a right old stupid nugget and trying to make rings out of thin air, the script does this next part.


if (player.GetItemCount Gem0SilverNugget >= 1)

If the player has greater than 1 Chicken Mcnugget sorry i mean silver nugget hehe. This checks if it failed not because of a lack of nugget but a bad armourer skill check, if that is why it failed it displays the following message.

Message "You try and make Silver Ring but end up with a mangled mess."

Always try and use messages that describe what would happen in real life if you tried to do something, dont use "you failed your skill check, thats just lame for a roll play game.

Player.RemoveItem Gem0SilverNugget 1

Even if the player fails he must use up 1 nugget so here we remove 1 nugget from the player.
Notice the of Player.RemoveItem, thats used a lot, you add the actor in this case the player to the start of the command in this case RemoveItem. If you need to search for a command, drop the Player. and just search for the RemoveItem to find out about it. You will get all info about i that way.


else
Message "1 Gold Nugget needed to make Gold Rings"
endif
endif
endif


Ok we checked if the armour skill failed, if the failure was anything els,e this appears, since theres only 2 reasons it could fail and 1 was a poor armour skill and the other a lack of nuggets. The ELSE part just assumes its a lack of nuggets. So if you wanted to call the player a stupid nugget for forgetting the nuggets, then this is where youd do it. But i found telling them what they need to be helpful. So ive used that instead.

Everything below here works the same way for different buttons, its only when you read the word END are you not dealing with some sort of button entry. The Word END finishes off the command above that says "begin gamemode". Skip to he end now for a final word on endings.


if button == 1
if (chance < player.GetActorValue Armorer) && (player.GetItemCount Gem0GoldNugget >= 1)
Playsound UIArmorWeaponRepair
player.additem JewelryRing5Gold 1
Player.RemoveItem Gem0GoldNugget 1
;ModPCSkill Armorer 1
else
if (player.GetItemCount Gem0GoldNugget >= 1)
Message "You try and make Gold Ring but end up with a mangled mess."
Player.RemoveItem Gem0GoldNugget 1
else
Message "1 Gold Nugget needed to make Gold Rings"
endif
endif
endif

endif

end


You may have noticed that theres 2 ENDs in this script.

Theres also this one.

begin OnActivate
if ( IsActionRef Player == 1 )
Messagebox "What type of item do you wish to forge","Silver Ring", "Gold Ring"
set chance to GetRandomPercent
endif
end


As you can see, this one starts with a Begin command too and it ends with the word END.

That means you can have more than one BEGIN line in a script, in fact i believe you can several, each one is basically an independant script in its own right but will share the same short vars which can be incredibly useful when you want one script to know what the value of CHANCE is above. If its in the same script, the value is always known as is the case here where chance appears in both Begin OnActivate and Begin Gamemode.

As you can see the script just takes away nuggets and replaces them with an item, so you could take away gold and replace it with something made of gold or have diamond rings by taking away gold and diamonds at the same time.

Enjoy

 

This is the end...my friend.

Copyright © 2010 The Engineering Guild. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.