Basic scripting resources

Maps and the art of mapmaking.
User avatar
Vitirr
Scout
Scout
Posts: 157
Joined: 06 Jan 2006
Contact:

Basic scripting resources

Unread postby Vitirr » 06 Nov 2006, 12:17

Is there any tutorial or guide to learn the basics of scripting? I'm starting to learn about it but I can't find good info. Right now I don't know if I must make my map scripts in lua files, or just use the editor field called "script text" (or something like that), I don't know what are the fields of the map properties tree about new day trigger or war fog, and I have no idea of which triggers are available and how can I use them in my functions.

So any help would be welcome.

User avatar
Sir_Toejam
Nightmare
Nightmare
Posts: 1061
Joined: 24 Jul 2006

Unread postby Sir_Toejam » 06 Nov 2006, 12:21

there is a forum on lua scripting over on elrath.com

User avatar
Grumpy Old Wizard
Round Table Knight
Round Table Knight
Posts: 2205
Joined: 06 Jan 2006
Location: Tower Grump

Re: Basic scripting resources

Unread postby Grumpy Old Wizard » 06 Nov 2006, 12:26

Vitirr wrote:Is there any tutorial or guide to learn the basics of scripting? I'm starting to learn about it but I can't find good info. Right now I don't know if I must make my map scripts in lua files, or just use the editor field called "script text" (or something like that), I don't know what are the fields of the map properties tree about new day trigger or war fog, and I have no idea of which triggers are available and how can I use them in my functions.

So any help would be welcome.
Click on start ->All Programs->Ubisoft->HOMM5. Then you will see Map Editor Manual, which is 4 parts. Go through the practical and theoretical guides.

Also, look at the scripting of some of the user made maps that have been published. My map, "Seize The Throne" has over 1000 lines of scripting. The scripting is heavily commented so you can look at examples of what I did for various things and it might help you figure out how to do what you want to do.
https://www.celestialheavens.com/search ... ion=search

GOW
Frodo: "I wish the ring had never come to me. I wish none of this had happened."
Gandalf: "So do all who live to see such times but that is not for them to decide. All we have to decide is what to do with the time that is given to us."

User avatar
Vitirr
Scout
Scout
Posts: 157
Joined: 06 Jan 2006
Contact:

Re: Basic scripting resources

Unread postby Vitirr » 06 Nov 2006, 21:00

Grumpy Old Wizard wrote: Click on start ->All Programs->Ubisoft->HOMM5. Then you will see Map Editor Manual, which is 4 parts. Go through the practical and theoretical guides.
Yes, as if those have much info about scripts :p

Ok since it looks like there are no guides or tutorials and the only way to learn is the hard way, I'll start with specific questions.

This is my code:
Trigger( NEW_DAY_TRIGGER, 'day1' );
Trigger( WAR_FOG_ENTER_TRIGGER, 'day2' );

function day1()
if GetDate(DAY) == 1 then
MoveCamera(69, 44, 0, 20, 0.05, -0.2, 0, 0);
sleep(20);
MessageBox ('Maps/SingleMissions/Nuevo_mapa_luces/mensaje1.txt');
elseif GetDate(DAY) == 3 then
SetAmbientLight(0, 'Lights/_(AmbientLight)/Prueba.(AmbientLight).xdb', false, 1);
end;
end;

function day2(hero_name)
if GetDate(DAY) == 2 then
MessageBox('Maps/SingleMissions/Nuevo_mapa_luces/mensaje2.txt');
print(hero_name);
end;
end;
Some questions. If I don't specify "day1" as a function in the NewDayTrigger field of the map properties tree, the day 1 the function is not triggered, (the rest of days it works however). In fact, if I set that parameter in the map properties tree, there's no need to specify in the script Trigger( NEW_DAY_TRIGGER, 'day1' ); Is that normal?

SetAmbientLight doesn't work. It never finds the ambient file. I've tried with the name and route of the file (as it is now) and with a name that I set in the name field of the ambientlight object. No success. Any idea?


Anybody knows when exactly triggers the event WAR_FOG_ENTER_TRIGGER? I thought it was when the hero removes the fog of war but I was wrong, and it never triggers.

By the way, I've found undocumented functions like QuestionBox or MessageBoxInt. Any idea of what those do? Is there's a list of these functions documented anywhere?

User avatar
Sir_Toejam
Nightmare
Nightmare
Posts: 1061
Joined: 24 Jul 2006

Unread postby Sir_Toejam » 06 Nov 2006, 21:29

like i said:

http://elrath.com/forums/index.php?s=29 ... owforum=16

several folks playing with scripting there, in case you don't get the answers you need here.

User avatar
Pitsu
Round Table Hero
Round Table Hero
Posts: 1830
Joined: 22 Nov 2005

Re: Basic scripting resources

Unread postby Pitsu » 07 Nov 2006, 19:01

Vitirr wrote: Some questions. If I don't specify "day1" as a function in the NewDayTrigger field of the map properties tree, the day 1 the function is not triggered, (the rest of days it works however). In fact, if I set that parameter in the map properties tree, there's no need to specify in the script Trigger( NEW_DAY_TRIGGER, 'day1' ); Is that normal?
Not sure whether normal or not, but it is a common case not anything specific to your editor. EDIT: day 1 events you can write to the script without any "if getdate(DAY)==1 then" or having them as a separate function.
SetAmbientLight doesn't work. It never finds the ambient file. I've tried with the name and route of the file (as it is now) and with a name that I set in the name field of the ambientlight object. No success. Any idea?
You can do like in C5M5. The light texture file has name/internal name reference fields in its body. Give them one and use the reference name in SetAmbientLight command. Additionally, it may be necessary to have appropriate pointes in the map.xdb file. I am afraid you may need to use a text editor, as the map editor didn't seem to do it correctly for me.
BTW, C5M5 uses texture from: Lights/_(AmbientLight)/AdvMap/C5M5/c4m4_wastes (2).xdb
Could successfully use the same texture in a test map of mine.
Anybody knows when exactly triggers the event WAR_FOG_ENTER_TRIGGER? I thought it was when the hero removes the fog of war but I was wrong, and it never triggers.
Sorry, no answer at the moment. Tried some combinations, but as it seem to ignore this trigger and not report any problems... hard to solve.
By the way, I've found undocumented functions like QuestionBox or MessageBoxInt. Any idea of what those do? Is there's a list of these functions documented anywhere?
Not tested lately, but questionbox gave a question box.
QuestionBox('/Maps/Scenario/C6M5/message-8.txt', "Info"); -- runs function info() only when player clicks yes.

There are some more undocumented commands that work fine AFAIK. GetPlayerState(PLAYER_#) or GiveBorderguardKey (PLAYER_#, key#) for example... But not seen a list anywhere
Avatar image credit: N Lüdimois

User avatar
Vitirr
Scout
Scout
Posts: 157
Joined: 06 Jan 2006
Contact:

Re: Basic scripting resources

Unread postby Vitirr » 08 Nov 2006, 00:58

Pitsu wrote:You can do like in C5M5. The light texture file has name/internal name reference fields in its body. Give them one and use the reference name in SetAmbientLight command.
Stupid me, I only had to add a new ambientlight in the map properties tree. I only used one, so the other ambientlight to swap, though the file was there in the file structure of the map, was ignored by the game.

Now I've been succesfull changing adventure map and combat ambientl ights, (thanks to examples in C5M5 scripts). The CombatMapLight function doesn't take the name of the ambient light but the name and route of the file (with the aditional #xpointer(/AmbientLight) at the end). Now my only complain is that I can't change the towns ambients, but I guess I can live with that :-p
Pitsu wrote:Additionally, it may be necessary to have appropriate pointes in the map.xdb file. I am afraid you may need to use a text editor, as the map editor didn't seem to do it correctly for me.
What do you mean?, to add the ambient light in the map.xdb file? If so it works for me from the editor.
Pitsu wrote:
Anybody knows when exactly triggers the event WAR_FOG_ENTER_TRIGGER? I thought it was when the hero removes the fog of war but I was wrong, and it never triggers.
Sorry, no answer at the moment. Tried some combinations, but as it seem to ignore this trigger and not report any problems... hard to solve.
Ok, solved ;) With this function SetWarfogBehaviour(0, 0); you set the fog or war unremovable (the hero can only move through the terrain already revealed). Now place a teleporter next to the hero, and another far away (in the darkness). When the hero goes through the teleporter the event triggers. What's the use of it? I have no idea, but at least it works :D

Pitsu wrote:Not tested lately, but questionbox gave a question box.
QuestionBox('/Maps/Scenario/C6M5/message-8.txt', "Info"); -- runs function info() only when player clicks yes.
Yes, I finally managed to find it out by myself after a lot of tests. By the way you can add a function (or more) to be executed first. Just like this:

QuestionBox('/Maps/Scenario/C6M5/message-8.txt', "Info", function1(), function2());

It might prove useful if you want to give a long explanation before asking the question, so function1 and function2 could be 2 messagebox functions.
Pitsu wrote:There are some more undocumented commands that work fine AFAIK. GetPlayerState(PLAYER_#) or GiveBorderguardKey (PLAYER_#, key#) for example... But not seen a list anywhere
It could be interesting to make a thread for that where people could add his new discovered functions.

Thanks Pitsu.

User avatar
Vitirr
Scout
Scout
Posts: 157
Joined: 06 Jan 2006
Contact:

Unread postby Vitirr » 08 Nov 2006, 20:41

I know you can add point lights to objects through scripts, but anybody knows if they can be also removed?

User avatar
Pitsu
Round Table Hero
Round Table Hero
Posts: 1830
Joined: 22 Nov 2005

Unread postby Pitsu » 09 Nov 2006, 08:29

Vitirr wrote:I know you can add point lights to objects through scripts, but anybody knows if they can be also removed?
Not tested myself, but does SetObjectFlashlight(objectName, nil); not work?
Avatar image credit: N Lüdimois

User avatar
Vitirr
Scout
Scout
Posts: 157
Joined: 06 Jan 2006
Contact:

Unread postby Vitirr » 09 Nov 2006, 10:42

I'll try, but the function definition doesn''t seem to suggest that, because it says it "adds" point lights, not set them. But the definition could be wrong of course.

User avatar
Pitsu
Round Table Hero
Round Table Hero
Posts: 1830
Joined: 22 Nov 2005

Unread postby Pitsu » 09 Nov 2006, 18:34

OK, the nil value did not work (for me). But another solution did. It indeed adds to colours. Say you have originally the three channels as 0,1,1 (cyan). By SetObjectFlashlight with 1,0,0 (red) the summary outcome is 1,1,1 (white). Thus, to remove a colour, one has to use negative values. SetObjectFlashlight to the very same object a light defined with -1,-1,-1 channels removed the light around it.
Hope it helps anyone who had not figured it out yet...
Avatar image credit: N Lüdimois

User avatar
Vitirr
Scout
Scout
Posts: 157
Joined: 06 Jan 2006
Contact:

Unread postby Vitirr » 09 Nov 2006, 21:53

LOL, great Pitsu! Good workaround. I wonder what will happen though after 3 months of gameplay if you keep adding lights and "antilights" each day/week. I wonder if it will have any effect on performance.

User avatar
Pitsu
Round Table Hero
Round Table Hero
Posts: 1830
Joined: 22 Nov 2005

Unread postby Pitsu » 09 Nov 2006, 22:01

Vitirr wrote: I wonder what will happen though after 3 months of gameplay if you keep adding lights and "antilights" each day/week. I wonder if it will have any effect on performance.
3 months of constantly blinking light and the player will develop epilepsy. Hence changes in his/her performance are very likely.
Avatar image credit: N Lüdimois

User avatar
Vitirr
Scout
Scout
Posts: 157
Joined: 06 Jan 2006
Contact:

Unread postby Vitirr » 13 Nov 2006, 17:26

Looks like ResetObjectFlashLight makes the work easier.

User avatar
Pitsu
Round Table Hero
Round Table Hero
Posts: 1830
Joined: 22 Nov 2005

Unread postby Pitsu » 13 Nov 2006, 19:35

Vitirr wrote:Looks like ResetObjectFlashLight makes the work easier.
You mean that there is some point in reading the manuals? :)
Avatar image credit: N Lüdimois

User avatar
Vitirr
Scout
Scout
Posts: 157
Joined: 06 Jan 2006
Contact:

Unread postby Vitirr » 13 Nov 2006, 19:46

Well, sometimes it helps yes :D

Others not, because I have no idea of how to make a hero appear on the map. I've been looking at DeployReserveHero but I don't know what are the reserved heroes, or how can I reserve them. Any help is welcome.

User avatar
Pitsu
Round Table Hero
Round Table Hero
Posts: 1830
Joined: 22 Nov 2005

Unread postby Pitsu » 13 Nov 2006, 20:31

Vitirr wrote:Well, sometimes it helps yes :D

Others not, because I have no idea of how to make a hero appear on the map. I've been looking at DeployReserveHero but I don't know what are the reserved heroes, or how can I reserve them. Any help is welcome.
It is under player properties. The same place where you define whether a colour is human playabe or who is the main hero etc...
Avatar image credit: N Lüdimois

User avatar
Vitirr
Scout
Scout
Posts: 157
Joined: 06 Jan 2006
Contact:

Unread postby Vitirr » 13 Nov 2006, 20:37

Ops, blind me.

User avatar
Vitirr
Scout
Scout
Posts: 157
Joined: 06 Jan 2006
Contact:

Unread postby Vitirr » 13 Nov 2006, 23:00

One more question. Any way to obscure the parts of the map that have already been cleared?

User avatar
Vitirr
Scout
Scout
Posts: 157
Joined: 06 Jan 2006
Contact:

Unread postby Vitirr » 21 Nov 2006, 00:00

GetObjectiveState is only returning 1 or -1 to me if the quest is active or inactive (completed, failed or still not started). Has anybody experienced the same with this script?

I'd like to diferenciate if the quest has been completed or failed, so if this doesn't work I'll have to do it manually.

EDIT: nevermind, I was using actually GetObjectiveProgress :disagree:


Return to “Mapmaking Guild”

Who is online

Users browsing this forum: No registered users and 3 guests