Scripting Tutorial By Kronos1000

Hello and welcome to my scripting tutorial I’ll explain how this works. :?: means a question of course it are all over the guide and then I’ll explain how. :!: means IMPORTANT these are things you’ll have to keep in mind while you’re writing your script.

This font is used as a place for a scripting example

Well then, there are three parts in this guide Basic, Advanced and Expert. Each of them explains a part of the scripting language the contain the following:

Basic: Messages, end; questions, variables and easy functions, triggers and syntaxes. Advanced: Harder triggers like OBJECT_CAPTURE_TRIGGER, startThread() and “for loops” plus more syntaxes and harder functions. Expert: “while loops”, Combat scripts, even more syntaxes 8-o and harder functions once again.

If you already understand everything of one part, feel free to skip it. ;-)


Phew, the advanced part allready we’re going to work with harder and better scripts now (But not as hard as Enter the Abyss though) but we don’t have time to chat let’s start! :D

:?: How to trigger a script if you touch a building :?:

With a new Trigger: OBJECT_TOUCH_TRIGGER. But first every Trigger has it’s own variables between its (). To see wich one you’ll have to check the script functions.pdf in the editor documentation. So after reading the Trigger part you’ll know wich one are used for OBJECT_TOUCH_TRIGGER. So we’re using heroname and objectname. But first every builing has it’s own script we’ll have to remove it it’ll require three steps:

1. Select the building you want to affect and give it a name at the name tag. 2. Now we’re going to remove the standart script of the building by using the SetObjectEnabled() function place this line on the top of your script outside of a function:

SetObjectEnable(“BuildingName”, false)

3. Now first we’re going to create a new Message, that says Nobody is here. Then create this function:

function OldBuilding(heroname, objectname) if objectname == “BuldingName” and IsObjectEnabled(objectname) == false then MessageBox(…) end; end; Trigger(OBJECT_TOUCH_TRIGGER, “BuildingName”, “OldBuilding”)

IsObjectEnabled() returns true if the building has its standart script if it has not it’s false. Anything else should be clear :-)

:!: Once again experiment with this before moving on :!:

Now if you want to re-add the standart script you’ll have to use the SetObjectEnabled() function again but this time like this:

SetObjectEnabled(“BuildingName”, true) Now I hope you can write a function with REGION_ENTER_AND_STOP_TRIGGER all by yourself now ‘cause you are going to write one :twisted: Use if GetCurrentPlayer() == PLAYER_1 as an if. If you forgot how to do this read back to Basic. Make this function re-add the standart script of your building.

Note: From now on I’m no longer going to give you a function that you can copy unless there’s a new trigger.

:?: Can I do more with MessageBoxes :?:

Yes you can, you can add colours and variables in it, we call that a complex message. A complex message shows the value of a variable (nil = no value)! :-D

:!: What the script functon.pdf says about this is wrong use mine :!:

The syntax of a complex message is a bit differant from MessageBox, for example:

MessageBox({“Maps/SingleMissions/Enter the Abyss/Gold.txt”; Gold = GetPlayerResource(PLAYER_1, GOLD)}) Now here is the part that’s wrong in the pdf file the manaul says that the Message has to contain <Gold> and that’ll be replaced by the value. but that won’t work it has to be <value=Gold> so if the function is correct you’ll have to put something ike this in the message:

“You have <value=Gold> pieces of gold!"

That’s not that hard isn’t is?

Adding colours is even less hard you’ll have to put <color_…> in the message and everything behind it looks that color multiple are allowed. Here is a shot of the possible colours:

The same works with QuestionBoxes it’s the same as a MessageBox but it has an Ok and Cancel button, syntax:

QuestionBox(“Message”, “CallbackOK”, “CallbackCancel”) The callbacks are names of invoked functions if you press the OK or the Cancel button.

Note: MessageBox can have ONE callback as well.

:?: How to transform a town after you capture it :?:

First we have to use a new trigger called OBJECT_CAPTURE_TRIGGER. If you’ve read the script functions.pdf you’ve seen that it has a hell lot of parameters :shock: : oldowner, newowner, heroname, objectname. First we’re going to give the town a scripting name (Like we did with OBJECT_TOUCH_TRIGGER) Now we have to use a new function: TransformTown(). Syntax:

TransformTown(“TownName”, x)

x = the id of the town. There are some issues with it so I’m going to give you them:

0 = Invalid 1 = Invalid 2 = Invalid 3 = Haven 4 = Sylvan 5 = Academy 6 = Dungeon 7 = Necropolis 8 = Inferno 9 = Fortress

Now because it’s a new trigger I’m going to give you the function:

function Raze(oldowner, newowner, heroname, objectname) if newowner == PLAYER_1 and objectname == “TownName” then TransformTown(objectname, 7) end; end; Trigger(OBJECT_CAPTURE_TRIGGER, “TownName”, “Raze”) Well I think it’s clear what it does :) Go try multiple things with OBJECT_CAPTURE_TRIGGER, be it a transform or a MessageBox or something else, just try!

Now we make the transform cost recources and only if you want it to, I think it’s to hard to make it done, so create a message one that asks you if you want to trasform, so once again here is the script:

function Capture(oldowner, newowner, heroname, objectname) Gems = GetPlayerResource(PLAYER_1, GEMS) Pay = Gems - 20 if newowner == PLAYER_1 and Gems >= 20 then QuestionBox(…, “Transform”) end; end; Trigger(OBJECT_CAPTURE_TRIGGER, “TownName”, “Capture”) function Transform() SetPlayerResource(PLAYER_1, GEMS, Pay) TransformTown(“TownName”, 7) end;

Now ther is a great chance this isn’t clear so I’ll explain it: There isn´t a function like TakePlayerResource so two Variables are needed so with the SetPlayerResource function did I fill in the numeric Variable Pay for the number that would do the same. If you anymore questions about this email me or post it here it is hard I know. :wink:

:?: Are there more ways to call a function :?:

Yes, there is one more way by using the startThread() function. You probably think what’s the use of that? I’ll show you it can be handy after I’ve shown the syntax:


Note: You don’t use ""

Here is an example of my Puzzle script don’t worry I’ve thought you to do this allready ;):

function puzzle(heroname, objectname) object = objectname if Stoneblock1 == 1 and object == “Stone1” then ShowFlyingSign(“Maps/SingleMissions/Enter the Abyss/Visited.txt”, object, Play[1], 3.0) elseif Stoneblock2 == 1 and object == “Stone2” then ShowFlyingSign(“Maps/SingleMissions/Enter the Abyss/Visited.txt”, object, Play[1], 3.0) elseif Stoneblock3 == 1 and object == “Stone3” then ShowFlyingSign(“Maps/SingleMissions/Enter the Abyss/Visited.txt”, object, Play[1], 3.0) else startThread(puzzle1) end; end; Trigger(OBJECT_TOUCH_TRIGGER, “Stone1”, “puzzle”); Trigger(OBJECT_TOUCH_TRIGGER, “Stone2”, “puzzle”); Trigger(OBJECT_TOUCH_TRIGGER, “Stone3”, “puzzle”); function puzzle1() if ending == 1 and Puzzle == 0 and GetCurrentPlayer() == Play[1] and IsObjectExists(“Heam”) == true then Puzzle = 1 ShowFlyingSign(“Maps/SingleMissions/Enter the Abyss/Puzzle1.txt”, object, Play[1], 3.0) elseif ending == 1 and Puzzle == 1 and GetCurrentPlayer() == Play[1] and IsObjectExists(“Heam”) == true then Puzzle = 2 ShowFlyingSign(“Maps/SingleMissions/Enter the Abyss/Puzzle2.txt”, object, Play[1], 3.0) elseif ending == 1 and Puzzle == 2 and GetCurrentPlayer() == Play[1] and IsObjectExists(“Heam”) == true then Puzzle = 3 ShowFlyingSign(“Maps/SingleMissions/Enter the Abyss/Puzzle3.txt”, object, Play[1], 5.0) else ShowFlyingSign(“Maps/SingleMissions/Enter the Abyss/Puzzle4.txt”, object, Play[1], 3.0) end; if object == “Stone1” and Puzzle > 0 then Stoneblock1 = 1 elseif object == “Stone2” and Puzzle > 0 then Stoneblock2 = 1 elseif object == “Stone3” and Puzzle > 0 then Stoneblock3 = 1 end; end; function puzzle2(heroname, objectname) if ending == 1 and Puzzle == 3 and GetCurrentPlayer() == Play[1] and IsObjectExists(“Heam”) == true then MarkObjectAsVisited(“Stone1”, heroname); MarkObjectAsVisited(“Stone2”, heroname); MarkObjectAsVisited(“Stone3”, heroname); SetObjectPosition(“Linaas”, 10, 206, 0) SetObjectPosition(“Heam”, 8, 206, 0) SetObjectPosition(“KingTolghar”, 12, 206, 0) elseif GetCurrentPlayer() == Play[4] then MoveHero(heroname, 133, 145, 0) else ShowFlyingSign(“Maps/SingleMissions/Enter the Abyss/Locked.txt”, objectname, Play[1], 3.0) end; end; Trigger(OBJECT_TOUCH_TRIGGER, “Portal”, “puzzle2”); function PuzzleReset() if Puzzle > 0 then MessageBox(“Maps/SingleMissions/Enter the Abyss/Reset.txt”) Puzzle = 0 Stoneblock1 = 0 Stoneblock2 = 0 Stoneblock3 = 0 end; end; Trigger(NEW_DAY_TRIGGER, “PuzzleReset”)

This took me ages to make and to get it Bug-Free but it works. You might not want to read it, but just try to read it you can understand it all ;-)

Btw. startThread can be handy if you want to trigger a script once on a specific moment ‘cause startThread is placed inside a function.

:?: Can I trigger a function multiple times :?:

Ah my favourite :-D : “for loops” Now do you think: WTF, what’s a “for loop” It triggers a function multiple times with a numeric variable that gets his worth + 1 every time. Syntax:

for i=x,y do

x = The start value of the variable it must be a number and y = the last value before the loop stops. In this case i is the variable that’s the most common one but any variable can be used.

:!: If you use a “for loop” it requires an extra end; :!:

And of course even an if can follow a loop but a loop is placed inside a function. Try to make a function with a for loop and see if it works :-) If you want an endless loop you’ll have to use a “while loop” more about that in the expert part.

:?: Are there more variables :?:

Well kind of ther is an array variable but it’s a combination of multiple variables. You make it like this Array = {} Array[1] = 1 Array[2] = 2 etc.

It usually goes in combination with a “for loop” for example if you want to block a region for all players you do the following:

Play = {} Play[1] = PLAYER_1 Play[2] = PLAYER_2 Play[3] = PLAYER_3 Play[4] = PLAYER_4 Play[5] = PLAYER_5 Play[6] = PLAYER_6 Play[7] = PLAYER_7 Play[8] = PLAYER_8 for i=1,8 do SetRegionBlocked(“RegionName”, 1, Play[i]) end; That’s the use of it 8-)It can also be used as a String now I’ll explain string variable: I prefer using it in an array so if you want multiple MessageBoxes you can use an array like this:

Message = {} Message[1] = “Maps/SingleMissions/…/Message1” Message[2] = “Maps/SingleMissions/…/Message2” Message[3] = “Maps/SingleMissions/…/Message3” for i=1,3 do MessageBox(Message[i]) end;

That’s pretty handy isn’t it? :-D

What you have learned:

Functions: GetDate() GetCurrentPlayer() Win() Trigger() SetObjectEnabled() GetPlayerRecource() SetPlayerResource() TransformTown() QuestionBox() MessageBox() Complex startThread() SetRegionBlocked()

Syntax: == Means Is equal to. > Greater then. < Means smaller then. >= means greater then or Equal to. ⇐ means Smaller then or Equal to. ~= means Unequal to. + means plus - means minus * means times / means divided by

How to create a “for loop”

Other: The first three Variables How to make a function How to change the colour of texts. How to write a complex message. How to make an array and the use of it.

Well great job if you really did everything as I told you to you can make a map with vey good scripts. ^_^ But if you want to be a master you’ll have to do the expert part as well…

scripting_tutorial/advanced.txt · Last modified: 2007/07/20 20:12 by kronos
Creative Commons License Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0