[H5 EDITOR] Troubleshooting topic

Maps and the art of mapmaking.
User avatar
alavris
Scout
Scout
Posts: 164
Joined: 06 Jan 2006
Location: Poland
Contact:

Unread postby alavris » 19 Sep 2006, 09:02

There were few very little mistakes in your code, but even little mistake makes program not work. :) Always remember that name of function must be in red color. If it's not, that means that name of function is typed in wrong way or it's function created by user (in our case function created by user is NewDayTrigger()). So, GetDay must be changed to GetDate and messageBox to MessageBox.

Second thing, that I forgot to say about previously, is that if you want message on the first day of first week you have to wrote the command before function. Below is the code you need: :)

Code: Select all

MessageBox("Maps/Multiplayer/Alavris 1/wiad11111.txt");
-- only do this the first day

function NewDayTrigger() 
	if GetDate(DAY_OF_WEEK) == 1 then 
		-- do this first day of every week. 
		MessageBox("Maps/Multiplayer/Alavris 1/wiad22222.txt"); 
	end; 
end; 
Trigger(NEW_DAY_TRIGGER, "NewDayTrigger");
Look that "wiad22222.txt" will not be shown on day1 week1, because its first day of first week (but of course it will be shown on day1 of next weeks). So if you want it to be like with "wiad11111.txt" then write command before function, just like i did this with "wiad11111.txt".
Don't forget to change "Maps/Multiplayer/Alavris 1/wiad11111.txt" into yours text file name (and path!).

Ooooh, this Heroes V editor is so complicated.... :)
Last edited by alavris on 19 Sep 2006, 12:09, edited 2 times in total.

User avatar
alavris
Scout
Scout
Posts: 164
Joined: 06 Jan 2006
Location: Poland
Contact:

Unread postby alavris » 19 Sep 2006, 11:08

I've just realized that this script editor is very small-mistake-sensitive. Even the smallest wrong command can make all other commands no longer work. So somethimes it's enough to erase one line of code and everything else start working... Just like in real programming... So all of us must be carefull. :D

Here is other example of using time events. We want computer to check on 5th day of week 1 if player1 has more (or equal) than 25 wood. If yes then box with message appears, and player1's amount of wood is decreased to 24. Here we go with the code:

Code: Select all

function fun1() 
	if GetDate(DAY) == 5 then
		if GetPlayerResource(1, WOOD) >= 25 then
			MessageBox("Maps/Multiplayer/Alavris 1/wiad1.txt", SetPlayerResource(1, WOOD, 24));
		end;
	end;
end;

Trigger(NEW_DAY_TRIGGER, "fun1");
If we want the same situation, but on day1 week1 we have to write this:

Code: Select all

if GetPlayerResource(1, WOOD) >= 25 then
	MessageBox("Maps/Multiplayer/Alavris 1/wiad1.txt", SetPlayerResource(1, WOOD, 25));
end;
We can also write much more complicated scripts in this editor, so... let the mapmaking party begin! ;)

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

Unread postby Grumpy Old Wizard » 19 Sep 2006, 12:18

Woot! It works finally! I was about ready to pull out what little remains of my hair! :)

MessageBox("Maps/SingleMissions/A Test Map/Intro1.txt");
-- only do this the first day

function NewDayTrigger()
if GetDate(DAY_OF_WEEK) == 1 then
-- do this first day of every week.

end;
end;
Trigger(NEW_DAY_TRIGGER, "NewDayTrigger");

Although the type may be single player, the directory (at least in the US standard version) strangely uses SingleMissions.

Image

Thanks to both of you for your help. :)

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
Bandobras Took
Genie
Genie
Posts: 1018
Joined: 06 Jan 2006

Unread postby Bandobras Took » 19 Sep 2006, 14:04

Pitsu wrote:
Bandobras Took wrote:Has anybody been able to get a script to fire when a town is captured? I've named a town "TestTown" and been trying Trigger(OBJECT_CAPTURE_TRIGGER,"TestTown","TestScript"); to no avail.
.
Should work. I would double check that the "TestScript" function itself is correct. And the syntax everywhere...
Hmmm . . . can someone provide an example of a function that works when capturing a town so I can compare?
Far too many people speak their minds without first verifying the quality of their source material.

User avatar
alavris
Scout
Scout
Posts: 164
Joined: 06 Jan 2006
Location: Poland
Contact:

Unread postby alavris » 19 Sep 2006, 18:59

Bandobras Took wrote:
Pitsu wrote:
Bandobras Took wrote:Has anybody been able to get a script to fire when a town is captured? I've named a town "TestTown" and been trying Trigger(OBJECT_CAPTURE_TRIGGER,"TestTown","TestScript"); to no avail.
.
Should work. I would double check that the "TestScript" function itself is correct. And the syntax everywhere...
Hmmm . . . can someone provide an example of a function that works when capturing a town so I can compare?
I can try. Firstly open object properties tree (of the town which will be captured). To do this, mark by the cursor the town on the map. When it's red, press CTRL+SPACE. Now, add name of the town in this tree. It's important to do it here, because done in town properties window will not work. Now in map properties window paste the example code:

Code: Select all

function fun1()
	MessageBox("Maps/Multiplayer/Alavris 1/wiad1.txt");
end;

Trigger(OBJECT_CAPTURE_TRIGGER, "TestTown", "fun1");
It's all simple, but the trap is when we have to name the town. Remember to do it in right place.
.

User avatar
Bandobras Took
Genie
Genie
Posts: 1018
Joined: 06 Jan 2006

Unread postby Bandobras Took » 19 Sep 2006, 20:32

When it's red, press CTRL+SPACE. Now, add name of the town in this tree. It's important to do it here, because done in town properties window will not work.
That could explain it; I always edited the town name from the town properties window. I'll try it when I get home.
Far too many people speak their minds without first verifying the quality of their source material.

User avatar
Bandobras Took
Genie
Genie
Posts: 1018
Joined: 06 Jan 2006

Unread postby Bandobras Took » 19 Sep 2006, 21:30

Cool; it works!

Now on to my next question: edit Never mind (hits self on forehead and reminds himself that LUA requires an end to all if then statements).

Okay, now for a real next question:

The OBJECT_CAPTURE_TRIGGER sends the old owner, new owner, name of the capturing hero, and name of the object.

But when I try to use the name of the object in a script, the line fails, even though all the others (lines relating to old and new owner or the hero) work. The line will even work if I simple type the script name of the town as a string, but will not work as a parameter passed to the function by the trigger. Any reason why?

e.g.
function Transformer(aaa,bbb,ccc,ddd)
SetPlayerResource(aaa,15000)
SetPlayerResource(bbb,20000)
if (HasHeroSkill(ccc,SKILL_GATING)) then
TransformTown(ddd,TOWN_INFERNO)
end;
end;
The bolded line fails, but will work if I use

TransformTown("TesterTown",TOWN_INFERNO)
Far too many people speak their minds without first verifying the quality of their source material.

User avatar
alavris
Scout
Scout
Posts: 164
Joined: 06 Jan 2006
Location: Poland
Contact:

Unread postby alavris » 20 Sep 2006, 08:02

Bandobras Took wrote:But when I try to use the name of the object in a script, the line fails, even though all the others (lines relating to old and new owner or the hero) work. The line will even work if I simple type the script name of the town as a string, but will not work as a parameter passed to the function by the trigger. Any reason why?

e.g.
function Transformer(aaa,bbb,ccc,ddd)
SetPlayerResource(aaa,15000)
SetPlayerResource(bbb,20000)
if (HasHeroSkill(ccc,SKILL_GATING)) then
TransformTown(ddd,TOWN_INFERNO)
end;
end;
The bolded line fails, but will work if I use

TransformTown("TesterTown",TOWN_INFERNO)
If this line works when it's separated then our suspicion goes to this line of code:

Code: Select all

if (HasHeroSkill(ccc,SKILL_GATING)) then
So, did you add/change hero name in his properties tree or properties window? Check if it's done in the right place... I think the problem may be here...
.

User avatar
Bandobras Took
Genie
Genie
Posts: 1018
Joined: 06 Jan 2006

Unread postby Bandobras Took » 20 Sep 2006, 13:29

The if/then/end part works beautifully -- it's the variable ddd (which ought to be the object name) that gives the problem. When I test the map and use the actual name of the town in the function, it works fine -- the town gets converted to Inferno if the hero has Gating.

I meant that the bolded line will fail unless I replace it with the other one. As long as I use a specific town name, the whole function works. If I try to use a parameter passed to the function, it fails.

EDIT:

Actually, the script works if written like this:
function Transformer(aaa,bbb,ccc,ddd)
SetPlayerResource(PLAYER_1,GOLD,15000)
if (HasHeroSkill(ccc,SKILL_GATING)) then
TransformTown("TesterTown",TOWN_INFERNO)
end;
end;
But failed if I tried to SetPlayerResource for aaa and bbb. Weird.
Far too many people speak their minds without first verifying the quality of their source material.

User avatar
alavris
Scout
Scout
Posts: 164
Joined: 06 Jan 2006
Location: Poland
Contact:

Unread postby alavris » 20 Sep 2006, 14:36

Bandobras Took wrote:The if/then/end part works beautifully -- it's the variable ddd (which ought to be the object name) that gives the problem. When I test the map and use the actual name of the town in the function, it works fine -- the town gets converted to Inferno if the hero has Gating.

I meant that the bolded line will fail unless I replace it with the other one. As long as I use a specific town name, the whole function works. If I try to use a parameter passed to the function, it fails.
Here's the srcipt which I have just written and it works:

Code: Select all

function fun1(oldowner, newowner, heroname, townname)
	if (HasHeroSkill(heroname, SKILL_GATING)) then 
		TransformTown("TestTown", TOWN_INFERNO);
		Trigger(OBJECT_CAPTURE_TRIGGER, "TestTown", nil);
	end;
end;

Trigger(OBJECT_CAPTURE_TRIGGER, "TestTown", "fun1");
Bandobras Took wrote:But failed if I tried to SetPlayerResource for aaa and bbb. Weird.
This makes that old_owner can be any player... but PLAYER_NONE can't have any resources... so here's the main problem I think.
.

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

Unread postby Pitsu » 20 Sep 2006, 17:36

Bandobras Took wrote:.
function Transformer(aaa,bbb,ccc,ddd)
SetPlayerResource(aaa,15000)
SetPlayerResource(bbb,20000)
if (HasHeroSkill(ccc,SKILL_GATING)) then
TransformTown(ddd,TOWN_INFERNO)
end;
end;
Is the 'ddd' specified correctly in function call-up? like

if GetObjectOwner("TestTown") == 1 then
Transformer(PLAYER_2, PLAYER_1, "Agrael", "TestTown");
end

? If the given name does not work, maybe to try to add a specialization and use the games internal name?

User avatar
alavris
Scout
Scout
Posts: 164
Joined: 06 Jan 2006
Location: Poland
Contact:

Unread postby alavris » 20 Sep 2006, 20:56

Pitsu wrote:Is the 'ddd' specified correctly in function call-up?
Bandobras Took said that this script works fine on his computer. I also provided similar code above which works too. So... as long as it works... it's fine. ;)
.

User avatar
Bandobras Took
Genie
Genie
Posts: 1018
Joined: 06 Jan 2006

Unread postby Bandobras Took » 20 Sep 2006, 21:30

alavris wrote: Here's the srcipt which I have just written and it works:

Code: Select all

function fun1(oldowner, newowner, heroname, townname)
	if (HasHeroSkill(heroname, SKILL_GATING)) then 
		TransformTown("TestTown", TOWN_INFERNO);
		Trigger(OBJECT_CAPTURE_TRIGGER, "TestTown", nil);
	end;
end;

Trigger(OBJECT_CAPTURE_TRIGGER, "TestTown", "fun1");
Can you use the parameter "townname" for anything in that script? Add a building, change the town type, etc? This is where it falls down for me, trying to use a variable instead of a hard-coded string.

If one can write a script that accepts a variable town name, then I won't have to duplicate it each time I place a town on the map, I'll only have to write different Triggers to call the same function.
Far too many people speak their minds without first verifying the quality of their source material.

User avatar
alavris
Scout
Scout
Posts: 164
Joined: 06 Jan 2006
Location: Poland
Contact:

Unread postby alavris » 20 Sep 2006, 21:53

Bandobras Took wrote:
alavris wrote: Here's the srcipt which I have just written and it works:

Code: Select all

function fun1(oldowner, newowner, heroname, townname)
	if (HasHeroSkill(heroname, SKILL_GATING)) then 
		TransformTown("TestTown", TOWN_INFERNO);
		Trigger(OBJECT_CAPTURE_TRIGGER, "TestTown", nil);
	end;
end;

Trigger(OBJECT_CAPTURE_TRIGGER, "TestTown", "fun1");
Can you use the parameter "townname" for anything in that script? Add a building, change the town type, etc? This is where it falls down for me, trying to use a variable instead of a hard-coded string.

If one can write a script that accepts a variable town name, then I won't have to duplicate it each time I place a town on the map, I'll only have to write different Triggers to call the same function.
I think that "townname" parameter can't be used in this function. As you can see "heroname" could be used, because it is not the main parameter that triggers uses in this situation... I don't know how to explain this more clearly... and I even don't know if I'm right... but this could explain why "heroname" works as parameter and "townname" don't. I have no other idea.
.

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

Unread postby Pitsu » 21 Sep 2006, 06:24

I did once get a simpler script in style (not an exact copy-paste) to work:

Code: Select all

function transform(townname);
if rass == 1 then
-- variable rass is defined elsewhere
TransformTown (townname, 1);
else
TransformTown (townname, 2);
end;
end;

function change1();
transform("Town1");
MessageBox("Maps/whereever... . txt");
end;

function change2();
transform("Town2");
MessageBox("Maps/whereever... 2. txt");
end;

Trigger(OBJECT_CAPTURE_TRIGGER, "Town1", "change1");
Trigger(OBJECT_CAPTURE_TRIGGER, "Town2", "change2");

User avatar
alavris
Scout
Scout
Posts: 164
Joined: 06 Jan 2006
Location: Poland
Contact:

Unread postby alavris » 21 Sep 2006, 08:10

Pitsu wrote:I did once get a simpler script in style (not an exact copy-paste) to work
Oh, it's very good idea! Can you also write the part of code where variable rass is defined, so that we have the whole example, ready to use for everyone who's not good enough in scripting?
.

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

Unread postby Pitsu » 21 Sep 2006, 19:41

Ok. A map with two players, both with random starting town and "generate hero in main town at the game start" enabled. Towns "town1" and "town2" keep switching every time when captured by opponent. Conversion is to opponents starting race, not occupying hero race in this case. Of course does not work in multiplayer mode and every transformation reduces town level to 1.

The first part that identifies players race seems unnecessarily long, but strangely none of the short versions did work for me

Code: Select all

for j = 1, 2 do
	nimi = GetPlayerHeroes(j);
		for i=0,length(nimi)-1 do
		if HasHeroSkill (nimi[i], SKILL_ARTIFICIER ) then
			rassx = 2;			
		end;
		if HasHeroSkill (nimi[i], SKILL_NECROMANCY ) then
			rassx = 4;	
		end;
		if HasHeroSkill (nimi[i], SKILL_AVENGER ) then
			rassx = 1;	
		end;
		if HasHeroSkill (nimi[i], SKILL_TRAINING ) then
			rassx = 0;	
		end;
		if HasHeroSkill (nimi[i], SKILL_INVOCATION ) then
			rassx = 3;	
		end;
		if HasHeroSkill (nimi[i], SKILL_GATING ) then
			rassx = 5;
		end;
		end;
			if j == 1 then 
				rass1 = rassx;
			else
				rass2 = rassx;
			end;
end;

function change(townname)
	if GetObjectOwner(townname) == PLAYER_2 then
		TransformTown(townname, rass2);
	else	
		TransformTown(townname, rass1);
	end;
end;

function change1()
	change("town1");
end;

function change2()
	change("town2");
end;

Trigger(OBJECT_CAPTURE_TRIGGER, "town1", "change1");
Trigger(OBJECT_CAPTURE_TRIGGER, "town2", "change2");

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

Unread postby Grumpy Old Wizard » 22 Sep 2006, 10:53

Does anyone know how to convert a single player map into a multiplayer map?

I started making a singleplayer map. I did not know when I started the map that you couldn't have multiple positions designated as playable (just one at a time) for a single player map. Now I would like to convert it to a multiplayer map if possible.

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
Pitsu
Round Table Hero
Round Table Hero
Posts: 1830
Joined: 22 Nov 2005

Unread postby Pitsu » 22 Sep 2006, 11:03

Grumpy Old Wizard wrote:Does anyone know how to convert a single player map into a multiplayer map?
Should be: open the *.h5m file with Winrar or Winzip and simply rename "SingleMissions" catalogue to "MultiPlayer". Not done myself, but some say it works.

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

Unread postby Grumpy Old Wizard » 22 Sep 2006, 12:14

Pitsu wrote:
Grumpy Old Wizard wrote:Does anyone know how to convert a single player map into a multiplayer map?
Should be: open the *.h5m file with Winrar or Winzip and simply rename "SingleMissions" catalogue to "MultiPlayer". Not done myself, but some say it works.
Thanks. :) ZipGenius doesn't seem to be able to open it so I am downloading Winzip to give it a go.

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."


Return to “Mapmaking Guild”

Who is online

Users browsing this forum: No registered users and 5 guests