Call to H-IV mapmakers - AI enchancing scripts

The old Heroes games developed by New World Computing. Please specify which game you are referring to in your post.

Moderator: Moderators

User avatar
Karmakeld
CH Staff
CH Staff
Posts: 1092
Joined: 12 Nov 2011

Postby Karmakeld » Jun 26 2015, 7:57

Regarding the H4utility it CAN extract and paste scripts, I have no idea how to do it, but Maciek does. I'll ask him. I don't know how the program can find heroes on a map but I assume it somehow can. Perhaps even the numberof heroes. ILive, in order to rename a script to xxMudgeon, you need to know Mudgeon is placed on the map. Formality, but we need to use numbers instead. The recursive script might be useable with the utility (thx Derrick for reminding us about it :) ).
I think it's very uncommon that maps have quests requiring multiple artifacts of the same kind AND at the same time most of these will be found on a single hero. But I'll Maciek to contribute with his knowledge about the program and its possibilities.
I'm silent in seven languages - and I got all my familys fear.
Everytime you throw dirt, you loose a little ground

User avatar
Maciek
Scout
Scout
Posts: 168
Joined: 14 May 2009
Location: Poland

Postby Maciek » Jun 26 2015, 12:12

All I know about h4util comes either from its documentation (h4util.doc) or from using it. In addition to h4util, you may want to get some text editor that's fit for editing scripts. Such as Notepad++ or Vim.


Now, let's teach you how to use h4util and your fancy text editor to modify scripts in your maps without opening the map editor.

Exercise 1. Make a simple test map with a few scripts. Keep the number of armies on the map and number of scripts under 10 or you'll have troubles finding them later. Put the map in the same folder as h4util.

Exercise 2. Open h4util's documentation. Find and read the descriptions of -p, -a and -w options and examples presenting their usage.

Exercise 3. Open a Terminal/Command Prompt. Use command 'cd' to go to the folder from exercise 1. Don't hesitate to ask google a short question if you don't know where is a 'Terminal' or 'Command Prompt' in your system or how to use 'cd command'.

Exercise 4. Produce a dump file for your map (see exercise 2). Open the newly created .c file with your text editor and find a script of your choice. Identify the script's beginning and ending.

Exercise 5. Make a small modification to the script and add it to the map (see exercise 2). Check in game and in map editor if your modification works as intended.

You can also add/delete scripts the same way.

User avatar
PatFX
Peasant
Peasant
Posts: 68
Joined: 05 Mar 2015
Location: Montreal, Canada

Postby PatFX » Jun 26 2015, 14:17

Good!

Thanks Maciek!

It looks pretty simple. I will get a look at h4util. I think then, I will be able to do a little programm that will automaticaly detect each hero, then modified and insert script for each hero.

I will be really happy if we can easily use the recursive methode#2, because we will don't need to care about the number of artifact, all artifact will be keep (no quest problem)... and less scripting.... :hoo:

I will get a look at h4util next week and come back to you.


Few more things need to be done before I can start doing the script:
1- Finish the left hand artifact list and do a resume of all list (and everybody need to agree). I already start the left hand list, but it's not finish yet...
2- Do a list for misc and ring artifact to decide how many of each artifact we want to equip (exemple, equip only 1 Flamming arrow first in the give script even if the hero has 2 flamming arrow, then, at the end, give back the remaining artifact)
3- Decide priority for misc artifact of the victorious script (for adventure map utility, Ressource and scouting radius)


Here is a list of artifact I want to equip on the victorious script of each hero:
Ring: Equestrian's Gloves
Boots: all boots except Winged Sandals
Neck: Necklace of Charm, Statesman's Medal, Druid's chains
Misc: all misc ressource artifact, Viewing Crystal/telescope (maybe sextant too)

For Necklace of Charm and Statesman's Medal, it's a little bit like cheating (the hero can get the creature with these artifact AND equip an other artifact fo combat with the encounter script, because diplomacy and charme is trig before encounter script), but I think it's OK.

User avatar
GreatEmerald
CH Staff
CH Staff
Posts: 3329
Joined: 24 Jul 2009
Location: Netherlands

Postby GreatEmerald » Jun 26 2015, 18:20

PatFX wrote:2- Do a list for misc and ring artifact to decide how many of each artifact we want to equip (exemple, equip only 1 Flamming arrow first in the give script even if the hero has 2 flamming arrow, then, at the end, give back the remaining artifact)


This is just a general question of "does it stack or not". If it stacks, give all of them the hero has. If it doesn't stack, give one. And it's something that would totally be fit for inclusion on a website article, too, since it's important for gameplay reasons.

User avatar
PatFX
Peasant
Peasant
Posts: 68
Joined: 05 Mar 2015
Location: Montreal, Canada

Postby PatFX » Jun 26 2015, 19:23

This is just a general question of "does it stack or not". If it stacks, give all of them the hero has. If it doesn't stack, give one. And it's something that would totally be fit for inclusion on a website article, too, since it's important for gameplay reasons.


Most Ring and Misc stacks, except for:

Ring of the Cobra’s eye
Ring of Permanency
Ring of Greater Negation
Ring of Lesser Negation

Arrows (Flamming, Poison, Stunning, Slayer, Spider's)
Shackles of War
Badge of Courage
Purse of Penny Pinching
Crystal of Memory

User avatar
PatFX
Peasant
Peasant
Posts: 68
Joined: 05 Mar 2015
Location: Montreal, Canada

Postby PatFX » Jun 26 2015, 20:58

Left hand artifact list:

LEFT HAND
Adamantine Shield (+3 defense to hero, +50% defense for friendly)
Lion's Shield of Courage (+3 defense to hero, +40% defense for friendly)
Death Shield (+3 defense to hero, +30% defense and Life Ward for friendly)
Life Shield (+3 defense to hero, +30% defense and Death Ward for friendly)
Shield of Chaos (+3 defense to hero, +30% defense and Order Ward for friendly)
Shield of Order (+3 defense to hero, +30% defense and Chaos Ward for friendly)
Unnatural Shield (+3 defense to hero, +30% defense and Nature Ward for friendly)
Dragon Scale Shield (+3 defense to hero, +30% defense and Fire resistance for friendly)
Steadfast Shield (+3 defense to hero, +30% defense for friendly)
Archmage's Codex (fifth level spell)
Guildmaster's Compendium (fourth level spell)
Tome of Order (all Order spell)
Tome of Chaos (all Chaos spell)
Tome of Nature (all Nature spell)
Tome of Life (all Life spell)
Tome of Death (all Death spell)
Dwarven Shield (+3 defense to hero, +20% defense for friendly)
Master's Spellbook (third level spell)
Journeyman's Notebook (second level spell)
Aiffe's Mandolin (can cast Song of Peace, Unholy Song and Mass Ferver)
Apprentice's Handbook (first level spell)
Demonary (twice creatures for all demon type summoning spell)
Shield (+3 defense to hero)
Ice Scales (Chaos Ward, Fire resistance and Order spell cost -2)
Breeze the Falcon (+2 scouting radius)
Logbook of the Master Sailor (+25% movement sea, if hero has Seamanship = +20% attack/defense)


This list is reallyyyy tricky!!!

Some item can be very good or totally useless (Demonary, Tome of Order/Death....)

What do you think????

Then, we will need to decide what artifact from this list are given back before weapon with the script (artifact more important than any two hand weapon).

I think the giving script (for left hand and weapon) will look like this:

Give good shield
Give good weapon (because of the Thunder Hammer, Halberd of the swiftwatch, Saint Ranan's Staff)
Give remaining shield (Because I want to give them back before Mayhem Staff....GreatSword)
Give remaining weapon

Where should we seperate the weapon and left hand list?? In my opinion (with the current left hand list), I think I would seperate the list just after Guildmaster's Compendium. So give all previous artifact, then give weapon until I reach Saint Ranan's Staff, then give all other left hand artifact and then all the other weapon.

What do you think??

User avatar
Karmakeld
CH Staff
CH Staff
Posts: 1092
Joined: 12 Nov 2011

Postby Karmakeld » Jun 26 2015, 21:10

I'd Place Dwarven Shield before books, simply because it's beneficial for all troops and has no IF. Wheter it should seperate before Codex, Compendium or Tomes I will let others decide. But I no objections to any of your points, beside the Dwarven Shield.
I'm silent in seven languages - and I got all my familys fear.

Everytime you throw dirt, you loose a little ground

User avatar
iLiVeInAbOx05
Equilibris Team
Equilibris Team
Posts: 577
Joined: 21 Jul 2014

Postby iLiVeInAbOx05 » Jun 26 2015, 21:26

Karmakeld wrote:I don't know how the program can find heroes on a map but I assume it somehow can. Perhaps even the numberof heroes. ILive, in order to rename a script to xxMudgeon, you need to know Mudgeon is placed on the map. Formality, but we need to use numbers instead. The recursive script might be useable with the utility (thx Derrick for reminding us about it :) ).


The map can probably be read like a spread sheet of some sort with certain fields that can be read to determine if the object is a hero, etc. That's the only way I could see this automated tool that can place scripts onto objects making sense :D

If that is the case, then the heroe's name is probably somewhere in the object properties list (which is why I suggested hero name), but I wonder if that's only the case for heroes with custom names? Either way, the program can just have an int, append it to the script name / variables with the tag, and then ++ the int like you mentioned :D

To PatFX: Not to insult your scripting abilities (seems like you've done much more than I have), but this is how I would organize the scripting:

Code: Select all

On hero encountered script (if the hero is Computer):
trigger custom event sort artifacts#heroNum

in sort artifacts#heroNum
{
    trigger custom event count and remove artifacts#heroNum
    trigger custom event add optimal artifacts#heroNum
}

in count and remove artifacts#heroNum
{
    trigger custom event count and remove longsword#heroNum
    trigger custom event count and remove next artifact#heroNum
    //and so on for each artifact
}

in remove longsword#heroNum
{
    if (this hero has a longsword)
    {
        take longsword;
        ++longsword#heroNum;
        trigger custom event remove longsword#heroNum;
    }
}


Then, you can do all that crazy logic in the event add optimal artifacts, remembering to subtract from the variable ie. longsword#heroNum for each artifact added back :D

Code: Select all

Finally, on victory or defeat, trigger custom event restore all artifacts#heroNum
{
    trigger custom event restore longsword#heroNum
    trigger custom event restore next artifact#heroNum
    //and so on for each artifact
}

in restore longsword#heroNum
{
    if (longsword#heroNum > 0)
    {
        give this hero a longsword;
        --longsword#heroNum;
        trigger custom event longsword#heroNum;
    }
}


Some of the scripting can be inlined, but I just like to keep things organized and modular :D

I'm also interested in Karmakeld's concern on the overhead of all this. On my extremely old laptop (it was good in 2004 when I purchased it), I have noticed some slight lag during heavy scripting (adding a large number of units back to an army using the recursive method outlined here). I never noticed any slowdown on my newer PC (which is currently out of commission >.<).

I'd also be interested to know how expensive a script calling another script is (is it a function call, table lookup, inlined?), or maybe if it is something more specific about the way adding or removing creatures / objects is done.

User avatar
GreatEmerald
CH Staff
CH Staff
Posts: 3329
Joined: 24 Jul 2009
Location: Netherlands

Postby GreatEmerald » Jun 26 2015, 22:33

PatFX: I think your list there is good, though I'd put Shield at the very bottom (if the logbook exists, it might be intended to be used in the map, so it ought to be higher than very last; and Ice Scales aren't that bad). Demonary and Apprentice's Handbook could also be lower (Demonary will hardly ever be used, so I'd rank it equal to the Logbook of the Master Sailor).

User avatar
Karmakeld
CH Staff
CH Staff
Posts: 1092
Joined: 12 Nov 2011

Postby Karmakeld » Jun 27 2015, 9:03

ILive.. If you extract text from a map, only custom hero names will appear. If you place the hero named Mudgeon several times on the map, but don't customize his name, only 1 hero will keep the name Mudgeon, while the others will automatically be renamed (portrait remains the same).
Also for obvious reasons we can't extract names of random heroes, there for I see numbers as the solution.
I'm silent in seven languages - and I got all my familys fear.

Everytime you throw dirt, you loose a little ground

User avatar
iLiVeInAbOx05
Equilibris Team
Equilibris Team
Posts: 577
Joined: 21 Jul 2014

Postby iLiVeInAbOx05 » Jun 27 2015, 16:24

Karmakeld wrote:ILive.. If you extract text from a map, only custom hero names will appear. If you place the hero named Mudgeon several times on the map, but don't customize his name, only 1 hero will keep the name Mudgeon, while the others will automatically be renamed (portrait remains the same).
Also for obvious reasons we can't extract names of random heroes, there for I see numbers as the solution.


Yep, appending an int to the script name / variables and incrementing it is definitely the way to go :D

User avatar
PatFX
Peasant
Peasant
Posts: 68
Joined: 05 Mar 2015
Location: Montreal, Canada

Postby PatFX » Jun 30 2015, 15:15

NEW Left hand artifact list:

LEFT HAND
Adamantine Shield (+3 defense to hero, +50% defense for friendly)
Lion's Shield of Courage (+3 defense to hero, +40% defense for friendly)
Death Shield (+3 defense to hero, +30% defense and Life Ward for friendly)
Life Shield (+3 defense to hero, +30% defense and Death Ward for friendly)
Shield of Chaos (+3 defense to hero, +30% defense and Order Ward for friendly)
Shield of Order (+3 defense to hero, +30% defense and Chaos Ward for friendly)
Unnatural Shield (+3 defense to hero, +30% defense and Nature Ward for friendly)
Dragon Scale Shield (+3 defense to hero, +30% defense and Fire resistance for friendly)
Steadfast Shield (+3 defense to hero, +30% defense for friendly)
Dwarven Shield (+3 defense to hero, +20% defense for friendly)
Archmage's Codex (fifth level spell)
Guildmaster's Compendium (fourth level spell)
Tome of Order (all Order spell)
Tome of Chaos (all Chaos spell)
Tome of Nature (all Nature spell)
Tome of Life (all Life spell)
Tome of Death (all Death spell)
Master's Spellbook (third level spell)
Journeyman's Notebook (second level spell)
Aiffe's Mandolin (can cast Song of Peace, Unholy Song and Mass Ferver)
Ice Scales (Chaos Ward, Fire resistance and Order spell cost -2)
Apprentice's Handbook (first level spell)
Demonary (twice creatures for all demon type summoning spell)
Logbook of the Master Sailor (+25% movement sea, if hero has Seamanship = +20% attack/defense)
Shield (+3 defense to hero)
Breeze the Falcon (+2 scouting radius)


I'd Place Dwarven Shield before books, simply because it's beneficial for all troops and has no IF. Wheter it should seperate before Codex, Compendium or Tomes I will let others decide. But I no objections to any of your points, beside the Dwarven Shield.


The Dwarven Shield is not benificial for all troops (Like other shield too). If the troop has 2 heroes (1 Nature and 1 tactic) and the Nature hero has the Dwarven Shield, it's totally useless because the defense of all creatures is modified by the hero with tactic. Because the Dwarven Shield is a Treasure artifact, there is more chance that a hero without tactic get it during the game. That's why I did put the books before. But it's OK to put it before. In the first list that I did, the Dwarven shield was just after the Steadfast Shield. So it's OK with me.

What do you think about this list?

I did have an idea to solve the scroll/parchment problem (the problem is that we will not take/give any scroll/parchment, so if the hero has a scroll/parchment equip, he will never have a shield or any left hand artifact equip for the rest od the game.)

Solution: Put a time event on day1, give a Breeze the Falcon to the hero:

On day1, I will give a Breeze the Falcon, so if the hero find any scroll after, it will be put in the backpack for the rest of the game. And I will put a defeated script: Take Breeze the Falcon. This way, there will be no problem with any scroll/parchment. If the hero find a shield during the game, the artifact script will equip the shield on the next encounter. If the hero has already a scroll/parchment at the beggining of the game (because the mapmaker give it to the hero), the scroll/parchment will be equip for the rest of the game.

....and Breeze the Falcon gives scouting radius, so it's good for the computer at the beggining of the game.

What do you think about it?


To IliveinAbox05:
There is few reasons why I will do the script with method#2:

Method#2:
Hero#1
Triggerable events#1:
Name "LongswordTakeCount1":
conditional action:
if hero has Longsword, then take 1 longsword, set vLongsword to vLongsword +1, trigger custom event named "LongswordTakeCount1"

Then a second Triggerable events:
Hero#1
Triggerable events#2:
Name "LongswordGive1":
conditional action:
if vLongsword > 0, then give 1 Longsword, set vLongsword to vLongsword -1, trigger custom event named "LongswordGive1"

Hero#2
Triggerable events#1:
Name "LongswordTakeCount2":
conditional action:
if hero has Longsword, then take 1 longsword, set vLongsword to vLongsword +1, trigger custom event named "LongswordTakeCount2"

...and...

Triggerable events#2:
Name "LongswordGive2":
conditional action:
if vLongsword > 0, then give 1 Longsword, set vLongsword to vLongsword -1, trigger custom event named "LongswordGive2"

Encounter script hero#1:
trigger custom event named "LongswordTakeCount1
trigger custom event named "GamblerDeckTakeCount1
trigger custom event named "ShieldTakeCount1
....
trigger custom event named "LongswordGive1
trigger custom event named "GamblerDeckGive1
trigger custom event named "ShieldGive1

(give script according to artifact list)


Reason#1: Victory script: I will give back adventure item on the Victorious script (scouting radius, ressources, movement...).

Reason#2: All hero will use the same artifact variable: vLongsword for exemple. So if there is 50 hero on the map and there is approx 200 artifacts. With your way of scripting, there will be 50*200 variable = 10 000 variables for artifact, but with my way, there will be only 200 variable.

Reason#3: Trigger custom event add optimal artifact: With your script, I would need to use an other variable to look if an item was give to the hero for each different slot (shoulder, neck weapon...). For exemple, the hero has Robe of the guardian and Angel feather cloak. I give back Robe of the guardian, then with your script, I need to skip all other shoulder artifact (because you give them back at the end on victorious script/defeat script). To do this, I need a variable and I need to look with a conditionnal action for each shoulder artifact this variable (so 1 conditionnal for each artifact).

Reason#4: victorious/defeated script: With your script, I would need to copy the "restore" event for Victorious AND Defeated script. I would need to do it in both Victoriuos/defeated script to prevent to lose artifact if the troop is defeated. With my script, all artifact are give back on the encounter, so the troop can be victorious or defeated, no more script need, except for few slot for adventure artifact and only on victorious)

Reason#5: Use of trigger event to call script: This is not bad at all, but I would not do it just to reduce as much as I can the number of operation on encounter. The result is the same (your script is more "clean&organized", I mean more easy to read), but my script use 1 less fonction call and 1 less script/hero. (trigger custom event count and remove artifact#heroNum) I would not use this script and put trigger custom event count and remove Longsword#1 (I mean LongswordTakeCount1) directly on the encounter script, except if there is a maximum of line for the encounter script (I am not sure if we can put that many lines of script??). Not a big deal, but I want to optimise the run time for script.

So to resume, I will take all artifact from a hero, then give back all artifact (all on the encounter script) according to the priority list. Then on the victorious script, I will take all ring (Equestrian gloves), boots (remove winged sandals), misc (ressources, scouting radius), neck (necklace of Charm and Statesman's medal) and then give them back to equip adventure object (accoring to an other list). There will be no crazy locic to give optimal artifact, only priority list with maybe few "IF".

User avatar
iLiVeInAbOx05
Equilibris Team
Equilibris Team
Posts: 577
Joined: 21 Jul 2014

Postby iLiVeInAbOx05 » Jun 30 2015, 16:35

PatFX wrote:To IliveinAbox05:

Reason#2: All hero will use the same artifact variable: vLongsword for exemple. So if there is 50 hero on the map and there is approx 200 artifacts. With your way of scripting, there will be 50*200 variable = 10 000 variables for artifact, but with my way, there will be only 200 variable.


If I understand what you're saying here, then that's actually not correct. With the scripting I outlined, ONLY the hero who's encounter script is being called will have HIS triggered scripts run / his variables used. So if the hero has, say, 10 artifacts, then those are the only artifacts that will be counted and removed, followed by your scripting to determine the optimal artifacts to have equipped (which gives them back to the hero who's encounter script is currently running).

PatFX wrote:Reason#3: Trigger custom event add optimal artifact: With your script, I would need to use an other variable to look if an item was give to the hero for each different slot (shoulder, neck weapon...). For exemple, the hero has Robe of the guardian and Angel feather cloak. I give back Robe of the guardian, then with your script, I need to skip all other shoulder artifact (because you give them back at the end on victorious script/defeat script). To do this, I need a variable and I need to look with a conditionnal action for each shoulder artifact this variable (so 1 conditionnal for each artifact).


No, what I was referring to here was the scripting you are doing to determine which artifacts the hero should have equipped. If you just counted and removed all of the heroe's artifacts, then you know exactly what artifacts the hero has (they're stored in the variables specific to the hero, if > 0, hero has that artifact).

If what you mean to do is give artifacts back in the priority order, then you just call a slightly different version of the give artifact script (or just put your set of ifs which will give an artifact back if the variable > 0), which gives only one back if the hero has one, and then exits. After the priority artifacts are returned, you can then return the rest.

Recall that I mentioned you could inline the triggered events to save on script calls. That also applies to the location of the scripts :D (ie. the scripts I listed as being on defeat/victorious could just as easily be used on the encounter script).

PatFX wrote:Reason#4: victorious/defeated script: With your script, I would need to copy the "restore" event for Victorious AND Defeated script. I would need to do it in both Victoriuos/defeated script to prevent to lose artifact if the troop is defeated. With my script, all artifact are give back on the encounter, so the troop can be victorious or defeated, no more script need, except for few slot for adventure artifact and only on victorious)


You would only need to create it once. The tool for placing scripts on the heroes for a map is what needs to know where to put said scripts..

If the scripting is modular as I described, you wouldn't need to copy anything. If you're putting the scripts on yourself, you just trigger the custom event which triggers the rest.

Also also, the triggered events can be put wherever you want (encounter/victorious/defeated) :D

PatFX wrote:Reason#5: Use of trigger event to call script: This is not bad at all, but I would not do it just to reduce as much as I can the number of operation on encounter. The result is the same (your script is more "clean&organized", I mean more easy to read), but my script use 1 less fonction call and 1 less script/hero. (trigger custom event count and remove artifact#heroNum) I would not use this script and put trigger custom event count and remove Longsword#1 (I mean LongswordTakeCount1) directly on the encounter script, except if there is a maximum of line for the encounter script (I am not sure if we can put that many lines of script??). Not a big deal, but I want to optimise the run time for script.


Again, that is what "inline" means. You don't have to use several triggered scripts, you can put them in the main script as I said :D

If there is a maximum number of scripting lines, I haven't run into it yet, and I have some events with a LOT of scripting lines.

Also, one more function call (ie. the call to the triggered script which calls the count and remove scripts), will not make any difference whatsoever on the timing. It's a single function call. The expensive part will be the recursive function calls (if there are many of them), which, unfortunately, can't be gotten around to do what you need to do.

User avatar
PatFX
Peasant
Peasant
Posts: 68
Joined: 05 Mar 2015
Location: Montreal, Canada

Postby PatFX » Jun 30 2015, 21:11

If I understand what you're saying here, then that's actually not correct. With the scripting I outlined, ONLY the hero who's encounter script is being called will have HIS triggered scripts run / his variables used. So if the hero has, say, 10 artifacts, then those are the only artifacts that will be counted and removed, followed by your scripting to determine the optimal artifacts to have equipped (which gives them back to the hero who's encounter script is currently running).


It's not what I'm saying. I only say that I will have 200 variables for artifact and you will have 10000:

My script:
vLongsword, vShield, vXXXXXX..... (same variable for all hero) Why: Because I take/give all artifact on the encounter AND victorious script, so each hero trig his encounter/victorious script in a sequence.

But for your script, you will need 10 000 variable:
vLongsword1 (hero#1), vLongsword2 (Hero#2), vLongsword3 (Her0#3).....
Why: Because you need to know during your Victorious/defeated script what artifact goes on what hero.

I agree that ONLY the hero who's encounter script is being called will have HIS triggered scripts run / his variables used (200 variables), but youre map will have 10 000 variables. Why: Because you want to give back the remaining artifact on the victorious/defeat script, so you need different variables for each hero.

No, what I was referring to here was the scripting you are doing to determine which artifacts the hero should have equipped. If you just counted and removed all of the heroe's artifacts, then you know exactly what artifacts the hero has (they're stored in the variables specific to the hero, if > 0, hero has that artifact).

If what you mean to do is give artifacts back in the priority order, then you just call a slightly different version of the give artifact script (or just put your set of ifs which will give an artifact back if the variable > 0), which gives only one back if the hero has one, and then exits. After the priority artifacts are returned, you can then return the rest.

Recall that I mentioned you could inline the triggered events to save on script calls. That also applies to the location of the scripts smile_teeth (ie. the scripts I listed as being on defeat/victorious could just as easily be used on the encounter script).


When you said "trigger custom events add optimal artifacts#HeroNum", I tought that you want to give back only the optimal artifact for each slot (and give back the rest on victorious/defeat script, that's why you are using different artifact variable name vLongsword1, vLongsword2..., to know what artifact each hero had for your victorious/defeat script)

If you want to do this, then you need to know wich artifact has the highest priority. For exemple:

The hero has 1 Flamming Sword, 2 GiantSlayer and 1 Longsword (so vFlamming = 1, vGiantSlayer = 2 and vLongsword =1). The give script would need to do this :

...
if vFlammingSword >0 and vWeaponOptimal=0, then give 1 Flamming Sword, set vFlammingSword to vFlammingSword-1, set vWeaponOptimal to 1.
if vGiantSlayer >0 and vWeaponOptimal=0, then give 1 GiantSlayer, set vGiantSlayer to vGiantSlayer-1, set vWeaponOptimal to 1.
.....

That's why I said you need a different variable for each different slot (if you want to give ONLY the optimal artifact for each slot).


If the hero has 3 Robe of the guardian, I give back all 3 during the giveback script(the first will be equip and the 2 other will be put in the backpack) and then give all other shoulder artifact. The same is true for other artifact except for ring and misc because those artifact have multiple slot. So I give back let say only 1 Flamming Arrow even if the hero has 3 Flamming Arrow, then give back other misc artifact and then give back the 2 reamining Flamming Arrow.

The srcipt you listed (defeat/victorious) is used on the encounter.


You would only need to create it once. The tool for placing scripts on the heroes for a map is what needs to know where to put said scripts..


You are right for the take/count script for ring, boots, neck and misc (only script that need to run twice: Encounter and Victorious), but the giveback artifact on the victorious scritp that I will use don't use the same priority list that the one on encounter because I give back adventure artifact first. So this is not the same script.

Also also, the triggered events can be put wherever you want (encounter/victorious/defeated)


No, because they are 2 different priority list, 1 for combat (encounter) and 1 for adventure (victorious)

Also, one more function call (ie. the call to the triggered script which calls the count and remove scripts), will not make any difference whatsoever on the timing. It's a single function call. The expensive part will be the recursive function calls (if there are many of them), which, unfortunately, can't be gotten around to do what you need to do.


I agree, that's why I said it was not a big deal (only 1 more fonction call)


The problem with your script was the Victorious/defeated script. This script must be put on encounter because i need a different priority list for adventure. If you put your Victorious/defeated script on encounter, then you dont need a different variable for each artifact/hero. The same vLongsword variable can be use for each hero.

Using a main triggerable event to call other triggerable events is good and more organized. I agree, I should use it (use a triggerable main event) for script TakeCount for Ring, Neck, boots and misc because I need to take/Count all those artifact in the Victorious script too.

Something like this:

encounter:
trig custom event TakeCountArtifactCombat1 (take all Helm, weapon, ranged weapon, armor, left hand artifact)
trig custom event TakeCountArtifactAdventure1 (take all ring, neck, boots and misc artifact)
....
then give back all artifact according to combat priority list:
trig custom event GiveArtifactCombat1 (give all Helm, weapon, ranged weapon, armor, left hand artifact)
trig custom event GiveArtifactAdventureEncounter1 (give all ring, neck, boots and misc artifact)


Victorious:
trig custom event TakeCountArtifactAdventure1 (take all ring, neck, boots and misc artifact = same script as encounter)
....
then give back those artifact according to adventure priority list:
trig custom event GiveArtifactAdventureVictorious1 (give all ring, neck, boots and misc artifact)

Because I need to Take/count ring, neck, boots and misc in the Encounter AND Victorious script, you are right, this part should use a triggerable event.

After few minutes of thinking about it: For the giveback script of ring, neck, boots and misc, I should use the same script too(same modified priority list), but I would need to use a variable to look if I'm on encounter or victorious. Something like:

Victorious script:
set vVictorious =1
trig custom event TakeCountArtifactAdventure1 (take all ring, neck, boots and misc artifact)
trig custom event GiveArtifactAdventure1 (give all ring, neck, boots and misc artifact)
set vVictorious =0

GiveArtifactAdventure1 (Exemple for ring):
If vVictorious =1, then trig custom event EquestrianGloveGive1
.... all other ring artifact with same priority as combat....

A variable vEncounter can be use the same way.

Finally, I think I could use the same give script by using a variable to look if I'm on encounter OR Victorious and put some conditionnal action to change the priority list. That way, i could use the same triggerable event for encounter AND Victorious script. :D

For Boots:
if vEncounter =1, trig custom event WingedSandalsGive1
....then all other boot artifact according to combat list
(so Winged Sandals give first if on encounter)

For Neck:
if vVictorious =1, trig custom event StatemanMedalGive1
if vVictorious =1, trig custom event NeckalceCharmGive1
....then all other neck artifact according to combat list

For Ring:
If vVictorious =1, then trig custom event EquestrianGloveGive1
.... all other ring artifact with same priority as combat....

For misc:
this script will be a little bit more tricky....

OR something even better: Use the same triggerable event for TakeCount AND Give script by using the same variable vEncounter and vVictorious and conditionnal action.
:D

I think it's a little bit more easy to do it the first way I was thinking (method#2, just look at the list and trig custom event in the same sequence), but i would need to do the take/count script for Ring/Neck/Misc/Boots twice (Encounter and Victorious). With the variables vEncounter/vVictorious, it's a little bit more complex to script, but less script to do (more efficient)

User avatar
iLiVeInAbOx05
Equilibris Team
Equilibris Team
Posts: 577
Joined: 21 Jul 2014

Postby iLiVeInAbOx05 » Jul 1 2015, 2:02

PatFX wrote:It's not what I'm saying. I only say that I will have 200 variables for artifact and you will have 10000:

My script:
vLongsword, vShield, vXXXXXX..... (same variable for all hero) Why: Because I take/give all artifact on the encounter AND victorious script, so each hero trig his encounter/victorious script in a sequence.

But for your script, you will need 10 000 variable:
vLongsword1 (hero#1), vLongsword2 (Hero#2), vLongsword3 (Her0#3).....
Why: Because you need to know during your Victorious/defeated script what artifact goes on what hero.


Oh I see what you're talking about now. The way the scripting would be done (only run once during the encounter script for each hero in the battle and zero'd out at the end), you are correct that only one variable for each artifact / item would work fine. Simply update the script outline to remove the #heroNum after the variable names ;) I'm just used to object oriented principles.

So I had a bunch of other stuff written / questions asked, but once I got to the end of your post, most of my questions were answered.

I think the only question I still have is how you're dividing up giving back priority artifacts, followed by the rest, in the same script. Are you just giving back all of each artifact (by calling their individual trigger give scripts) in the priority order?

User avatar
Karmakeld
CH Staff
CH Staff
Posts: 1092
Joined: 12 Nov 2011

Postby Karmakeld » Jul 1 2015, 8:28

A few comments:
Agreed that Using the same variable for ALL heroes, is the most optimal/'cheapest' way of doing things.
But, are you certain that encountered script aren't run simultaneously?
Obviously 4x texts can't be displayed at the same time, but it doesn't necessarily mean we can trust that game can tell the difference between 4 heroes in an army, using the same variable. Has this been tested?

In my opinion, I think the smoothest script would be to gather all artifacts checked for in 1 script, like TakeArtifactCountCombat. It will be a longer script, but the amount of triggered scripts will be reduced to basically 1. Or gather helmets, rings, armours, weapons/shields etc. Now this way, the script will need a final condition to only run again IF hero has 1 or more artifacts left, otherwise the script will run infinitely or cause a crash. (but that basically also applies for TakeLongSword etc) I'm not sure we can check for numbers of artifacts, though. So in that matter it might be easier to check for each artifact one by one.

Anyway what ever script you do, I imagine you'd be able to extract the script using the H4utility, copy/paste it to the other desired places, eg. Victorious/defeated and both be able to rearrange the order (priority list) and change variable names eg. if you want vEncountered -> vVictorious or vGivexx -> vTakexx. That should speed up the scripting process.
I'm silent in seven languages - and I got all my familys fear.

Everytime you throw dirt, you loose a little ground

User avatar
Taro
Scout
Scout
Posts: 163
Joined: 11 Feb 2011
Location: Poland

Postby Taro » Jul 1 2015, 13:25

I have a feeling this "artifact script" will not be applied in the tool. There are too many loopholes, that's the first thing. Second - you can't apply it on every hero. Only on placed heroes but not on heroes bought in a tavern.

User avatar
PatFX
Peasant
Peasant
Posts: 68
Joined: 05 Mar 2015
Location: Montreal, Canada

Postby PatFX » Jul 1 2015, 14:47

Second - you can't apply it on every hero. Only on placed heroes but not on heroes bought in a tavern.


You are right, Hero bought in a tavern won't get that script. It depend on the map. For some map with a lot of hero, this script can be usefull, but for some map with only few hero (and other hero from tavern), this script will be almost useless.

Agreed that Using the same variable for ALL heroes, is the most optimal/'cheapest' way of doing things.
But, are you certain that encountered script aren't run simultaneously?
Obviously 4x texts can't be displayed at the same time, but it doesn't necessarily mean we can trust that game can tell the difference between 4 heroes in an army, using the same variable. Has this been tested?


I'm certain that script don't run simultaneously. I did already test this.

In my opinion, I think the smoothest script would be to gather all artifacts checked for in 1 script, like TakeArtifactCountCombat. It will be a longer script, but the amount of triggered scripts will be reduced to basically 1. Or gather helmets, rings, armours, weapons/shields etc. Now this way, the script will need a final condition to only run again IF hero has 1 or more artifacts left, otherwise the script will run infinitely or cause a crash. (but that basically also applies for TakeLongSword etc) I'm not sure we can check for numbers of artifacts, though. So in that matter it might be easier to check for each artifact one by one.


Do you mean something like this:

TakeArtifactCountCombat:
if hero has Longsword, take longsword and vLongsword++
if hero has Shield, take Shield and vShield++
if hero has Gambler's deck, take Gambler's deck and vGamblerDeck++
.....
if hero has Longsword OR has Shield OR has Gambler's deck OR ..., then trig custom event TakeArtifactCountCombat

The only way to check if the hero has artifact is with 200 OR (each artifact). Not a good idea. Second, if the hero has 10 Ring of Strenght, the loop will run 10 time, and each time, every artifact will need to be check (if hero has artifact), so definitly not the best way to do it..... but if we gather helmets together, then ring, then armor..... maybe it coulb be good. Something like this:

ShoulderTakeCount:
if hero has Robe of the Guardian, then take Robe of the Guardian and vRobeGuardian++
if hero has Mage's Robe, take Mage's Robe and vMageRobe++
..... (same for each shoulder artifact)
if hero has Robe of the Guardian OR has Mage's Robe OR ..., then trig custom event ShoulderTakeCount

This is not a bad idea at all. For the give script, we would need to use "Greater than 0" with "OR" (vRobeGuardian OR vMageRobe...).

....but I think I prefer to check each artifact one by one.


Anyway what ever script you do, I imagine you'd be able to extract the script using the H4utility, copy/paste it to the other desired places, eg. Victorious/defeated and both be able to rearrange the order (priority list) and change variable names eg. if you want vEncountered -> vVictorious or vGivexx -> vTakexx. That should speed up the scripting process.


I will probably put the Victorious script (adventure) in a main triggerable event, so I will need to do the script only once, and use the same script on encounter with some conditional action. The list Encounter and Victorious script for Ring, Neck and Boots are almost the same (only 1 item for ring: Equestrian's Glove, 2 item for Neck: Necklace of Charm and Statsman's Medal, and 2 item for boots), so it will be easy. Only the misc list will be bigger because there is a lot of adventure artifact for this slot. No speed up for scripting process with H4utility. If we want to rearrange the priority order, it will be easy with the Editor because we only need to drag sript in the order list.


I think the only question I still have is how you're dividing up giving back priority artifacts, followed by the rest, in the same script. Are you just giving back all of each artifact (by calling their individual trigger give scripts) in the priority order?


Yes, I simply give back all of each artifact (by calling their individual trigger give scripts) in the priority order, except for Ring* and Misc artifact because those artifact have multiple slot and I don't want to equip 2 Arrow of Slaying. The first item that we give back go on an empty equip slot, then, if there is no empty equip slot, the artifact go in the backpack. If the hero has 3 Flamming Arrow and 3 Gambler's deck, I want the hero to use 1 Flamming Arrow AND 3 Gambler's deck even if the Flamming Arrow has a higher priority. So the script will give back only 1 Flamming Arrow, then give back other misc artifact, then give the remaining misc artifact (the 2 Flamming Arrow and others).

For weapon and left hand artifact, I will need to give back those artifact in a special way because some weapon are two hand, and if a two hand weapon is equip, you then can't equip a shield. So the weapon and left hand list are mixt together.

User avatar
PatFX
Peasant
Peasant
Posts: 68
Joined: 05 Mar 2015
Location: Montreal, Canada

Postby PatFX » Jul 2 2015, 13:41

Complete priority list for artifact script (for each individual slot):

SHOULDER
Robe of the Guardian (first 3 attacks wasted)
Angel Feather Cloak (+10 spell point, Heavenly shield and flight)
Neener’s Invulnerable Cloak (100% MR)
Cape of Protection (if creatures in army, +30% MR to troops, gone if hero is dead)
Mantle of Spell Turning (70% MR)
Cloak of Darkness (+10 defense - Life Ward)
Cowl of Resistance (+50% MR)
Cloak of Warding (+30% MR)
Mage's Robe (spell cost reduced by 1)
Cloak of Distraction. (ignore threat area)

BOOTS
Winged Sandals (+2 combat movement) (if vEncounter = 1)
Wayfarer Boots (+10 spell points, +25% movement bonus, ignores all terrain penalties.)
Boots of Travel (+50% movement)
Boots of the Explorer (ignore all terrain penalties)
Snowshoes (ignore snow terrain)
Fireproof Boots (volcanic terrain)
Boot of the Crocodile (swamp terrain)
Surefooted Boots (rough terrain)
Sandwalker Sandals (sand terrain)
Winged Sandals (+2 combat movement)

HELM
Helm of Command (+20% to all friendly's Melee/Ranged Attack, +20% Melee/Ranged Defense, +1 to their speed)
Supreme Crown of the Magi (+50 spell point, reg. 10 extra/day)
Helm of Power (+20 spell point, 4 extra/day)
Mullich’s Helm of Leadership (+2 morale and +1 speed)
Mind Shield (all friendly immune to mind spells)
Archmage's Hat (+10 spell point, reg. 2 extra/day + Blur)
Circlet of Winsdom (+10 spells point, 2 extra/day)
Tiger Helm (+5 att/def, negate first strike)
Magic Amplifier (-33% spell cost to all friendly)
Crown of Enchantment (cast mind spells on creatures immune to mind spells)
Griffin Helmet (unlimited retal.)
Hideous Mask (gives Hero Fear)
Cap of Knowledge (+5 spell points, 1 extra/day)
Helm of Seeing (all friendly immune to blind)
Seaman’s Hat (no penelty for boarding ships)

NECK
Statesman’s Medal (+10%/basic diplomacy) (if vVictorious = 1)
Necklace of Charm (+5%/basic charm) (if vVictorious = 1)
Necklace of Muses (set) (+15 S.P. and extra 5/day)
Ankh of Life (10% resurrection)
Scarab of Summoning (summon, raise, illusion spells +100%)
Fizbin of Misfortune (misfortune)
Medal of Honor (+2 morale)
Necklace of Balance (set) (increase Order/Chaos spells +25%)
Amulet of Fear (no retaliation)
Mirror of Revenge (Magic Mirror)
Druid’s Chain (+1 lvl. summon/basic summon)
Amulet of the Undertaker (+10 %/basic necromancy)
Statesman’s Medal (+10%/basic diplomacy)
Necklace of Charm (+5%/basic charm)

ARMOR
Adamantine Armor (50)
Tiger Armor (25, +2 Speed and +2 movement)
Breastplate of Regeneration (20, +20 HP and+2HP/level)
Brimstone Breastplate (20, Fire Shield)
Gryphonheart's Plate Mail (30)
Harmonic Chainmail (15, Mirth, so +25% damage and play first)
Dragon Scale Armor (25, Fire Resistance)
Armor of Chaos (20, Order Ward)
Armor of Order (20, Chaos Ward)
Armor of Death (20, Life Ward)
Armor of Life (20, Death Ward)
Unnatural Armor (20, Nature Ward)
Scale Mail of Strength (10, +10 attack)
Elven Chainmail (10)
Leather (5)
Chain Mail (8, -1 movement and +1 casting cost)
Plate Mail (10, -2 movement and +2 casting cost)

RANGED WEAPON
Horned Bow (+50)
Emerald Longbow (+30)
Bow of the elf King (+5, additionnal range attack)
Nomad Blackbow (+20)
Sniper's Crossbow (+3, no penalty)
Spear of the Centaur (+8, no melee penalty)
Valder's Crossbow of Sloth (+5, slow)
War Sling (+10)
Barbarian Throwing Club (+5, stunt)
Throwing Spear (+8)
Crossbow (+3)
Longbow (+5)
David's Sling (friendly ranged creatures +50% to level4 creatures)

RING
Equestrian’s Gloves (+25% movement on land) (if vVictorious = 1)
Warlord’s Ring (friendly +20% attack)
Ring of Protection (friendly +20 defense)
Ring of Speed (+2 speed hero and creatures)
Ring of Flare (+10 spell point and -2 casting cost)
Ring of Health (+50% hit point)
Ring of Regeneration (restore 20 Hit point +2/level)
Ring of the elementals (all summon Elemental twice) (if hero has nature skill)
Ring of Light (+10 attack, increase effect of Life spell and Death Ward)
Wizard’s Ring (+5 spell point and +1/day)
Leprechaun’s Ring (+2 luck)
Ring of Strenght (+5 attack)
Ring of Lesser Negation (hero ignores all Ward)
Ring of the Cobra’s eye ( poison)
Ring of Permanency (friendly immune to Dispel, Cancellation and Steal ench.)
Ring of Greater Negation (immunities and protection are negated for all creatures/heroes)
Ring of the elementals (all summon Elemental twice)
Equestrian’s Gloves (+25% movement on land)

MISC
Flaming Arrow (3*3 yard) (if vEncounter = 1) (give only 1)
Maranthea's Mug (+3 moral) (if vEncounter = 1)
Spider's Silk Arrow (Bind) (if vEncounter = 1) (give only 1)
Arrow of Stunning (if vEncounter = 1) (give only 1)
Poison Arrow (poison) (if vEncounter = 1) (give only 1)
Four Leaf Clover (+1 luck) (if vEncounter = 1)
Gambler's Deck (+1 luck) (if vEncounter = 1)
Horshoes (+1 luck) (if vEncounter = 1)
Arrow of Slaying (Slayer) (if vEncounter = 1) (give only 1)
Crystal of Memory (Immune to Forgetfulness) (if vEncounter = 1) (give only 1)
Crest of Valor (+1 moral) (if vEncounter = 1)
Badge of Courage (immune to fear) (if vEncounter = 1) (give only 1)
Viewing Crystal (+2 scouting radius)
Sack of Gold (750 gold)
Bag of Gold (500 gold)
Purse of Gold (250 gold)
Telescope (+1 scouting radius)
Cart of Lumber (+2 wood)
Cart of Ore (+2 Ore)
Gem Casket (+1 gem)
Flask of Mercury (+1 mercury)
Crystal Figurine (+1 crystal)
Brazier of Sulfur (+1 sulfur)
Sextant (+50% movement over sea)
Purse of Penny Pinching (25% discount)
Flaming Arrow (3*3 yard)
Maranthea's Mug (+3 moral)
Spider's Silk Arrow (Bind)
Arrow of Stunning
Poison Arrow (poison)
Four Leaf Clover (+1 luck)
Gambler's Deck (+1 luck)
Horshoes (+1 luck)
Arrow of Slaying (Slayer)
Crystal of Memory (Immune to Forgetfulness)
Crest of Valor (+1 moral)
Badge of Courage (immune to fear)
Shackles of War (no retreat or surrender)

WEAPON AND LEFTHAND
Adamantine Shield (+3 defense to hero, +50% defense for friendly)
Lion's Shield of Courage (+3 defense to hero, +40% defense for friendly)
Death Shield (+3 defense to hero, +30% defense and Life Ward for friendly)
Life Shield (+3 defense to hero, +30% defense and Death Ward for friendly)
Shield of Chaos (+3 defense to hero, +30% defense and Order Ward for friendly)
Shield of Order (+3 defense to hero, +30% defense and Chaos Ward for friendly)
Unnatural Shield (+3 defense to hero, +30% defense and Nature Ward for friendly)
Dragon Scale Shield (+3 defense to hero, +30% defense and Fire resistance for friendly)
Steadfast Shield (+3 defense to hero, +30% defense for friendly)
Dwarven Shield (+3 defense to hero, +20% defense for friendly)
Sword of the God (+3 attack/defense, +50% friendly)
Axe of Legend (+8 attack, +40% friendly)
True Gryphonheart Blade (+8 attack, +40% friendly)
Crusader’s Mace (+30% friendly)
Angel’s Blade (+3 attack/defense, +50% friendly vs Death) (if opposing troop is Death alignement)
Bull Rune Battleaxe (+50 attack)
Frost Hammer (+25 attack, frost)
Tunder Hammer (+8 attack, 70 damage + 7/level) (two Hand)
Halberd of the Swiftwatch (+25 attack, +2 speed, negate first strike, 2 yard attack) (two Hand)
Flaming Sword (+3 attack/defense, 30 damage + 3/level)
Sword of Swiftness (+6 attack/defense, extra melee attack)
Soul Stealer (+4 attack/defense, heal 1 HP/2 HP of damage)
Saint Ranan’s Staff (double healing, 20% resurrect) (two Hand)
False Gryphonheart Blade (+8 attack/defense)
Archmage's Codex (fifth level spell)
Guildmaster's Compendium (fourth level spell)
Tome of Order (all Order spell)
Tome of Chaos (all Chaos spell)
Tome of Nature (all Nature spell)
Tome of Life (all Life spell)
Tome of Death (all Death spell)
Master's Spellbook (third level spell)
Staff of Disruption (+10 spell point, ignore Ward)
Deadwood Staff (cast Hand of Death Spell) (two Hand)
Staff of Power (reduce all cost by 1/3) (two Hand)
Angel’s Blade (+3 attack/defense, +50% friendly vs Death)
Giant Slayer (+3 attack/defense, double damage to level4)
Longsword (+3 attack/defense)
Journeyman's Notebook (second level spell)
Aiffe's Mandolin (can cast Song of Peace, Unholy Song and Mass Ferver)
Ice Scales (Chaos Ward, Fire resistance and Order spell cost -2)
Apprentice's Handbook (first level spell)
Demonary (twice creatures for all demon type summoning spell)
Logbook of the Master Sailor (+25% movement sea, if hero has Seamanship = +20% attack/defense)
Shield (+3 defense to hero)
Mage's Staff (all spell cost -1) (two Hand)
Mayhem Staff (+50% Chaos direct damage) (two Hand)
Staff of Death (+50% power of death spell) (two Hand)
Staff of Wizardry (reduce 50% Order spell) (two Hand)
Staff of Summoning (reduce 50% cost of summoning) (two Hand)
Dwarven Hammer (+10 attack)
GreatSword (+13 attack) (two Hand)
Wand of illusion
Wand of Healing
Wand of Blesses
Wand of Curse
Wand of Haste
Wand of Animating Dead
Wand of Weakness
Wand of Fireballs
Wand of Fire
Wand of Ice
Axe (+8 attack, -1 speed)
Tyran’s Dagger of Despair (sorrow)
Flame of Chaos (Order Ward, cold resist, -2 Chaos spell casting cost)
Breeze the Falcon (+2 scouting radius)

Can you please check each list. I did few little modifications. We forgot few item (DeadWood Staff, Wand....)

User avatar
Karmakeld
CH Staff
CH Staff
Posts: 1092
Joined: 12 Nov 2011

Postby Karmakeld » Jul 18 2015, 22:00

Simply assuming This is gathered from all prev. lists it should be ok. I only wonder if we did place cloak of darkness that high? Oh well, seems like it's job done...?
I'm silent in seven languages - and I got all my familys fear.

Everytime you throw dirt, you loose a little ground


Return to “Heroes I-IV”

Who is online

Users browsing this forum: No registered users and 1 guest