Jump to content

Garrison units from the editor


Franc160th
 Share

Recommended Posts

5 minutes ago, Franc160th said:

First of all thanks for your reply, what do you mean with "triggers"?

Triggers are basically a JavaScript script that you add to your map to trigger specific events. For instance you can make units spawn from a specific area, or make the water rise. There is no current way to edit it directly in the editor, so you have to create it manually. Look at other maps to see how it is done.

One thing you can try (I'm absolutely not sure whether it works) is to start the simulation in atlas, make entities garrison walls, and save the map.

 

Link to comment
Share on other sites

4 minutes ago, stanislas69 said:

Triggers are basically a JavaScript script that you add to your map to trigger specific events. For instance you can make units spawn from a specific area, or make the water rise. There is no current way to edit it directly in the editor, so you have to create it manually. Look at other maps to see how it is done.

One thing you can try (I'm absolutely not sure whether it works) is to start the simulation in atlas, make entities garrison walls, and save the map.

 

Ouuh ok, understood, I'll try to make my way through these scripts :)

By the way every kind of help is welcomed :D

Edited by Franc160th
Link to comment
Share on other sites

Quote

    TriggerHelper.SpawnAndGarrisonAtClasses(5, "Tower", TriggerHelper.GetTemplateNamesByClasses("CitizenSoldier+Infantry", "kush", undefined, "Basic", true), 0.6);

This garrisons all towers to 60% capacity with kush Citizen Soldier Infantry units for player 5. Taken from elephantine_trigger_scripts.json.

One can do it without a trigger script too, for example Sicilia Nomad has this:

Quote

  "Garrison": {
    "3434": [3435, 3436, 3437, 3438, 3439, 3440, 3441, 3442, 3443, 3444, 3429, 3430, 3431, 3432, 3433],
    "3445": [3446, 3447, 3448, 3449, 3450, 3451, 3452, 3453, 3454, 3455, 3456, 3457, 3458, 3459, 3460]
  },

But you can see it's quite uncomfortable - one has to place the entities manually and find the entity IDs of these units.

See Gallic Fields for example to see how triggerscript files can be loaded.

  • Like 2
Link to comment
Share on other sites

18 hours ago, elexis said:

This garrisons all towers to 60% capacity with kush Citizen Soldier Infantry units for player 5. Taken from elephantine_trigger_scripts.json.

One can do it without a trigger script too, for example Sicilia Nomad has this:

But you can see it's quite uncomfortable - one has to place the entities manually and find the entity IDs of these units.

See Gallic Fields for example to see how triggerscript files can be loaded.

18 hours ago, elexis said:

TriggerHelper.SpawnAndGarrisonAtClasses(5, "Tower", TriggerHelper.GetTemplateNamesByClasses("CitizenSoldier+Infantry", "kush", undefined, "Basic", true), 0.6); 

 

Ok, but let's assume that I need my kush soldiers of player 5 to get into the towers. Is it enough if I copy that script and paste it in the js console of the editor?

Link to comment
Share on other sites

How should garrisons be handled at mapGen stage if its decided to support this? I have been working with making it possible to set stances. If it can be done in a clean way, I might look into it.

1 hour ago, Franc160th said:

Is it enough if I copy that script and paste it in the js console of the editor?

Not quite, you would need the script in a .js file and change the map xml file to load it. More info can be found here.

Link to comment
Share on other sites

Quote

  "TriggerScripts": [
    "scripts/TriggerHelper.js",
    "skirmishes/Gallic Fields (3).js"
  ],

Above is added to the XML file, taken from Gallic Fields (3).xml.

Below is the triggerscript JS file:

Quote

Trigger.prototype.InitMyMap = function()

{

     TriggerHelper.SpawnAndGarrisonAtClasses(5, "Tower", TriggerHelper.GetTemplateNamesByClasses("CitizenSoldier+Infantry", "kush", undefined, "Basic", true), 0.6); 

};

{
    Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger).RegisterTrigger("OnInitGame", "InitMyMap", { "enabled": true });
}

 

Link to comment
Share on other sites

20 hours ago, (-_-) said:

How should garrisons be handled at mapGen stage if its decided to support this? I have been working with making it possible to set stances. If it can be done in a clean way, I might look into it.

Not quite, you would need the script in a .js file and change the map xml file to load it. More info can be found here.

Ok, I took a look at that page and it was useful, thanks

Quote

  "TriggerScripts": [
    "scripts/TriggerHelper.js",
    "skirmishes/Gallic Fields (3).js"
  ], 

@elexis I added the above lines to my map.xml file, changing the "Gallic Fields (3).js" file with another one, where I added the following lines:

Quote

{
warn("My first trigger script");
    };
        Trigger.prototype.InitMyMap_GarrisonBuildings = function()
{
    let romeInfantryUnits = TriggerHelper.GetTemplateNamesByClasses("CitizenSoldier+Infantry", "rome", undefined, "Elite", true);

    TriggerHelper.SpawnAndGarrisonAtClasses(2, "Tower", romeInfantryUnits, 1);
};

{
    Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger).RegisterTrigger("OnInitGame", "InitMyMap", { "enabled": true });
}

I understood that had to define who "romeInfantryUnits" are and I tried to do so with this as you can see:

Quote

let romeInfantryUnits = TriggerHelper.GetTemplateNamesByClasses("CitizenSoldier+Infantry", "rome", undefined, "Elite", true);

But I still get these errors:

Quote

 

[2000.822] error: JavaScript error: maps/skirmishes/Gauls_vs_Romans.js line 14 (even if there are 13 lines)

[2000.822] error: SyntaxError: illegal character

[2000.822] error:

 

I know that I may seem stupid, but I never used java or any other code and I actually don't know anything about it:rolleyes:, sorry :)

Link to comment
Share on other sites

9 minutes ago, elexis said:

Yeah sounds like an encoding issue. You can also check for JavaScript syntax errors on http://jshint.com/

Also InitMyMap != InitMyMap_GarrisonBuildings

Ok gonna check that out

32 minutes ago, (-_-) said:

Which editor did you use? Editors such as Microsoft Word could mess up a sourcecode file.

I use xed, I'm on linux. I'll download gedit just to see if the editor messes up with the code

 

Link to comment
Share on other sites

For future reference, you can use cat to check if a file (not a good idea for a large file) has any wierd invisible characters. You would just need the -A option IIRC.

cat -A <your trigger script>;

$ indicates a newline, ^I would be tab.

Edited by Guest
Reformat
Link to comment
Share on other sites

4 hours ago, elexis said:

Yeah sounds like an encoding issue. You can also check for JavaScript syntax errors on http://jshint.com/

Also InitMyMap != InitMyMap_GarrisonBuildings 

Ok, I checked those lines in that site and solved about everything, I do not get the error messages and I get the warning I wantend (My first trigger script). There's one last thing: where shall I put this?

Quote

InitMyMap != InitMyMap_GarrisonBuildings 

4 hours ago, (-_-) said:

For future reference, you can use cat to check if a file (not a good idea for a large file) has any wierd invisible characters. You would just need the -A option IIRC.


cat -A <your trigger script>;

$ indicates a newline, ^I would be tab.

Thanks for the tip, didn't know that

 

Link to comment
Share on other sites

7 minutes ago, Franc160th said:

where shall I put this?

In a new .js file in the same directory as where your .xml file is. Convention is to name both files the same. Also dont forget to update the xml files “TriggerScripts” part.

Edit: seems like I misread your post if you meant where to put the qouted statement.

It was merely stating that the two functions are not the same.

Edited by Guest
Link to comment
Share on other sites

3 minutes ago, (-_-) said:

In a new .js file in the same directory as where your .xml file is. Convention is to name both files the same. Also dont forget to update the xml files “TriggerScripts” part.

In my .xml file I put this:

Quote

  "TriggerScripts": [
    "scripts/TriggerHelper.js",
    "skirmishes/Gauls_vs_Romans.js"
  ], 

I should add that line to "Gauls_vs_Romans.js"?

Link to comment
Share on other sites

You defined InitMyMap_GarrisonBuildings but used InitMyMap as the function name while registering the trigger. The last InitMyMap should be changed to InitMyMap_GarrisonBuildings.

Link to comment
Share on other sites

20 minutes ago, (-_-) said:

You defined InitMyMap_GarrisonBuildings but used InitMyMap as the function name while registering the trigger. The last InitMyMap should be changed to InitMyMap_GarrisonBuildings.

Oh yeah you're right. This one shall be good:

Quote

{
  warn("My first trigger script");
    }
         
        Trigger.prototype.InitMyMap_GarrisonBuildings = function()
        
{
    let romeInfantryUnits = TriggerHelper.GetTemplateNamesByClasses("CitizenSoldier+Infantry", "rome", undefined, "Elite", true);
    TriggerHelper.SpawnAndGarrisonAtClasses(2, "Tower", romeInfantryUnits, 1);
};

{
    Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger).RegisterTrigger("OnInitGame", "InitMyMap_GarrisonBuildings", { "enabled": true });
}

 

Yess, it is. I succeded in garrisoning the tower. I now need to garrison tents..I'll let you know.

Edited by Franc160th
Link to comment
Share on other sites

Ok, done. Thank you so much for your support!!

This is my final Gauls_vs_Romans.js:

Quote

{
  warn("My first trigger script");
    }
         
        Trigger.prototype.InitMyMap_GarrisonBuildings = function()
        
{
    let romeInfantryUnits = TriggerHelper.GetTemplateNamesByClasses("CitizenSoldier+Infantry", "rome", undefined, "Elite", true);
    TriggerHelper.SpawnAndGarrisonAtClasses(2, "Tower", romeInfantryUnits, 1);
    TriggerHelper.SpawnAndGarrisonAtClasses(2, "House", romeInfantryUnits, 1);
    TriggerHelper.SpawnAndGarrisonAtClasses(2, "defense_wall_long", romeInfantryUnits, 1);
};


{
    Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger).RegisterTrigger("OnInitGame", "InitMyMap_GarrisonBuildings", { "enabled": true });
}

 

The only problem now is  garrisoning units on the siege wall, but I'll try to solve this problem, which is less important than garrisoning in 80 tents and so many wall towers :D

Edited by Franc160th
  • Like 1
Link to comment
Share on other sites

For future references, it is possible to garrison units without using a trigger script. But I'm guessing that no UI has been implemented. So it would be pretty troublesome to do this by hand for a couple dozen units and buildings. But putting this here just because it is possible.

Basically you would need a Garrison value in the xml file.

"Garrison": {
    "3434": [3435, 3436, 3437, 3438, 3439, 3440, 3441, 3442, 3443, 3444, 3429, 3430, 3431, 3432, 3433],
    "3445": [3446, 3447, 3448, 3449, 3450, 3451, 3452, 3453, 3454, 3455, 3456, 3457, 3458, 3459, 3460]
  },

This is copy pasted from Sicilia Nomad map file. 3434 is the entity which is housing the units. The array contains the entityIDs of all units garrisoned in entity 3434. There are two players who have garrisoned ships, hence two keys.

Link to comment
Share on other sites

2 hours ago, (-_-) said:

For future references, it is possible to garrison units without using a trigger script. But I'm guessing that no UI has been implemented. So it would be pretty troublesome to do this by hand for a couple dozen units and buildings. But putting this here just because it is possible.

Basically you would need a Garrison value in the xml file.


"Garrison": {
    "3434": [3435, 3436, 3437, 3438, 3439, 3440, 3441, 3442, 3443, 3444, 3429, 3430, 3431, 3432, 3433],
    "3445": [3446, 3447, 3448, 3449, 3450, 3451, 3452, 3453, 3454, 3455, 3456, 3457, 3458, 3459, 3460]
  },

This is copy pasted from Sicilia Nomad map file. 3434 is the entity which is housing the units. The array contains the entityIDs of all units garrisoned in entity 3434. There are two players who have garrisoned ships, hence two keys.

said by elexis allready :D

Link to comment
Share on other sites

On 8/31/2018 at 2:38 PM, (-_-) said:

For future references, it is possible to garrison units without using a trigger script. But I'm guessing that no UI has been implemented. So it would be pretty troublesome to do this by hand for a couple dozen units and buildings. But putting this here just because it is possible.

Basically you would need a Garrison value in the xml file.


"Garrison": {
    "3434": [3435, 3436, 3437, 3438, 3439, 3440, 3441, 3442, 3443, 3444, 3429, 3430, 3431, 3432, 3433],
    "3445": [3446, 3447, 3448, 3449, 3450, 3451, 3452, 3453, 3454, 3455, 3456, 3457, 3458, 3459, 3460]
  },

This is copy pasted from Sicilia Nomad map file. 3434 is the entity which is housing the units. The array contains the entityIDs of all units garrisoned in entity 3434. There are two players who have garrisoned ships, hence two keys.

Yeah, but it's actually very unconfortable :D

On 8/31/2018 at 4:58 PM, Angen said:

said by elexis allready :D

ahah yep :)

 

Btw still thank you so much, I did manage to garrison what I needed except for walls, but they're not a big problem

  • Like 1
Link to comment
Share on other sites

  • 4 years later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...