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


Age of Heroes Headlines:  
5 Oct 2016: Heroes VII development comes to an end.. - read more
6 Aug 2016: Troubled Heroes VII Expansion Release - read more
26 Apr 2016: Heroes VII XPack - Trial by Fire - Coming out in June! - read more
17 Apr 2016: Global Alternative Creatures MOD for H7 after 1.8 Patch! - read more
7 Mar 2016: Romero launches a Piano Sonata Album Kickstarter! - read more
19 Feb 2016: Heroes 5.5 RC6, Heroes VII patch 1.7 are out! - read more
13 Jan 2016: Horn of the Abyss 1.4 Available for Download! - read more
17 Dec 2015: Heroes 5.5 update, 1.6 out for H7 - read more
23 Nov 2015: H7 1.4 & 1.5 patches Released - read more
31 Oct 2015: First H7 patches are out, End of DoC development - read more
5 Oct 2016: Heroes VII development comes to an end.. - read more
[X] Remove Ads
LOGIN:     Username:     Password:         [ Register ]
HOMM1: info forum | HOMM2: info forum | HOMM3: info mods forum | HOMM4: info CTG forum | HOMM5: info mods forum | MMH6: wiki forum | MMH7: wiki forum
Heroes Community > Heroes 4 - Lands of Axeoth > Thread: Expert Guide to Scripting
Thread: Expert Guide to Scripting
Kujo
Kujo


Known Hero
who loves to script.
posted December 06, 2002 03:36 PM

Expert Guide to Scripting

This is the last part of my tutorial. It deals with everything featured in Sections 1&2. However, the main focus is on Numeric Variables and their purpose. I intend to dive deep down into their ocean, and analyze their purpose to my full ability. So, without further ado, let's begin.

Part 1: What they Are
As mentioned before in my earlier post, A Beginner's Guide to Scripting, Numeric Variables are those that use numbers to set values instead of True and False. They can be set to choose a random number, do all the primary mathematical functions, and many other things.

Part 2: How to Find them
If you haven't read my other tutorial, A Beginner's Guide to Scripting, I suggest you push the back button and go to it. I explain wholeheartedly how to get to the Numeric Variable, and also how to use it. But, if you are the lazy kind, here is how you arrive at it.

In Arrow form:

For a Timed Event:
Campaign->Map Properties->Events->Timed Events->New->Script->New->Arrow until you get to it

For a Triggerable Event:
Campaign->Map Properties->Events->New->Script->New->Arrow until you get to it

For a Continuous Event:
Campaign->Map Properties->Events->Continuous Events->New->Script->New->Arrow until you get it

Placed Events
Campaign->Map Properties->Events->Placed Events->New->Script->New->Arrow until you get to it

That is the quick way to find Numeric Variables. Now, onto the fun stuff .

Part 3: Usage of the Numeric Variable
This is where I start going into detail on how to use it. You may have to reread this guide several times to fully understand what I am saying, or maybe not. Here we go.

P3: Example 1
In this example, I will show you how to do a simple randomization script, allowing several different paths that your game can take. To keep it simple, I will make only 6 possible outcomes, and the recipient outcome will be hero selection. As a summary, I will label one variable Indirect, and another Direct. The direct variable is a result of the indirect.

Indirect: Random number 1-6
Direct: Hero chosen

Now, here is how to do the script.

Step 1: Go into the Placed Events menu, and create a new script. Place the event on the map, and name it anything you want. (mine is called BeginScript) Name the event in the menu equally to what you named the event, and get ready to script.

Step 2: To begin with, ask a question that says, "Are you ready to begin the game?" If yes, make it say "Choosing your hero from several choices." Set the Numeric Variable to the name hero16, and set it to Random Number 1-6. You can do this by clicking edit beside the box, and arrowing down to Random Number. Next, display a message that says "Hero chosen Proceed to the teleporter." Use a Boolean Variable, and set it to the name HC1, with the value as True. Lastly, Remove Script. If the answer is No, then say a message like "Hurry up!".

Ok, you have done all this scripting, and now you're done. But what did that actually accomplish? It accomplished many different things.

1. The Question: It asked the person if they were ready to begin the game. No one in their right minds would click no, but it gives them a feeling that they have an option. This script could have been done as a regular Placed Event without the question, but would have been without the freedom.

2. The Numeric Variable: When you set the variable to random number 1-6, it chose one automatically and set your variable to the random value. Since the next step in our script involves this random number, it is very important.

3. The Displayed Messages: Worthless. There is no point in them except to add a little spice to your script. The only worthwhile message was the question. If you want, you can just delete the messages right now.

4. The Boolean Variable: Very important. Without it, the next step of the script would activate on the first second of the first day.

5. Remove Script: Kills the script so you cannot step on it multiple times. Very important when used correctly.

Those are the reasons that those scripts were used. I will do that for all scripts in the future, to help you, the reader, understand WHY you are doing this.

Step 3: Choosing the Hero
This script involves Conditional Actions. 7 of them, to be exact. It is a very long script, and can barely fit in the Sequence. To begin it, go into the Continuous Events menu and create a new event. Change the default Sequence event to Conditional Action, and click the edit box under If. Remember how we set HC1 to True? This is where that has its moment of glory. Under If, go to the Variable, (V hotkey) and choose our variable HC1. Under the Then box, create SIX Conditional Actions. Make them all If hero16 Then. For the first CA (conditional action), make it If hero16=1. For the second CA, make it If hero16=2. Repeat this for the other 4, changing their values to 3,4,5 and 6. After that, set them all to Delete Adventure Object named under 1,2,3,4,5,6 respectively. Lastly, Remove the Script.
Side Note: Under the Else box, keep it as Do Nothing.

1. The first CA: It says that HC1 must be TRUE in order for the script to activate. Since Step 2 set HC1 to TRUE, Step 3 is automatically activated.

2. The Six CAs: Only one can be activated per game. Which one of them depends on what our variable hero16 chooses randomly. After being activated, they will delete the adventure object which guards the hero from being taken.

3. Remove Script: The same function as above. Keeps the event from being repeated over again.

Step 4: Activating the hero.
This step explains how to activate the hero and make him yours after he has been chosen. (All heroes should be neutral) Place 6 heroes onto the map, and enclose them in walls. Lay dynamite on the walls and name it 1,2,3,4,5 and 6 respectively. Inside of the walls, lay an event which will trigger the events 1,2,3,4,5 and 6. In the hero's menu, go to triggerable events and create 6 events, 1,2,3,4,5 and 6 respectively. Script each of these events to CHANGE OWNER to red player. When something steps on the Placed Event, the event will be triggered. The last part of this step is to lay a peasant near the FIRST Placed Event you created. Have him step on it to activate the event.

1. Placing the heroes: Duh! You have to have heroes to be able to activate the events.

2. Dynamite: Only one is triggered throughout the game. Allows peasant to pass through the walls and activate the hero.

3. Placed Events: Trigger the hero to change his ownership from neutral to red player.

4. Peasant: Lets you activate the first event that triggers all other events.

There you have it folks, the Choose Hero script. It reviews pretty much everything I went over in my previous tutorials, and some stuff I didn't. Depending on the popularity of this thread, I will do another example script to familiarize you even more with scripting. Until then, though, keep scripting!!
____________
guten tag

du bist schwul.

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


Promising
Known Hero
from the Carribean
posted December 06, 2002 05:09 PM

Why did you post a new topic? Are you trying to fish a new QP with the same subject j/k,

P.S Happy birthday to Finland!
____________
-Largo has spoken-

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


Known Hero
who loves to script.
posted December 06, 2002 05:26 PM

Largo I'm not in this for the QP. I'm just trying to help the community by posting a quality thread on the topic of scripting. A QP would be nice for my effort, but I really don't care . As for why I made a new one, I thought that Beginner's was getting long, and no one would read all of my new tutorial, so I made a new thread.
____________
guten tag

du bist schwul.

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


Hired Hero
posted December 06, 2002 06:08 PM

well, this is really nice man i have stored this and previous threads very useful, for doing some timepass with the editors
____________
there is no god, he is yet to be discovered

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
Jump To: « Prev Thread . . . Next Thread »
Post New Poll    Post New Topic    Post New Reply

Page compiled in 0.0454 seconds