Heroes of Might and Magic Community
visiting hero! Register | Today's Posts | Games | Search! | FAQ/Rules | AvatarList | MemberList | Profile


Age of Heroes Headlines:  
5 Oct 2016: Heroes VII development comes to an end.. - read more
6 Aug 2016: Troubled Heroes VII Expansion Release - read more
26 Apr 2016: Heroes VII XPack - Trial by Fire - Coming out in June! - read more
17 Apr 2016: Global Alternative Creatures MOD for H7 after 1.8 Patch! - read more
7 Mar 2016: Romero launches a Piano Sonata Album Kickstarter! - read more
19 Feb 2016: Heroes 5.5 RC6, Heroes VII patch 1.7 are out! - read more
13 Jan 2016: Horn of the Abyss 1.4 Available for Download! - read more
17 Dec 2015: Heroes 5.5 update, 1.6 out for H7 - read more
23 Nov 2015: H7 1.4 & 1.5 patches Released - read more
31 Oct 2015: First H7 patches are out, End of DoC development - read more
5 Oct 2016: Heroes VII development comes to an end.. - read more
[X] Remove Ads
LOGIN:     Username:     Password:         [ Register ]
HOMM1: info forum | HOMM2: info forum | HOMM3: info mods forum | HOMM4: info CTG forum | HOMM5: info mods forum | MMH6: wiki forum | MMH7: wiki forum
Heroes Community > Heroes 5 - Modders Workshop > Thread: Random Mixed Neutrals on any map
Thread: Random Mixed Neutrals on any map This thread is 2 pages long: 1 2 · «PREV
magnomagus
magnomagus


Admirable
Legendary Hero
modding wizard
posted August 25, 2008 09:00 PM

Very nice work!, but can it also be used for multiplayer maps? Multiplayer maps are mostly constructed with more randomization but I thought it isn't possible to use scripts on multiplayer maps.

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
SimonaK
SimonaK


Promising
Supreme Hero
posted August 26, 2008 06:13 AM

Quote:
I thought it isn't possible to use scripts on multiplayer maps.


En effet, les scripts ne peuvent être utilisés dans les cartes multi-joueurs.


 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
Asheera
Asheera


Honorable
Undefeatable Hero
Elite Assassin
posted August 26, 2008 12:47 PM
Edited by Asheera at 13:16, 26 Aug 2008.

Scripts work in Multiplayer in TotE

EDIT: I'm thinking of creating an "auto" function as well, which will generate neutrals automatically (but also much random - use the first function if you want more "customizable")

The first parameter will still be a table like MapNeutrals with the format:

MapNeutrals =
{
  [1] = {group =  1, x =  5, y = 76, rot =  90},
  [2] = {group =  1, x = 76, y = 90, rot =   0, u=1},
}


However, the other table will be different. It will look something like:

NeutralGroups =
{
  [1] =
  {
    MinPower = 8000,
    MaxPower = 12000,

    CreatureIDs =
    {
      [1] = {1, 2, 3},
      [2] = {4, 5, 6},
    }
  },
}


In the first layer we find the groups, like in the other one (based on tiers, whatever you like)

A group has the following properties:
MinPower the minimum power this neutral will have
MaxPower the maximum power this neutral will have

The function will then choose a random power between these two values and then generate the creatures randomly based on this.

Then we have the CreatureIDs sub-table which contains some lists of creature IDs. The function will pick one of these groups and then generate neutrals in different number of stacks (mixed) with creatures chosen randomly from that group. This is to prevent, for example, Archers mixed with Demons (not very likely - but you can still do it if you want) or 1 Dragon on your Sawmill, etc... (basically, you will limit the random selection of creatures with this)

For example, you may have two lists, one with all "good" creature IDs and the other with all "evil" creature IDs.

EDIT2: I'm very busy these days, so I won't be able to do this function soon.
____________

 Send Instant Message | Send E-Mail | View Profile | PP | Quote Reply | Link
SimonaK
SimonaK


Promising
Supreme Hero
posted August 26, 2008 05:17 PM


Quote:
Scripts work in Multiplayer in TotE




It's excellent if scripts work in multiplayer maps...

One year ago, I asked whether we would use scripts on the multiplayer maps
and the answer which had been given was: impossible to do that


http://forums-fr.ubi.com/eve/forums/a/tpc/f/7501009903/m/2331017506


I admire perseverance.


 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
Seraf
Seraf


Hired Hero
away til august:(
posted August 26, 2008 08:06 PM
Edited by Seraf at 20:07, 26 Aug 2008.

... Maybe I misunderstand something, but what is it made for?
If we want our stacks to be mixed, we can do it manually right in the editor..
Or this places neutrals anywhere on the map absolutely randomly? But then its rather pointless to me..
____________
Kill'em and grill'em!

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
Asheera
Asheera


Honorable
Undefeatable Hero
Elite Assassin
posted August 26, 2008 08:08 PM

Yes you can place them in the editor

But with my method, they will be "random" every time you start the map

I mean, look at the difference between placing some Peasants at your Sawmill and placing a Random Tier 1 Creature object.
____________

 Send Instant Message | Send E-Mail | View Profile | PP | Quote Reply | Link
Asheera
Asheera


Honorable
Undefeatable Hero
Elite Assassin
posted August 26, 2008 11:15 PM
Edited by Asheera at 12:02, 27 Aug 2008.

Ok, I have finished the function

Copy & Paste the following function at the start of the map script:

function CreateCreepsAuto(creeps, creep_groups)
 -- first we need the power table
 local power_table = {41, 72, 140, 199, 201, 287, 524, 716, 1086, 1487, 2185, 2520, 4866, 6153, 75, 124, 101, 150, 259, 370, 511, 694, 1069, 1415, 2102, 2360, 4868, 5850, 54, 84, 105, 150, 232, 327, 518, 739, 1166, 1539, 2204, 2588, 3174, 3905, 100, 169, 191, 311, 309, 433, 635, 846, 1072, 1441, 1717, 1993, 4942, 6028, 63, 105, 113, 172, 243, 357, 498, 643, 839, 1126, 2108, 2535, 4822, 6095, 180, 295, 333, 484, 342, 474, 598, 812, 968, 1324, 2193, 2537, 5234, 6443, 829, 795, 856, 813, 2560, 8576, 70, 115, 115, 171, 304, 419, 318, 434, 932, 1308, 2109, 2477, 4883, 6100, 72, 203, 299, 697, 1523, 2520, 6003, 355, 671, 2523, 1542, 42, 69, 121, 174, 190, 254, 492, 680, 695, 926, 2058, 2571, 4790, 5937, 127, 149, 338, 680, 1434, 2448, 5860, 290, 477, 488, 833, 1333, 2622, 6389, 174, 308, 447, 862, 1457, 2032, 5905, 85, 145, 331, 757, 1541, 2449, 3872, 105, 180, 355, 642, 1096, 2581, 6095, 113, 171, 422, 434, 1329, 2437, 6070, 66, 181, 265, 692, 895, 2572, 5937}

 local additional_stacks = {}
 local x = 1

 -- go through all creeps
 for i, creep in creeps do
   -- get current creep properties
   local creep_name = "CreepAuto_" .. i
   local group = creep_groups[creep.group]
   local power = group.MinPower+random(group.MaxPower-group.MinPower+1)
   local subgroup = group.CreatureIDs[random(length(group.CreatureIDs))+1]
   local numCreatures = length(subgroup)

   -- define number of stacks (max three) and the creatures' power divided between them
   local c1 = random(numCreatures)+1
   local c2 = 0
   local c3 = 0
   local c1_amount = 15+random(86)
   local c2_amount
   local c3_amount

   if c1_amount > 85 then
     c1_amount = 100
   else
     c2 = random(numCreatures-1)+1
     if c2 >= c1 then c2 = c2 + 1 end

     c2_amount = 15+random(86-c1_amount)
     if c1_amount + c2_amount > 85 then
       c2_amount = 100 - c1_amount
     else
       c3 = random(numCreatures-2)+1
       if c3 >= c1 then c3 = c3 + 1 end
       if c3 >= c2 then c3 = c3 + 1 end

       c3_amount = 100 - c1_amount - c2_amount
     end
   end

   -- convert the list IDs to creature IDs
   c1 = subgroup[c1]

   -- create the monster on the map with the first stack
   CreateMonster(creep_name, c1, ceil(((c1_amount * power) * 0.01) / power_table[c1]), creep.x, creep.y, creep.u or 0, creep.mood or 1, creep.courage or 2, creep.rot)

   if c2 > 0 then
     c2 = subgroup[c2]
     additional_stacks[x] = {Name = creep_name, Id = c2, Num = ceil(((c2_amount * power) * 0.01) / power_table[c2])}
     x = x + 1

     if c3 > 0 then
       c3 = subgroup[c3]
       additional_stacks[x] = {Name = creep_name, Id = c3, Num = ceil(((c3_amount * power) * 0.01) / power_table[c3])}
       x = x + 1
     end
   end
 end

 -- pause the script so the engine can place the neutrals on the map
 sleep(2)

 -- add additional stacks (NOTE: only the first stack's size is adjusted by the difficulty of the game, we need to do it here manually)
 x = GetDifficulty(); local y = 1.0
 if     x == 0 then y = 0.75
 elseif x == 2 then y = 1.15
 elseif x == 3 then y = 1.35
 end

 for i, v in additional_stacks do
   AddObjectCreatures(v.Name, v.Id, v.Num*y)
 end
end





This function will be used to create random neutrals on the map, with the possibility to be mixed as well. Note that it generates a neutral monster with either 1, 2 or 3 stacks, chosen randomly. (yes, only three stacks maximum for now)



How to use the function
First of all, you'll need to know the Creature IDs. They are found in the "HOMM5_A2_IDs_for_Scripts.pdf" file located in the Editor Documentation folder which is located where you installed TotE.


The first step is to place the Map Neutrals. I already explained how to do this in this thread. The table should look something like this:

MapNeutrals =
{
 [1] = {group =  1, x =  5, y = 76, rot =  90},
 [2] = {group =  1, x = 76, y = 90, rot =   0, u=1},
}





Now, we'll have to create the table holding the neutral groups. Here's an example (don't let it overwhelm you, I'll explain)

NeutralGroups =
{
 [1] =
 {
   MinPower = 2000,
   MaxPower = 2600,

   CreatureIDs =
   {
     [1] = {1, 2, 106, 3, 4, 107},
     [2] = {15, 16, 131, 17, 18, 132},
   }
 },
 [2] =
 {
   MinPower = 3000,
   MaxPower = 4000,

   CreatureIDs =
   {
     [1] = {1, 2, 106, 3, 4, 107, 5, 6, 108},
     [2] = {15, 16, 131, 17, 18, 132, 19, 20, 133},
   }
 },
 [3] =
 {
   MinPower = 4200,
   MaxPower = 5500,

   CreatureIDs =
   {
     [1] = {2, 106, 3, 4, 107, 5, 6, 108, 7, 8, 109},
     [2] = {16, 131, 17, 18, 132, 19, 20, 133, 21, 22, 134},
   }
 },
 [4] =
 {
   MinPower = 6500,
   MaxPower = 8800,

   CreatureIDs =
   {
     [1] = {2, 106, 3, 4, 107, 5, 6, 108, 7, 8, 109, 9, 10, 110},
     [2] = {17, 18, 132, 19, 20, 133, 21, 22, 134, 23, 24, 135},
   }
 },
 [5] =
 {
   MinPower = 10000,
   MaxPower = 13000,

   CreatureIDs =
   {
     [1] = {9, 10, 110, 11, 12, 111},
     [2] = {23, 24, 135, 25, 26, 136},
   }
 },
 [6] =
 {
   MinPower = 15000,
   MaxPower = 20000,

   CreatureIDs =
   {
     [1] = {9, 10, 110, 11, 12, 111, 13, 14, 112},
     [2] = {23, 24, 135, 25, 26, 136, 27, 28, 137},
   }
 },
 [7] =
 {
   MinPower = 25000,
   MaxPower = 33000,

   CreatureIDs =
   {
     [1] = {9, 10, 110, 11, 12, 111, 13, 14, 112},
     [2] = {23, 24, 135, 25, 26, 136, 27, 28, 137},
   }
 },
}


As you see, the NeutralGroups table contains a list of groups. Let's analyze group 1:

 [1] =
 {
   MinPower = 2000,
   MaxPower = 2600,

   CreatureIDs =
   {
     [1] = {1, 2, 106, 3, 4, 107},
     [2] = {15, 16, 131, 17, 18, 132},
   }
 },


A group contains the following properties:

MinPower and MaxPower are used to describe the neutral's power (it's measured in creature power values - you can check these in the Fan Manual). The function will pick a random number between these two values and use it to generate the neutrals as close to that power as possible.

CreatureIDs is a list of neutral "teams". The function will only choose and mix neutrals from only one team (randomly chosen for each neutral on the map). This is useful, for example, if you don't want to mix "good" and "evil" races together (you can create two teams: one holding all good creature IDs, while the other all the evil creature IDs). This is also used to filter some creatures for some groups if you want (for example, you don't want Peasants (in very large numbers) to be possible to spawn at a tier 7 neutral). Moreover, you can create only one team with all the neutrals and it will be purely random and chaos in creature selection. Or one team with only some creatures (for example, the Haven ones) so that the monster will only spawn between those creatures.

NOTE: In a team there must be at least THREE creature IDs, otherwise the script may fail at times!

Let's analyze the above example (group 1). It generates neutrals with a power between 2000 and 2600, chosen randomly. The creatures that are available to spawn and mix are either:
1) Peasants, Conscripts, Brutes, Archers, Marksmen and Crossbowmen
or
2) Imps, Familiars, Vermin, Horned Demons, Horned Overseers and Horned Grunts

I hope it's clear enough.




And finally, call the function and pass the above tables as parameters:

CreateCreepsAuto(MapNeutrals, NeutralGroups)






IMPORTANT
I have updated the function and fixed a bug. Please re-copy and paste it if you have already done so before.
____________

 Send Instant Message | Send E-Mail | View Profile | PP | Quote Reply | Link
Zenithale
Zenithale


Promising
Famous Hero
Zen Mind
posted August 28, 2008 10:55 PM

Well, I tried your script, but I don't know where is the "scripts" folder:
Quote:
First, add this piece of code to "scripts/common.lua" file (my creation)

If I understand correctly I should change this "common.lua" file and then create a MapScript file (which will be linked to the map).
Thanks in advance.
____________
TWITCH|YouTube | NewArenas2023 MOD

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
Asheera
Asheera


Honorable
Undefeatable Hero
Elite Assassin
posted August 29, 2008 12:26 PM

Quote:
If I understand correctly I should change this "common.lua" file and then create a MapScript file (which will be linked to the map).
Thanks in advance.
Actually forget about that "common.lua" file, it's a little complicated for nothing.

Just Paste the function in the beginning of the Map Script and then add those tables to generate neutrals (in the same map script) and finally call the function.

Also, I wrote a small "tutorial" for the second function here

PS: I hope you know how to add a map script, no?
____________

 Send Instant Message | Send E-Mail | View Profile | PP | Quote Reply | Link
Zenithale
Zenithale


Promising
Famous Hero
Zen Mind
posted August 29, 2008 07:13 PM
Edited by Zenithale at 19:18, 29 Aug 2008.

Thanks.
Quote:
PS: I hope you know how to add a map script, no?

A map script? It's my first time...

Well I tried several times but it doesn't work. I used this files:
MapScript.xdb
MapScript.lua
(Maybe should I add 3 ',' in MapScript.lua after the 3th 'end', after 'MapNeutrals{...}' and after 'NeutralGroups = [1] = {...} },}' ?)
With the map link: Script:Maps\Multiplayer\test Chaotic Fiesta\MapScript
____________
TWITCH|YouTube | NewArenas2023 MOD

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
Asheera
Asheera


Honorable
Undefeatable Hero
Elite Assassin
posted August 29, 2008 07:21 PM
Edited by Asheera at 19:34, 29 Aug 2008.

1) Are you sure those files are in the Map's folder?

2) Try to rename the map to be without "spaces" (for example "test_Chaotic_Fiesta"

EDIT: There's a bug with your Script
Under
NeutralGroups =

you should have an {

Like this:

NeutralGroups =
{
[1] = ...


EDIT2: There's another bug. After MapNeutrals you should have a "=".

Like this:

MapNeutrals =
{



I tested a map with your fixed script (see above fixes) and it worked perfectly fine
____________

 Send Instant Message | Send E-Mail | View Profile | PP | Quote Reply | Link
Zenithale
Zenithale


Promising
Famous Hero
Zen Mind
posted August 29, 2008 11:47 PM

Quote:
1) Are you sure those files are in the Map's folder?


Of course.

It works perfectly now, thanks!
____________
TWITCH|YouTube | NewArenas2023 MOD

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
Zenithale
Zenithale


Promising
Famous Hero
Zen Mind
posted February 25, 2010 06:16 PM
Edited by Zenithale at 18:17, 25 Feb 2010.

I finished a new map with this script and I found a bug, which created very big stacks (500 Phoenixs for exemple) ! In fact the Phoenix ID is 91, and there is NO creature with ID 90 in the game. Thus when the function create the monsters, ALL creatures after the Phoenix (and itself) use the Power of the next creature in the ID list (Phoenix Power becomes that of the Defender (ID 92) etc...).

I added a number to correct the issue (the value has no importance since there is no creature n°90).

local power_table = {41, 72, 140, 199, 201, 287, 524, 716, 1086, 1487, 2185, 2520, 4866, 6153, 75, 124, 101, 150, 259, 370, 511, 694, 1069, 1415, 2102, 2360, 4868, 5850, 54, 84, 105, 150, 232, 327, 518, 739, 1166, 1539, 2204, 2588, 3174, 3905, 100, 169, 191, 311, 309, 433, 635, 846, 1072, 1441, 1717, 1993, 4942, 6028, 63, 105, 113, 172, 243, 357, 498, 643, 839, 1126, 2108, 2535, 4822, 6095, 180, 295, 333, 484, 342, 474, 598, 812, 968, 1324, 2193, 2537, 5234, 6443, 829, 795, 856, 813, 2560, 1 (added), 8576 (Phoenix), 70 (Defender), 115, 115, 171, 304, 419, 318, 434, 932, 1308, 2109, 2477, 4883, 6100, 72, 203, 299, 697, 1523, 2520, 6003, 355, 671, 2523, 1542, 42, 69, 121, 174, 190, 254, 492, 680, 695, 926, 2058, 2571, 4790, 5937, 127, 149, 338, 680, 1434, 2448, 5860, 290, 477, 488, 833, 1333, 2622, 6389, 174, 308, 447, 862, 1457, 2032, 5905, 85, 145, 331, 757, 1541, 2449, 3872, 105, 180, 355, 642, 1096, 2581, 6095, 113, 171, 422, 434, 1329, 2437, 6070, 66, 181, 265, 692, 895, 2572, 5937}

____________
TWITCH|YouTube | NewArenas2023 MOD

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
Jump To: « Prev Thread . . . Next Thread » This thread is 2 pages long: 1 2 · «PREV
Post New Poll    Post New Topic    Post New Reply

Page compiled in 0.0779 seconds