Jump to content

Franc160th

Community Members
  • Posts

    12
  • Joined

  • Last visited

Posts posted by Franc160th

  1. Well it's not hard, you just have to know a couple of things.

    Here's my topic where I asked the exact same thing https://wildfiregames.com/forum/index.php?/topic/24774-garrison-units-from-the-editor/&tab=comments#comment-361355

     

    Basically you've to "invoke" a trigger script and let it do what you want; in this case I wanted to garrison people, so:

    1- Trigger:

    Trigger.prototype.InitMyMap_GarrisonBuildings = function()

    2- Who do I want to garrison?  I want infantry units, he'll decide which ones; they have to be romans and be Elite:

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

    3- Where and how many people do I want to garrison? I want the 20% of the maximum garrison number in everything that responds to the class of tower; they've to be Roman infantry units, belonging to player 1:

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

     

    Before you do anything, though, you've to tell the game he's to look where the triggers are, in my case in

        "scripts/TriggerHelper.js",
        "skirmishes/Gauls_vs_Romans.js"

    The first one is the reference for triggers in the whole game, the second one is my personal script referred to that particular map

    • Thanks 2
  2. 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
  3. 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

    • Like 1
  4. 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.

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

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

     

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

     

  8. 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 :)

  9. 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?

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

×
×
  • Create New...