1. Hey Guest, is it this your first time on the forums?

    Visit the Beginner's Box

    Introduce yourself, read some of the ins and outs of the community, access to useful links and information.

    Dismiss Notice

HOW TO automatically spawn blobs (rooms, boulders, lanterns, zombies, etc.) per Map

Discussion in 'Modding [KAG Classic]' started by Strathos, Dec 12, 2012.

  1. Strathos

    Strathos KAG Guard Tester

    Messages:
    198
    Create an empty text file for each map. Change its extension to ".gm".
    Edit the gm file:
    Code:
    LoadMap( "Maps/Map.png" );
     
    addblob(); 
    On mapcycle.cfg, reference to the gm files instead of pngs: mapcycle = Maps/Map1.gm; Maps/Map2.gm; Maps/Map3.gm;

    Blobs usage
    X = horizontal tile coordinate starting from left; Y = vertical tile coordinate starting from top; Team can be 0(blue), 1(red), 3(neutral); Class can be 0, 1, 2.

    Lanterns: addBlob(`genericitem`, `Entities/Items/Lantern.cfg`, X*8 , Y*8, Team);

    Boulders: addBlob(`boulder`, `Entities/Items/Boulder.cfg`, X*8, Y*8, Team );

    Zombies: addBlob(`zombie`, `Entities/Actors/Skeleton.cfg`, X*8, Y*8, Team );

    Rooms: addBlob(`room`, `Entities/Rooms/Tunnel.cfg`, X*8, Y*8, Team );
    (there has to be 1 room.cfg per room and be sure to select which room you want to spawn at u8_default_room)

    Kegs: addBlob(`keg`, `Entities/Items/Keg.cfg`, X*8, Y*8, Team );

    Crates: addBlob(`genericblock`, `Entities/Items/Crate.cfg`, X*8, Y*8, Team );
    (crates can be stacked)

    Other useful stuff:
    Bots: addBotX(Team, Class, `Name`);
    Water: waterLevel( tiles height from bottom );

    You can also run loops and other logic stuff. More info.

    Edit:
    Entity spawner. It's a simple code that spawns a number of entities on random positions in a defined space (a box).
    Code:
    global spawner = function(x, y, width, height, type, cfg, number, team){
        print( number, cfg, "for team", team, "coords: (", x, ",", y, ")");
        for ( i = 1; i <= number; i = i  + 1){
            rX = randint(x, x + width + 1);
            rY = randint(y, y + height + 1);
            addBlob(type, `Entities/` + cfg, rX*8 + 4, rY*8 + 4 , team);
            sleep( 0.1 );
        }
    };
    How to use
    Copy paste the code at the top of your gm script. If you want it to be accessible through multiple maps, you can just paste it in autostart.gm.
    Then call the function from inside your map.gm:
    Code:
    spawner(top left x coordinate, top left Y coordinate, box width, box height, "entity type", "cfg file of actor starting from entities folder", number of entities to spawn, team number);
    
    for example
    spawner(15, 120, 45, 10, "zombie", "Actors/Skeleton.cfg", 20, 1);
    This will spawn 20 Skeletons randomly in a 45 tiles wide and 10 tiles high "box" placed on the coordinates (tiles) x = 15, y = 120)
    This can be used with the console ingame: \rcon spawner(15, 120, 45, 10, "zombie", "Actors/Skeleton.cfg", 20, 1);
     

    Attached Files:

  2. Arcrave

    Arcrave http://tinyurl.com/ArcravesTheme Tester
    1. SharSharShar - [SHARK]

    Messages:
    262
    Interesting, I'll look into this for some "sekrit" surprises on the Action server. I'll probably be bugging you on IRC about it when I wake up.

    Custom Zombie maps maybe?
     
  3. AZ

    AZ Bison Rider

    Messages:
    4
    Thx this helped me a lot!!!! ^_^
     
  4. D0ubl3Tr0ubl3

    D0ubl3Tr0ubl3 Shopkeep Stealer

    Messages:
    282
    Speak in english please.
     
  5. Zer0Striker

    Zer0Striker Shipwright

    Messages:
    139
    You might wanna learn/practice coding KAG a bit if you don't understand this.
     
  6. Strathos

    Strathos KAG Guard Tester

    Messages:
    198
    This can be used to spawn stuff when a map ends. One simple way to do it is using variables and making each map script wait in a loop until the next map script starts.

    on Map1.gm:
    Code:
    global MAP = 1; 
    while ( WORKING == 1 ) {sleep( 0.5 );} // Waits until the previous map script ends
    LoadMap( "Maps/Map1.png" );
     
    global WORKING = 1;
    while ( MAP == 1 )
    {
    sleep( 1 );
    }
    //at this point both map 1 and map 2 scripts will be running concurrently.
    addBlob(`zombie`, `Entities/Actors/ZombieKnight.cfg`, randint(10,70)*8, randint(10,100)*8, 3); //Map ending stuff: spawns a ZombieKnight on a random tile.
    sleep( 10 );
    global WORKING = 0;//makes the next map script continue
    on Map2.gm:
    Code:
    global MAP = 2;
    while ( WORKING == 1 ) {sleep( 0.5 );} // Waits until the previous map script ends
    LoadMap( "Maps/Map2.png" );
     
    global WORKING = 1;
    while ( MAP == 2 )
    {
    sleep( 1 );
    }
    //at this point both map 2 and map 3 script will be running concurrently.
    //addblob(); ...Map ending stuff here
    sleep( 10 );
    global WORKING = 0; //makes the next map script continue 
    And so on.
    Note that this doesn't account for map restarts and admins issuing a next map multiple times in a row.

    If you want to see a live demo, join Beo's Donkey Kong Server : )
     
    Coookie likes this.
  7. Zer0Striker

    Zer0Striker Shipwright

    Messages:
    139
    Thanks I needed this, as zombies were spawning on generated maps when I didn't want them to.
    </br>--- merged: Dec 16, 2012 12:33 AM ---</br>
    Is there a way to load .gm files in-game, like for testing purposes instead of having to add or make a whole mapcycle to load it?
     
    Coookie and VanHuek like this.
  8. Strathos

    Strathos KAG Guard Tester

    Messages:
    198
    You can run a gm script without a dedicated server. An easy way to do it would be to start an offline zombie fortress match, then on console:
    Code:
    LoadMap("Scripts/script.gm");
    (case sensitive)

    Or in a dedicated server:
    Code:
    \rcon LoadMap(`Scripts/script.gm`); 
    (case sensitive)
     
    Coookie likes this.
  9. Downburst

    Downburst Mindblown Global Moderator Forum Moderator Donator Tester

    Messages:
    1,813
    Another useful command:
    serverMessage("message");
     
  10. Zer0Striker

    Zer0Striker Shipwright

    Messages:
    139
    Thank you so much!!! I have been looking for this command for a while now.
     
  11. Coookie

    Coookie Shopkeep Stealer

    Messages:
    81
    How to SUMMON addBlob by an room function? :3
     
  12. Zer0Striker

    Zer0Striker Shipwright

    Messages:
    139
    Are you asking how to spawn a room using the addBlob command? If so, Type /rcon addBlob(`room`,`Entities/Rooms/FullCTF_Room.cfg`,100,100,3);. Replace FullCTF_Room.cfg with the config of your choice.
     
  13. Coookie

    Coookie Shopkeep Stealer

    Messages:
    81
    Woah no!!!
    I want to summon meteorites by a room_function !!!
    Example:
    My .gm script is in Entities/Items/MeteoritesSpawner1.gm

    I tryed to use this method but didn't worked:
    summon; -; Entities/Items/MeteoritesSpawner1.gm; Entities/Items/Sprites/Boulder.png; 0; 16; Summon meteorites!; c50;

    Help meh! :/
    </br>--- merged: Dec 25, 2012 8:12 AM ---</br>
    P.S.: The script:

    serverMessage("Just gonna spawn some meteorites!");
    global NUMS = 0
    global WORK = 1
    global NUMSmax = 21
    for(NUMS = 1; NUMS < NUMSmax; NUMS++){
    addBlob(`keg`, `Entities/Items/Meteorite.cfg`, randint(10, 340)*8, 10*8, 3);
    sleep(0.5)
    }
    serverMessage("I think, I spawned 20 meteorites!");
    global WORK = 0

    If you can help me about this, thanks to accepting me into your clan of modding.
    I'm basicly a LUA pro scripter and C, C ++ begginer scripter.
    I'm using LUA in my cmd.exe files to make C and C++ working scripts.
     
  14. Zer0Striker

    Zer0Striker Shipwright

    Messages:
    139
    I tried using the randint function, but it didn't work for me(Maybe it isn't in the default GameMonkey Library.) Try making a loop to generate random numbers(Not really random, but are in a pattern that doesn't repeat that much). The command to spawn a meteor itself is /rcon addBlob(`keg`,`Entities/Items/Meteorite.cfg`,x*8,y*8,3);
     
  15. Coookie

    Coookie Shopkeep Stealer

    Messages:
    81
    And, how to make the summoning ? (how to start the .gm script via the room function?)
    PS: i do it correct?
     
  16. Zer0Striker

    Zer0Striker Shipwright

    Messages:
    139
    I don't think you can open .gm scripts in room functions, you have to make your own .gm file and open it with mapcycle or LoadMap( "Example.gm" );.
     
  17. GloriousToast

    GloriousToast Haxor Donator

    Messages:
    1,463
    strathos you forgot signs
    Code:
    addSign( 25*8+4, 25*8+16, "cuz signs are too mainstream" );
     
  18. VanHuek

    VanHuek KAG Guard Tester

    Messages:
    751
    Signs don't work on multiplayer.
     
  19. PainGiver

    PainGiver Arsonist

    Messages:
    78
    Trying to figure out how to disable bots in Zombie Fortress, possible to do this with this type of scripting? I used to just black list the bots, but some reason that doesn't work anymore.
     
  20. Zer0Striker

    Zer0Striker Shipwright

    Messages:
    139
    Why would you want to get rid of the bots? Aren't they like your lives in zombie fortress?