~ Forums of Enroth ~

An Enroth diehard fan community
 
HomeHome  ChatChat  FAQFAQ  SearchSearch  RegisterRegister  Log inLog in  
Latest topics
» Link do pobrania
by Ragoon 2017-05-25, 05:49

» Introduce yourself
by Tibor0803 2017-05-23, 09:02

» 7 Days Quest [Eng] by Nieznany !NEW! 2017
by Pitsu 2017-05-23, 07:20

» Ragoon's Graphics For HoMM3SW
by xxswwxx 2017-05-23, 05:46

» Pogawędki (PL)
by Huntka 2017-05-23, 04:36

» Chat relocation
by Orzie 2017-05-23, 01:20

» The Symphony of Heroes - Paul Romero with ochestra concert
by Sir Albe 2017-05-21, 10:02

Poll
"Wait" in HoMM2?
Yes
81%
 81% [ 42 ]
No
19%
 19% [ 10 ]
Total Votes : 52
Most Viewed Topics
H3SW: General Graphics discussion
Ragoon's Graphics For HoMM3SW
H3SW General Discussion
H3SW: Dwelling Development
H3SW Map List: Work in progress
Dervish Faction General Concept
Enrothian Fan Art
H3SW Recruitment Point - Enroth Needs You!
Серия книг "Земли Меча и Магии"
Introduce yourself

Share | 
 

 Sorrow's End script

View previous topic View next topic Go down 
AuthorMessage
Unknown_Hero
Minotaur
Minotaur
avatar

Messages : 313
Quality Points : 37
Registration Date : 2015-09-06

PostSubject: Sorrow's End script   2015-09-26, 08:56

In the Sorrow's End script, I added the lines:

GrantSpell(h, SPELL_VIEW_MINES);
GrantArtifact(h, ARTIFACT_ENDLESS_POUCH_OF_SULFUR);

If I understand correctly, the "give_spells" function should only be applied once at the start of the scenario.

Trigger(MAP_START, "", "give_spells");

But, and this only during the first turn, each time I exit the town screen, the hero gets an additional Endless Pouch of Sulfur, and he regains all his spell points (I casted the View Mines spell several times to reduce the hero spell points), and this happens if the hero is inside or outside the town.

Tested with Ironfist version 0.8.2, since the Ironfist version 0.8.3 program display an "Unexpected Program termination" window with "Error opening file .\GAMES\AUTOSAVE.GM1!", when I end the turn.

Code:
Trigger(MAP_START, "", "give_spells");
Trigger(TOWN_LOADED, "Sorrow's End", "check_library");

function give_spells()
 p = GetPlayer(0);
 h = GetHero(p, 0);
 GrantSpell(h, SPELL_METEOR_SHOWER);
 GrantSpell(h, SPELL_VIEW_MINES);
 GrantArtifact(h, ARTIFACT_ENDLESS_POUCH_OF_SULFUR);
 SetPrimarySkill(h, PRIMARY_SKILL_KNOWLEDGE, 10);
 SetSpellpoints(h, 100);
 SetSecondarySkill(h, SECONDARY_SKILL_LEADERSHIP, 1);
 SetSecondarySkill(h, SECONDARY_SKILL_WISDOM, 3);
 
 p2 = GetPlayer(1);
 h2 = GetHero(p2, 0);
 GrantArmy(h2, CREATURE_BONE_DRAGON, 10);
 
end;


Then I added the line:

GrantArtifact(h, ARTIFACT_MAGES_RING_OF_POWER);

The Mage Guild is built as expected, but all spells are not written in the magic book (click directly on the hero portrait to open the hero screen and look at the spells in the magic book), then exit the hero screen and move the hero outside the town, look once again in the magic book, all spells are not avalaible.

In this save, all spells are not written in the magic book, and the hero gets the Armageddon spell, even if this spell is not avalaible in the Mage Guild.

Link expired, New link for test-sorrow-01.GX1.

If you look at the spells in the Mage Guild when the hero is still inside the town, then the spells are written in the magic book; if the hero outside the town comes back in the town, then the spells are written in the magic book.

Another problem is than each time the hero enters the town with another Mages Ring of Power, the message box "The Mage's Ring fits easily in the keyhole of the sealed library door. Inside lie shelves packed with tomes." is displayed, and 1 Mages Ring of Power is removed from the hero inventory, and this even if the Mage Guild is already built.

The message display and the removal of the artifact should only be applied once, when the Mage Guild is built the first time.

Code:
Trigger(MAP_START, "", "give_spells");
Trigger(TOWN_LOADED, "Sorrow's End", "check_library");

function give_spells()
 p = GetPlayer(0);
 h = GetHero(p, 0);
 GrantSpell(h, SPELL_METEOR_SHOWER);
 GrantSpell(h, SPELL_VIEW_MINES);
 GrantArtifact(h, ARTIFACT_ENDLESS_POUCH_OF_SULFUR);
 GrantArtifact(h, ARTIFACT_MAGES_RING_OF_POWER);
 SetPrimarySkill(h, PRIMARY_SKILL_KNOWLEDGE, 10);
 SetSpellpoints(h, 100);
 SetSecondarySkill(h, SECONDARY_SKILL_LEADERSHIP, 1);
 SetSecondarySkill(h, SECONDARY_SKILL_WISDOM, 3);
 
 p2 = GetPlayer(1);
 h2 = GetHero(p2, 0);
 GrantArmy(h2, CREATURE_BONE_DRAGON, 10);
 
end;

function check_library()
 t = GetCurrentTown();
 if HasVisitingHero(t) then
 h = GetVisitingHero(t);
 if HasArtifact(h, ARTIFACT_MAGES_RING_OF_POWER) then
 TakeArtifact(h, ARTIFACT_MAGES_RING_OF_POWER);
 MessageBox("The Mage's Ring fits easily in the keyhole of the sealed library door. Inside lie shelves packed with tomes.");
 BuildInCurrentTown(BUILDING_MAGE_GUILD);
 BuildInCurrentTown(BUILDING_MAGE_GUILD);
 BuildInCurrentTown(BUILDING_MAGE_GUILD);
 BuildInCurrentTown(BUILDING_MAGE_GUILD);
 BuildInCurrentTown(BUILDING_MAGE_GUILD);
 SetNumGuildSpells(t, 0, 4);
 SetNumGuildSpells(t, 1, 4);
 SetNumGuildSpells(t, 2, 4);
 SetNumGuildSpells(t, 3, 4);
 SetNumGuildSpells(t, 4, 4);
 SetGuildSpell(t, 4, 0, SPELL_DIMENSION_DOOR);
 SetGuildSpell(t, 4, 1, SPELL_SUMMON_WATER_ELEMENTAL);
 SetGuildSpell(t, 4, 2, SPELL_SUMMON_EARTH_ELEMENTAL);
 SetGuildSpell(t, 4, 3, SPELL_RESURRECT_TRUE);
 end;
 end;
end;



Last edited by Unknown_Hero on 2016-04-04, 09:12; edited 1 time in total
Back to top Go down
Unknown_Hero
Minotaur
Minotaur
avatar

Messages : 313
Quality Points : 37
Registration Date : 2015-09-06

PostSubject: Re: Sorrow's End script   2016-04-01, 07:20

For the spells in the Mage Guild, it would be nice to being able to have random spells.

Examples:

For a completely random spell: SetGuildSpell ... random

For a random spell among several: SetGuildSpell ... random, (SPELL_DIMENSION_DOOR, 3), (SPELL_RESURRECT_TRUE, 4), (SPELL_SUMMON_EARTH_ELEMENTAL, 2)

A spell will be selected among the 3 spells available, the values 3, 4 and 2 are used to calculate the percentage chance of appearance of spells in the Guild.

3 + 4 + 2 = 9

100 / 9 = 11.11

3 * 11,11 = 33.33 % chance of appearance for Dimension Door
4 * 11,11 = 44.44 % chance of appearance for Resurrect True
2 * 11,11 = 22.22 % chance of appearance for Earth Elemental
Back to top Go down
Darmani
Master Modder
Master Modder
avatar

Messages : 163
Quality Points : 29
Registration Date : 2014-12-27

PostSubject: Re: Sorrow's End script   2016-04-02, 12:02

Good find with MAP_START. The buggy behavior of the MAP_START trigger has been known since it was implemented (in the Sorrow's End script, we tried to mostly use things like SetPrimarySkill where it wouldn't matter). We're currently merging in the code from the Tales of Enroth mod, which has massive expansions to the scripting system, including a proposed fix for the MAP_START behavior.

For learning the spells in the mage guild, I believe there are certain cases in the original game where that happens too. Still, this should be a quick fix, and I'll note it.

You can actually implement the random spell behavior in pure Lua -- see http://www.lua.org/pil/18.html .

It's perfectly fine that that message appears twice in Sorrow's End. Under normal map play, you can't get multiple Mage's Rings, and so the map wasn't built with that in mind.
Back to top Go down
Unknown_Hero
Minotaur
Minotaur
avatar

Messages : 313
Quality Points : 37
Registration Date : 2015-09-06

PostSubject: Re: Sorrow's End script   2016-04-03, 03:50

Darmani wrote:
We're currently merging in the code from the Tales of Enroth mod, which has massive expansions to the scripting system, including a proposed fix for the MAP_START behavior.

Interesting, is there a link with the description of this Tales of Enroth mod?

Darmani wrote:
You can actually implement the random spell behavior in pure Lua -- see http://www.lua.org/pil/18.html .

So, it's possible in some way. Smile

Darmani wrote:
It's perfectly fine that that message appears twice in Sorrow's End. Under normal map play, you can't get multiple Mage's Rings, and so the map wasn't built with that in mind.

In this case, the script/map creator has to be very cautious and remember the same artefact can also appear in Chest, Graveyard, Skeleton (Desert), etc.
Back to top Go down
Darmani
Master Modder
Master Modder
avatar

Messages : 163
Quality Points : 29
Registration Date : 2014-12-27

PostSubject: Re: Sorrow's End script   2016-04-03, 17:14

It seems the link to download that savegame is broken. I just tried this in Sorrow's End, and I saw the spells all being written correctly. Still, I am putting in an extra line of code so that, in all cases, when you build a mage guild or library using scripts, the hero in the town will get the new spells.

Quote :
In this case, the script/map creator has to be very cautious and remember the same artefact can also appear in Chest, Graveyard, Skeleton (Desert), etc.

That is true. I will say that, the important thing is, it is quite easy to change the script so that this only happens once. This may be a bug in this map (although I think it's fine), but it is not a bug in the game.
Back to top Go down
Darmani
Master Modder
Master Modder
avatar

Messages : 163
Quality Points : 29
Registration Date : 2014-12-27

PostSubject: Re: Sorrow's End script   2016-04-03, 17:19

Okay, actually, I just checked the code again. The code is such that a hero learns new spells every time a mage guild is built, no matter how it was built. This shouldn't be happening.
Back to top Go down
Darmani
Master Modder
Master Modder
avatar

Messages : 163
Quality Points : 29
Registration Date : 2014-12-27

PostSubject: Re: Sorrow's End script   2016-04-03, 17:20

Back to top Go down
Unknown_Hero
Minotaur
Minotaur
avatar

Messages : 313
Quality Points : 37
Registration Date : 2015-09-06

PostSubject: Re: Sorrow's End script   2016-04-04, 09:46

Darmani wrote:
It seems the link to download that savegame is broken.

It's not broken, the link is expired, the link is valid for a period of 30 days, and if there is at least one download during this time, the period is extended again for 30 days, and this forever if there is a least one download; if there is no download during this period, the file is considered expired and deleted.

So, this means that you have not downloaded this file during the period of 30 days; interesting.

What is your method of working with the files uploaded to the forum to report bugs?
You should cherish these files and back them everywhere as soon as they are available, it's a lot of work.

New link for test-sorrow-01.GX1

Unknown_Hero wrote:
In this save, all spells are not written in the magic book, and the hero gets the Armageddon spell, even if this spell is not avalaible in the Mage Guild.

The hero gets the Armageddon spell certainly because it's the "normal" spell generated by the game in the Mage Guild, so the hero learns it, then, the lua script is applied and the Armageddon spell is removed from the Mage Guild, and the script spells are assigned, you need to make a change for this to not happens.

*

Here the Sorrow's End modified script.

http://speedy.sh/UwgmK/SorrowEn.MX2.lua

I don't have the save file for this example, ironfist.exe ver 0.8.4 crashed several times during my test and the print screens.


Check hero at start of the scenario, 3 artefacts generated by lua script.




Check hero start magic book adventure spell, 1 spell generated by lua script.




Check hero start magic book combat spell, 1 standard spell for Wizard hero, 1 spell generated by lua script.




Enter the Town Screen, message for Mage Guild.




Bug line of dots bottom of the screen during Mage Guild building.




Check directly hero inside town after Mage Guild built, Mage's Ring removed by lua script.




Check directly hero inside town magic book adventure spell after Mage Guild built, 2 "normal" spells generated and written in the book by the program are added.




Check directly hero inside town magic book combat spell after Mage Guild built, 7 "normal" spells generated and written in the book by the program are added.
Here you can see the level 5 "normal" spell Mirror Image is written in the book, but it will not be in the Mage Guild later, so the hero gets this spell "for free".




Exit Hero Screen, exit Town Screen.
Check directly hero inside town after exiting Town Screen, 3 artefacts generated by lua script.




Move hero outside town.
Check directly hero moved outside town magic book adventure spell after Mage Guild built, no spells added.




Check directly hero moved outside town magic book combat spell after Mage Guild built, no spells added.




Check the Mage Guild, here the Mirror Image spell is "removed" because lua script generated new spells.
Note: You can also see that there is also a low priority bug (already on my list, but not yet reported), the cost of the spell [30] is cut for the Summon Elemental spells.




Exit the Mage Guild Screen, exit the Town Screen.
Check Hero Screen, 3 artefacts generated by lua script.




Move the hero to the town, message for Mage Guild.




Check hero just after entering town, Mage's Ring removed by lua script.




Check hero magic book adventure spell after entering town, spells generated by lua script added.




Check hero magic book combat spell after entering town, spells generated by lua script added first page.




Check hero magic book combat spell after entering town, spells generated by lua script added second page, Mirror Image still there.



*

Darmani wrote:
Okay, actually, I just checked the code again. The code is such that a hero learns new spells every time a mage guild is built, no matter how it was built. This shouldn't be happening.

Are you this type of programmer that changes the code, then just looks at the code and says: "Yes, it works now.", and then doesn't even try the modified program to test it in real situations?  Shocked  Evil or Very Mad  Question

Darmani wrote:
This shouldn't be happening.

E pur si muove! Cool

Darmani wrote:
Tales of Enroth: http://handbookhmm.ru/forum/viewtopic.php?f=39&t=388&sid=4013c3b3863bfd5c323cf2a187b7437f

Спасибо. Smile


Last edited by Unknown_Hero on 2016-04-04, 11:07; edited 1 time in total
Back to top Go down
Steven Aus
Elf
Elf
avatar

Messages : 108
Quality Points : 38
Registration Date : 2015-07-21
Age : 37

PostSubject: Re: Sorrow's End script   2016-04-04, 11:04

Everyone can make mistakes. Even for good programmers, for a reclusive bug it can be tempting to make a change and then leave it. But obviously this current solution needs to be fixed.
Back to top Go down
Darmani
Master Modder
Master Modder
avatar

Messages : 163
Quality Points : 29
Registration Date : 2014-12-27

PostSubject: Re: Sorrow's End script   2016-04-05, 07:00

Unknown_Hero wrote:
Darmani wrote:
It seems the link to download that savegame is broken.

So, this means that you have not downloaded this file during the period of 30 days; interesting.

What is your method of working with the files uploaded to the forum to report bugs?
You should cherish these files and back them everywhere as soon as they are available, it's a lot of work.

Yeah, it is a lot of work to create these, and I understand that us downloading them helps you feel appreciated. From our perspective, these forums serve as a nice list of bugs and things to work on, and having the links to the savegames in the thread works to keep all information about the bug in one place, especially because I don't expect download links to expire. Maybe there's a way of uploading savegames which doesn't have this problem? It actually probably doesn't matter anymore, because we're about to (this week) change how we track information about bugs and tasks.

Also....I confess that I somehow missed this thread when it was first created. Embarassed

(As an aside, Hongxuan is still working on the bug with elementals and spell immunity. It does take new programmers time to ramp up, so we are still processing these slower than they come in, sadly.)


Quote :

Are you this type of programmer that changes the code, then just looks at the code and says: "Yes, it works now.", and then doesn't even try the modified program to test it in real situations? Shocked Evil or Very Mad Question

No. I am a professional.

I'm not taking about my code. Ironfist is a relatively small amount of code which integrates with the 100,000 lines of code that comprise the original game. What I mean is that I checked the decompilation of Heroes II, and it appears there is simply no circumstance under which you could build a mage guild and not learn the spells.


It sounds I misunderstood you, and thought you were saying that the hero didn't learn any of the spells in the new mage guild. This is what I was looking for when I tested, the behavior I failed to find, and then what I checked the original game's code to see if I could find any situation in which anything like it could happen.

I now understand that you are only talking about the spells specifically set by the Sorrow's End script. Now that I understand that, I know perfectly what's happening and how to fix it: that you do learn new spells immediately when the mage guild is built, but you don't learn new spells immediately after a call to SetGuildSpell. I will change SetGuildSpell to immediately have the visiting hero learn the spell, which is part of the problem. This is first and foremost a bug in the Sorrow's End script: the real fix is to set the new spells in the mage guild before it is built. I've updated the documentation for the SetGuildSpell function with this caveat, and will fix the Sorrow's End script tonight for the next release. Here's the new documentation for the SetGuildSpell function; I've bolded the added sentence.

Quote :

SetGuildSpell(town, level, column, spell)
town: The town to modify. (See GetCurrentTown.)
level: The level of mage guild to modify.
column: A number 0-4 representing which spell in that level to change.
spell: The spell to assign to that level and column of the mage guild

Sets which spell is available in the mage guild at the given level and column. Which spells will be available in the mage guild is predetermined, meaning this can be used whether or not the mage guild has been built to that level. It is recommended that you call this before building a mage guild, as heroes will immediately learn whatever is in the mage guild immediately when the mage guild is built.

So, I apologize for misunderstanding you earlier, and hope this clears things up.
Back to top Go down
Unknown_Hero
Minotaur
Minotaur
avatar

Messages : 313
Quality Points : 37
Registration Date : 2015-09-06

PostSubject: Re: Sorrow's End script   2016-04-06, 04:49

Darmani wrote:
So, I apologize for misunderstanding you earlier, and hope this clears things up.

No worries, my English is certainly not "at the top". Laughing
Back to top Go down
 
Sorrow's End script
View previous topic View next topic Back to top 
Page 1 of 1
 Similar topics
-
» "Post a comment" Script - very important!
» Help with snow script and java.
» Anti DDOs script
» Golden Oldies complete with videos
» All watched over by machines and Loving Grace

Permissions in this forum:You cannot reply to topics in this forum
~ Forums of Enroth ~ :: Modding Guild :: Heroes of Might and Magic II: Project Ironfist :: Modding and Mapmaking-
Jump to: