Heroes of Might and Magic Community
visiting hero! Register | Today's Posts | Games | Search! | FAQ/Rules | AvatarList | MemberList | Profile


[X] Remove Ads
LOGIN:     Username:     Password:         [ Register ]
HOMM1: info forum | HOMM2: info forum | HOMM3: info forum | HOMM4: info forum | HOMM5: info forum | MMH6: wiki forum | MMH7: wiki forum
Heroes Community > Heroes 4 - Lands of Axeoth > Thread: Beginner's Guide to Scripting
Thread: Beginner's Guide to Scripting
Kujo
Kujo


Known Hero
who loves to script.
posted November 28, 2002 08:55 PM bonus applied.
Edited By: Kujo on 1 Dec 2002

Beginner's Guide to Scripting

This is for all you people out there who complain about there being no manual for scripting. HERE IT IS! In this thread I am going to tell you all the commands you can script with, as well as how to use them and also examples. No more whining after this about no manual.

Section 1: Basic Scripting in HOMM4
This section will explain all the very basic commands, sequence, conditional action, ask question, remove script, display message, and delete adventure object.

Script 1: Sequencing
The sequence command is used for long scripts, which involve many different commands. It can hold several different scripts before it will kick you out of the editor. To add a new script to a sequence, simply click New. After clicking New a list will pop up allowing you to choose from the scripts you want. Choose it, and then do whatever scripts you please. Here is an example.

Ex1: Using the Sequence
Go into Adventure Objects, Quests, and pick out a quest hut. Drag the hut out onto the ground, and let it go. Double click on the hut to bring up the scripting section. Click on the Triggered Script tab and the default is Sequence. In this example we will just deal with do nothing. After bringing up sequence, click New. Push enter, and the command Do Nothing appears. Click New again, and push enter once more, and Do Nothing appears again. You have just created a Sequence!

Script 2: Asking Questions
The Ask Questions script is useful for, yep you guessed it, asking questions! To use ask question, take your quest hut from above, and go into triggered script once more. Instead of playing with sequence, click the drag down arrow and push A. The Ask Question script format will appear. At the top it says Ask, and below there is an empty white box. Under that, it says If Yes, If No, both followed by Do nothing. In order for Ask Question to be properly used, you must have a question, and 2 answers. Here is an example.

Ex2: Asking Questions
For this example, we will be asking the question Do you like Heroes of Might and Magic 4? Type the question into the white box, and then click Edit in the If yes box. A drop down arrow will appear, with WOW! That's a lot of choices. Which one should we choose for this? Well, let's go with the Display message option. I like to use the hotkey E to get to Display Message. It takes you to Enable Standard Victory script, and then you simply push the up arrow twice. When you get to Display Message, type in Wow! I like Heroes too. After doing that, push OK at the bottom, and then choose the If no edit. Type in That's too bad, Heroes is a great game, and push OK. To finish the script, push OK again. You have just asked a (very simple) question.

Script 3: Remove Script
Since I have already shown Display Message in the previous example, I will skip to Remove Script. Remove Script can be very vicious, depending on how you use it. It cancels all activities that follow it.
Here is a script that I have done:

Ex3: Remove Script
Sequence
New
Display Message: Testing
Remove Script
Click on the quest hut once, and it will display Testing. Then try to click it again, and it will not. Remove Script has cancelled the Display Message script.

Script 4: Deleting Adventure Objects.
This script, whose icon is a stick of dynamite, deletes any adventure object which the user has placed it upon. There is one exception to its rule, though. It cannot delete heroes, towns, mines, and anything else which can occupy monsters or other heroes. This is a very powerful script, and if used correctly produces splendid results.

Ex4: Blowing up a Mountain
For the purposes of this example, you will need a stick of dynamite, a mountain, and a quest hut. First, lay the quest hut on the ground, as well as the mountain. Then open the menu of the quest hut and go to the Triggered Script tab. Press E to get to Enable Standard Victory Conditon, and then press up 4 times to arrive at Delete Adventure Object. Type in any name you want; I chose mountain. Next, take a stick of dynamite (Adventure Objects->Miscellaneous) and lay it on top of the mountain. Name it whatever you named the event in the quest hut, and then press OK. The event has now been set and will be activated when the hero enters the quest hut.

These are the very basics of scripting. I will now go into more complicated scripts, such as variables, numeric variables, and triggering custom events.

Section 2: Advanced Scripting in HOMM4
So far we have learned to sequence, create conditional actions, display messages, and remove scripts. In this section, numeric and boolean variables will be covered, as well as custom event triggering.

Script 1: Boolean Variables
What is a boolean variable you ask? Well, a boolean variable is a variable that can be either true or false. True means that the variable does actually exist, and false means it doesn't. Here is an example of a time you might use boolean variables.

Ex1: Using Boolean Variables
In this example, we will be making a quest requirement being that the hero has visited a place, and so may complete the quest in the hut.
Step 1: Put down your quest hut like usual.
Step 2: Click on your quest hut, and go the tab named Quest Requirement. This takes you to a screen where there is the word False in the drop down arrow box. For this example, we will want to use variable, to create our boolean variable. Click the drop down arrow, and find Variable at the bottom. A shortcut is to simply press V. Variable appears in the box, followed by the words Enter Variable Name. When naming a variable, it must be either one word, or 2 words with an underscore (_) in it. For this example, let's name our variable Boolean_test. It doesn't matter what you name a variable, as long as you know what it is.
Step 3: Now, put any kind of adventure object down nearby the quest hut. I put a sawmill on mine. Next, go into Miscellaneous in Adventure Objects and scroll down until you find a yellow-orange circle that says Event. Drag Event onto the screen, and place it in front of your adventure object. Click on the Event and name it anyting you want; I named it Boolean. Now, go up to the bar at the top of the screen, and click on Campaign. The only option avaiable should be Map Properties, so go to that. A box with several tabs appears, with Map Name, Description, and Carryover Description boxes. Ignore those, and click on the Events tab. The default event is Timed Events, but for our tutorial we want Placed Events. Click on the arrow and scroll down, or simply press P to get to Placed Events. Click New, and a new event will be created. Type in the name of your event you placed on the ground (for the event to work they must be named the same EXACT thing) and then click on the Script tab. Our old friend Sequence is there, which we are familiar with. Click New to create a new script, and push S until you get to Set Boolean True/False Variable. The variable we created is already in the drop down box, so simply click on the box and push DOWN arrow. Your variable appears in the box, and is ready to be changed to True. To do this, click on the Edit button to the right of the box, and push T to change it to True. Click through all the OK's until you get back to the screen without any scripts. The result of this scripting is that when the hero visits the event, he will trigger it and set Boolean_test to True, and let him complete the event in the quest hut. You have successfully created a Boolean True/False Variable!!

Script 2: Numeric Variables
Numeric variables, my favorite. They are so powerful, yet so complicated to master. I, of course, have not mastered them, but am getting pretty close to doing so. What are numeric variables and what are they used for? Numeric variables are variables that use numbers instead of True/False, as above in Boolean variables. They can be used for practically everything in HOMM4, and there is almost no limit to their power. In the example below, I will illustrate how powerful they really are.

Ex2: The Almighty Numeric Variable!
Numeric variables are pretty complex, so if you're not a thinker you should probably leave. Just kidding . They really aren't that hard to use, just a little frustrating at times. In this example, I will show you how to do a basic Food and Water script, which takes 1 food from the hero every day and 1 water every 2 days. It involves Timed Events, too, which I have not gone into yet, but which are very simple.

For this example, you will not need a quest hut (yay! ), actually, you really don't need anything. All this script involves is Timed Events, and not many of those either. To create a Timed Event, go to Campaign->Map Properties->Events and Timed Events will be there. Create a new event by clicking New at the bottom, and get ready to script! There are 2 parts to the food and water script, a setting of variables and a taking of variables. We will do the setting part first. To accomplish this, name your Timed Event Set Variables and change the day to 1 if it isn't already on that. (it should be) Go over to the Script tab, and Sequence is there once again. Sequence will always be there, because it is default. Click New, and push S until you arrive at Set Numeric Variable. This is where you will set your food and water variables. We will do the food variable first. Enter the name of the variable you want to stand for Food, I named it Food obviously, and then click Edit in the box below and choose a value. I chose 13, just because thats my favorite number . Now, click OK until you get back to Sequence, and repeat the process for the Water variable. I named mine water, and set it to 13 also. We have just set our two variables, food and water, to a value of 13. Press OK until you arrive back at the Timed Events screen, and create another variable. You can make it any day you want, in my case it is 2. Go to the Script tab, and create another Numeric Variable. Use the arrow in the box to find the variable you created, and STOP EVERYTHING! BRAKES!!! This is where it gets slightly complicated. Once your variable is inputted into the computer, it must be assigned a value to be taken every day to be a true Food/Water script. To do this, click Edit in the box beside it, and push M twice to get to Minus. Click edit beside the first box, and push V for Variable. Whichever variable you are working with at the moment, push that one in the box. Below that, click Edit and push the up arrow on the screen beside number. After doing that, push OK until you get to the Timed Event screen where you change the name of the event (not the Timed Event screen where you create new ones) and click the Every button under Subsequent Occurences. If doing Food variable, then leave the 1 where it is. If doing Water variable, then change the 1 to 2. This triggers your event every 1 or 2 days, and takes the amount you chose from the variable. After finishing one variable, go back and repeat the process for the other variable, and you have completed a Food/Water script.

Last, but not least, is the Trigger Custom Event section. It is very simple, and should not require a lot of explanation. Therefore, I will just make a list of steps to follow when creating an Event trigger.

Ex3: Changing the Owner of a Hero using Triggerable Events
1. Get a hero from the Character menu to the right and lay him on the ground.
2. Click on the hero and go to the Events tab.
3. Scroll down to Triggerable Events and create a new event.
4. Name the event whatever you want to, and then proceed to the Script tab.
5. Click New and push C for Change Owner.
6. Click the arrow and make the hero change to Red Player.
7. Exit from Triggerable Events and proceed to Timed Events.
8. On day 2, make the event trigger the event you just created bu using the Trigger Custom Event script.
9. The event will be triggered on day 2, changing the neutral hero to Red Player's hero.
10. If you want to test it, place a red hero on the ground, and test it.
See? Wasn't that almost as easy as sequencing? Triggerable events can be potent if used correctly, but sometimes can backfire if not.
Summary of Triggerable Events:
To create one, go to the object you want it to be activated in, and make it in there. Then, make an event, where a Timed, Continuous, Placed, or even another Trigger, and tell it to Trigger Custom Event. The event triggers when stepped on, or activated, and does the action it is told to.

Well, there is almost all of my tutorial. I will put more up when I feel like it, but thanks for reading and leave me a comment or suggestion if you like it.
____________
guten tag

du bist schwul.

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
bobntamr1
bobntamr1


Known Hero
non dictionary ownen hero
posted November 30, 2002 05:25 PM

give the man a QP for gods sakes nice work...
____________
god please spare me from my contribulations

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
Kujo
Kujo


Known Hero
who loves to script.
posted December 01, 2002 12:38 AM
Edited By: Kujo on 30 Nov 2002

Only 1 reply post? I guess you guys don't appreciate someone trying to help the community by posting something that everybody has been whining about since the game came out. hmph
Thanks to bobntamr1 for being nice
____________
guten tag

du bist schwul.

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
DocFritch
DocFritch


Hired Hero
Never let your dreams die
posted December 01, 2002 03:13 AM

Thank You Kujo

Fantastic job you did Kujo.  As far as posting replies,  I don't think there is much to say except thank you so much for your efforts in posting a remarkable subject.

Because the information in it is so valuable  there will be a lot of "reads" I am sure.  BUT  because it doesn't slam, spam or jam anyone I doubt there will be much posting .

Please continue with your "tutorial"  I know it will make a better gaming enviornment for all of us.  Hoping you'll feel like continuing soon.

Thank you so much again for a magnificent  post

Doc
____________
Always tell the truth.....you'll never have to remember ANYTHING

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
aces170
aces170


Hired Hero
posted December 01, 2002 06:26 AM

ok, i am a newbie, is the above post for the homm4 editor, or is there a third party editor?
____________
there is no god, he is yet to be discovered

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
Largo_LeGrande
Largo_LeGrande


Promising
Known Hero
from the Carribean
posted December 01, 2002 08:17 AM

Few things I like to add:

1.Copying events: The editor doesn't allow you to copy events. But if you copy a creature (CTRL + drag), all the events will be copied. So if you had to do an event that would need lot's of repeative commands (let's say you have to make a complicated event that would set all the variables you have in the map), you should but that event on a neutral stack and copy the stack. Then you just need to change the variables and other parametres if you need to and but the creatures somewhere where they could not be seen. The only weakness of this system is that if you make timed events and they need to be run in a certain order.

2.Continuous events: I'm not 100% sure, but conditional continous events triggers immediadly when their requirments are filled. This is good if you need to run the event just when e.g. an amount of gold is gained. But that's not all. So these continuous events run all the time until they are done? You can use this to give you as much gold as much the variable 'Gold' is. By the normal way (if 1 give 1, if 2 give 2) this is impossible to do! But with continuous events it's pretty easy:

IF [Current Day] < 25 and [Current Day] > 25 and 'Gold' = 'Gold_given'

THEN Do nothing

ELSE Give 1 gold to Red Player
Set 'Gold_given' to ''Gold_given' + 1


____________
-Largo has spoken-

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
Kujo
Kujo


Known Hero
who loves to script.
posted December 01, 2002 12:16 PM

Yes I've been using Ctrl Drag a whole lot in building things such as bridges, walls, and monsters. It is also useful for setting events and dynamite. To the triggerable continuous, yes that would probably be very helpful to have. Without it, you would need a long script requiring much effort and maybe not even working. Thanks for your input Largo. I'll have more of my tutorial when I can think what else to do, but until then keep scripting everybody!
Oh and Aces, my tutorial is for the HOMM4 editor.
____________
guten tag

du bist schwul.

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
Kujo
Kujo


Known Hero
who loves to script.
posted December 01, 2002 02:46 PM

Tutorial Part 2

Ok so far I've gone over Advanced and Basic Scripting. Those are probably the hardest parts to learn of this tutorial. This next part covers ALL of the secondary commands which do only 1 (sometimes 2) functions.

Section 3: Secondary Scripting
I'm taking these from the Placed Events script, so if I miss any please tell me. They are in alphabetical order from C to W.

Script 1: Clear Loss Condition Description
Gee that's a long name. It must be terribly complicated and I'll never figure out. Actually, this script is laughably simple. Its function is to clear the loss conditon message you set when you made the map, and change it back to the default. Here is how to do it.
Ex1: Changing Loss Description
Since this is so easy I'll just do steps.
Step 1: Create a map and give it a custom loss condition such as "Get eaten by the Psychotic Gorilla".
Step 2: Create a script using the Clear Loss Condition Description.
Step 3: Test the map before and after using the script, and it will be cleared when it has been activated.
That was tough wasn't it? Since that is all this script is, let's continue.

Script 2: Ok since the next 3 scripts all follow the same format of the one above, I'm just going to tell you what they do. You can figure the steps out by looking above.
Clear Loss Message: Clears the Loss Message you set (if you set one) that appears when the player loses.
Clear Victory Condition Description: Exactly the same as Script 1 except that instead of LOSS it is VICTORY.
Clear Victory Message: Same as Clear Loss Message except it is Victory.
That is all of the clear message scripts there are. Here's the next one.

Script 3: Combat
The Combat script can really screw up your whole map if you use it a lot incorrectly. It is helpful in the way of fighting, but not really that useful. It still deserves a full example, though.

Ex2: Proper Usage of Combat
For this script, all you will need is a hero. The rest of the action will be events. In this example we will use a Timed Event to trigger the combat on our hero.
Step 1: Place your hero onto the map and go into their Timed Events script. I will not waste space telling you how to do this, as it is posted in my first tutorial.
Step 2: Create a new Timed Event, go over to script, and push C until you get to Combat. Choose any kind of battle you want, preferably something the hero can kill, and then go to the Branches tab. Here's where most people do the most obvious thing, and mess up their map. I, too, used to do this, until I figured it out. There are 2 branches that happen, Victorious and Defeated.

Victorious: This event is triggered When the monster beats the hero.
Defeated: This event is triggered When the hero beats the monster.

If you are not one of the people who switches these two around, you should be proud of yourself. It is a very common error and very easy to do. Anyways, on with the tutorial.
Step 3: In the VICTORIOUS box, put a phrase that you will remember to be the hero dying, such as "Agh! I, the hero, am dead!". In the DEFEATED box, put a phrase that you will remember to be the monster dying, such as "Urgh! Thou hast slain me! Once you have done this, click OK until you get out of the hero's events, and make sure that the hero has a color. Then you are ready to test the combat.

Script 4: Decrease/Increase Attack
This script is very self-explanatory. It increases the attack of the hero by however much you tell it to. Since it simple, I will do basic steps to use it. To do a decrease, simply go to decrease instead of increase.

With A Message Displayed
Ex3: Increasing Attack of a Hero
Step 1: Set a placed event on the ground and name it.
Step 2: Go into placed events menu and create a new one by the same name.
Step 3: Make that event display the message "Increased attack by ___" ___ being however much you want to increase the attack.
Step 4: Click the New button under Subactions and push I to choose Increase Attack. Assign a number and then click OK until you are out. When your hero steps on the event,  the message will be displayed and(s)he will get a bonus to his/her attack.

Without A Message Displayed
Ex4: Increasing Attack of a Hero
Step 1: Set an event on the ground and name it.
Step 2: Create a new event in Placed Events menu.
Step 3: Make that event increase attack by a number.
Step 4: Click OK until you get out and then test the event. No visible evidence will appear telling you that your attack was increased until you go into your hero screen and see the bonus.

For the rest of the decrease stats/increase stats, I think you can figure them out using the above steps. They are so easy a monkey could do them without effort .

Script 5: Giving/Taking
These scripts can also be done with messages and no messages, but you can figure that out with the above scripts. I will do the Give Creatures script as an example for the other ones, which you can figure out using the model.

Ex5: Giving Creatures
Step 1: Place/Create a Placed Event and name them identically.
Step 2: Select the script Give Creatures from the dropdown arrow, choose the creatures and the amount, and then press OK. That is all the effort needed to do this script. Lol easy huh?

Script 6: Lose
This is another one of those self-explanatory scripts. What do you think it does? Well, if you haven't guessed yet (lol) it makes the player selected lose the game.

Ex6: Making a player lose
Step 1: Place/Create a Placed Event and name them identically.
Step 2: Select the script Lose from the dropdown arrow, and choose the player you want it to work on. That's all there is to this script. 2 Steps.
Of course Lose can be used more significantly in other places, and of course more complexly, but for our purposes here this is all you need to know.

Script 7: Removing Object
I have never used this script and probably never will, so I am not sure what it does. I think it acts about the same way as Delete Adventure Object, but it gets rid of the event. If you are like me, you will never use it, so I don't need to do a tutorial on it. Therefore, my tutorial is 100% finished.

If you found my tutorial to be informative, and sometimes even humorous, leave me a message below. If you have a question about something appearing in my tutorial, you can email me at kujo82@lycos.com. Otherwise, I am cutting the chain from you and letting you run free in the world of scripting. Feel free to prance, frolic, twirl, and play rugby in the world of scripting. Peace out!

____________
guten tag

du bist schwul.

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
Nidhgrin
Nidhgrin


Honorable
Famous Hero
baking cookies from stardust
posted December 02, 2002 12:32 AM

I'm sorry for arriving here so late Kujo.  I have hardly had any time to get online during the last three days.  This thread definitely deserves a quality point, but I see another moderator already gave you one. Forgive me for going off topic here, but your guide will certainly come in handy to a newbie mapmaker like myself.  Great post!  Keep up the good work.

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
Largo_LeGrande
Largo_LeGrande


Promising
Known Hero
from the Carribean
posted December 03, 2002 02:13 PM
Edited By: Largo_LeGrande on 3 Dec 2002

3.Triggerable events: Remember, that a triggerable event can trigger itself too. Just add the trigger custom event thing into the end of the script. You can do that continuous event example by this style too. This system could be good in events that ask a question from the player:

PLACED EVENT "Crossroads"

Display 'You've come to a place where the road splits into three directions. The road to north is full of bushes and bricks, the road to east leads to Erathia and there is man standing on the  road to west.'

Trigger custom event named "Question"

TRIGGERABLE EVENT "Question"

Ask: Choose the road

1. Bushy road to north
2. East road to Erathia
3. Road to west with a man standing on it

Yes: Bushy road to north
No: Next

If yes Trigger custom event named "North"
Remove Script
If no Do nothing

Ask: Choose the road

1. Bushy road to north
2. East road to Erathia
3. Road to west with a man standing on it

Yes: East road to Erathia
No: Next

If yes Trigger custom event named "East"
Remove Script
If no Do nothing

Ask: Choose the road

1. Bushy road to north
2. East road to Erathia
3. Road to west with a man standing on it

Yes: Road to west with a man standing on it
No: Next

If yes Trigger custom event named "West"
Remove Script
If no Do nothing

Trigger custom event named "Question

---

Well this example may not be pleasant for the map maker but very pleasant to the player as (s)he can decide where to go in peace.
____________
-Largo has spoken-

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
aces170
aces170


Hired Hero
posted December 05, 2002 05:19 PM

excellent thread, dude, kudos to u for posting it,
i had a question btw, i was trying to decorate my map with trees and all the problem is that shift function doesnt work well so when i want a large area with trees i have to manually to drag the trees now, thats irritating anyway out?
____________
there is no god, he is yet to be discovered

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
DonGio
DonGio


Promising
Famous Hero
of Clear Water Mountain Clan
posted December 06, 2002 12:29 AM
Edited By: DonGio on 5 Dec 2002

Yeah, Kujo should get more than one qp for this, he should get paid by the no-good slobs at 3DO.

Great work. And the same to Largo.

Dixi
DonGio

EDIT: Oh yeah, and this post needs to be pinned, or whatever they call it, so it's always accessible from the index menu. Or that's what I think, anyway. Good night.
____________
There are 10 types of people: Those who read binary, and those who don't.

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
Kujo
Kujo


Known Hero
who loves to script.
posted December 06, 2002 02:01 AM
Edited By: Kujo on 5 Dec 2002

Thx Don .
Its too bad 3DO didn't make a manual, but we really don't need one. I mean, after using the editor for several test maps, I was quite familiar with it. I used the map Escape From Biggun's Playground to actually learn how to use scripts, then followed it up with that guy's (forgot his name!) online tutorial. It helped a little bit, but I mostly learned through trial and error. I will make steps for learning through t&a if anyone wants them.
Edit: Woops didn't see your post aces. To copy items, hold ctrl and then drag the item. A plus sign will appear, and then you just click where you want the copy made. Use this also to make items in the menu, so you can use them in different areas.
____________
guten tag

du bist schwul.

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
YUC
YUC

Tavern Dweller
posted November 04, 2004 10:16 AM

What's the meaning of the 2 x 1 and 1 x 2 events?
____________

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
< Prev Thread . . . Next Thread >
Post New Poll    Post New Topic    Post New Reply

Page compiled in 0.3459 seconds