Thread: [Tutorial]Scalable monster health / Player amount detector

Results 1 to 8 of 8
  1. #1
    Administrator Hezus's Avatar  
    Manager
    Join Date
    Aug 2001
    Location
    The Netherlands
    Posts
    9,048

    [Tutorial]Scalable monster health / Player amount detector

    EDIT:
    There's an improved prefab of this system to be found here.




    This tutorial covers how you can trigger certain events in your map according to the amount of players currently on the server. Probable usages are dynamicly opening up new area's to let more monsters in and dynamicly adjusting the health or all monsters to make a map harder or easier. In this tutorial I'll be showing you the latter.

    Before you start:
    This tutorial uses some hidden and advanced entity systems, of which you can learn more here. I'll talk you through the entire process and provide a sample RMF, but some mapping knowledge is required. Read the notes under each step for detailed explanation of certain entities or setups.

    Also, this setup much more powerful than the game_zone_player entity. Game_zone_player only triggers once and only counts the players within the trigger. It can only carry one amount of players so you'd have to make 32 fields to cover it all and then when you have 32 players, it will also fire triggers 1 to 31 since it doesn't recognise =, <= or =>.


    Part 1: Setting up the player counter

    1. Add an info_target to your level and name it 'player_counter'. This entity will keep track of the amount of players. To give it this functionality, we need to add a custom keyvalue. Hit the SmartEdit button and add the key '$i_playercount' with a value of '0'.

    2. Create a trigger_changevalue and name it 'game_playerjoin'. Game_playerjoin is a special targetname which is triggered when a player joins the server. Set the Destination Entity to 'player_counter' and the Destination Key to '$i_playercount'. Source Value should be set to '1' and Action to 'Add'. Joining the server will now add 1 to our player_counter.

    3. Copy and paste the trigger_changevalue and change the name to 'game_playerleave'. Change the Action to 'Sub'. Leaving the server will now subtract 1 from our counter.


    Part 2: Using the counter

    1. We need to add a trigger_condition to constantly read our player_counter. The trigger_condition will need no name. Monitored Entity should be 'player_counter' and Monitored key '$i_playercount'. Set Compare Value (alternative) to 1. Comparator should be set to '== Equal.'. Set Target for True-case to 'playeramount1'. This trigger_condition will fire that output when the requirements are met.

    Note: To test our map on our own, we will keep the value at 1. Ofcourse it would make more sense to add higher numbers later on.

    2. We're going to use our system to alter the health of all monsters on the map. Add a squad_maker and name it 'spawn_zombie'. Set Monster Type to 'monster_zombie' and tag the Start On flag. Click on SmartEdit and add the key '$i_originalhp' and value '100'. This is the default health of the zombie. If you used a different monster, use a different default health.

    Note: We're using squad_makers to change the health because we want the monster to carry the most up-to-date health amount according the the current amount of players. You could use regular monster_zombie entities but the way this system works it will reset the health of the monster. That would look odd to players currently fighting that monster. For that same reason, do not use the Childrens Name key or at least don't use the targetname of the squadmaker (spawn_zombie).

    2. Create a trigger_copyvalue. Name it 'playeramount1'. Set Source Entity to 'spawn_*' and Source key to '$i_originalhp'. Destination Entity should be 'spawn_*' and Destination Key 'health'. Action should be 'Replace'. Set Trigger After Action to 'playeramount1_math'. Tag flag: Multiple Destinations. This will reset the monster health to it's original health.

    Note1: Resetting the health is necessary because we will be multiplying and dividing the health in the next step. If we didn't reset the health and a monster health was previously changed then dividing it again would lead to undisirable results.
    Note2: The asterisk (*) in the name is a wildcard search query. This will look for targetnames matching that prefix, so all squadmakers using the 'spawn_' prefix will be affected by our system. Therefore always call squadmakers by that name: spawn_gargantua, spawn_hgruntsquad, spawn_hugeslimycreaturething.
    Note3: Even though we're only triggering one entity, the copyvalue requires the Multiple Destinations flag to work properly. I guess because of the wildcard this setup uses.

    3. Create a trigger_changevalue and name it 'playeramount1_math'. Destination Entity should be 'spawn_*' and Destination Key 'health'. Set Source Value to 1.25 and Action to Mul (multiply). This will now multiply all monster healths by a factor of 125%. If you want to go lower you can multiply with 0.75 for instance (75% of its original health).

    4. Load up the map and see the zombie spawn with increased health!

    5. To add more conditions, copy and paste the trigger_condition, trigger_copyvalue and trigger_changevalue and change their values to accomendate a condition for 2 players. Use the names 'playeramount2' and playeramount2_math and change the trigger_condition's Compare-value to '2'. You don't necessarily need to add a condition for each amount of players. I'd advice to create conditions in layers, eg. for 2 players, for 4 players, 8 players, 12 players, etc. In the end you'd still have to intensivly test your map to see if the amount of health boost is resonable for that number of players.
    Attached Files Attached Files
    Last edited by Hezus; 08-08-2018 at 05:52 AM.

  2. #2
    Silencer Lt.JC's Avatar  
    Tester
    Join Date
    Dec 2003
    Location
    Germany
    Posts
    1,249

    Re: [Tutorial]Scalable monster health / Player amount detector

    Nice tutorial and very helpful.

    But I got a question: Let's say I'm not a big fan of dynamically changing health or damage values for standard monsters (But for bossfights this would definately be useful ^^), could this system also be used to somehow change the players armor values depending on playercount?

    Like 1-2 players on the server and everyone spawns with 100 armor, 3-4 players and everyone spawns with only 75 armor and so on.

    I'm not sure about this because usually the startarmor value is set within the map.cfg and I don't know if it could be dynamically changed?
    Born to Fight,
    Trained to Kill,
    Taught to Survive,
    and told to take no Prisoners.
    Visit http://www.youtube.com/NostalgicGames

  3. #3
    Administrator Hezus's Avatar  
    Manager
    Join Date
    Aug 2001
    Location
    The Netherlands
    Posts
    9,048

    Re: [Tutorial]Scalable monster health / Player amount detector

    Stuff that is handled in the map's cfg file can't be modified in-game, but there are some key values you can change. I think you can set a targetname on a info_deathmatch_start and then change it's 'health' keyvalue by use of the above system. This way players can have increased or decreased health according to the amount of players on the server.

    There are also 2 keyvalues called 'armortype' and 'armorvalue'. I haven't tested those and the documentation here shows no description of these values, so I'm not sure if they are actually functional. If I have some time later on I'll see if any of these things work.

    Alternatively, you could disable and enable some item_battery's which have been placed in a dark room in which the players first spawn and then get teleported into the real map.

  4. #4
    Silencer Lt.JC's Avatar  
    Tester
    Join Date
    Dec 2003
    Location
    Germany
    Posts
    1,249

    Re: [Tutorial]Scalable monster health / Player amount detector

    Yeah I kinda figured it wouldn't work the way I want but thanks for the info though ^^

    Maybe I test this out if I'm actually mapping something
    Born to Fight,
    Trained to Kill,
    Taught to Survive,
    and told to take no Prisoners.
    Visit http://www.youtube.com/NostalgicGames

  5. #5
    Registered User
    Join Date
    Jan 2016
    Posts
    71

    Re: [Tutorial]Scalable monster health / Player amount detector

    I have been making a map which uses this idea to scale challenge based on number of players. I am using "game_player_counter" entities to detect player number change, and "trigger_changevalue" to change values based on that detection. I am wondering if it is more or less efficient than the method in this tutorial. I am changing the value of a game_counter entity with trigger_changevalue based on the number of players, and use two trigger_changevalue entities for each game_player_counter entity as the minimum and maximum targets.

    The trigger_condition is set to run every 0.1 seconds by default. I am wondering what the default check rate is for game_player_counter, or if it is only triggered when a player joins or leaves where it does not constantly check to see if player number has changed.

    I guess the triggering could be applied more efficiently and with more control using the method in this tutorial depending on circumstances. I am having ideas of triggering multiple values to change based on player number and am curious what is actually more efficient.

  6. #6
    Administrator Hezus's Avatar  
    Manager
    Join Date
    Aug 2001
    Location
    The Netherlands
    Posts
    9,048

    Re: [Tutorial]Scalable monster health / Player amount detector

    Quote Originally Posted by swampdog View Post
    I have been making a map which uses this idea to scale challenge based on number of players. I am using "game_player_counter" entities to detect player number change, and "trigger_changevalue" to change values based on that detection. I am wondering if it is more or less efficient than the method in this tutorial. I am changing the value of a game_counter entity with trigger_changevalue based on the number of players, and use two trigger_changevalue entities for each game_player_counter entity as the minimum and maximum targets.

    The trigger_condition is set to run every 0.1 seconds by default. I am wondering what the default check rate is for game_player_counter, or if it is only triggered when a player joins or leaves where it does not constantly check to see if player number has changed.

    I guess the triggering could be applied more efficiently and with more control using the method in this tutorial depending on circumstances. I am having ideas of triggering multiple values to change based on player number and am curious what is actually more efficient.
    I've asked Sniper and he says that game_player_counter uses the player_leave and player_join outputs to count, so it's not constantly checking the amount of players. So, using game_player_counter would be work pretty well for this purpose. If you use that or my method, you will not notice a difference in perfomance according to Sniper.

    The main reason why I prefer my method is because you actually have the right amount of players stored somewhere. With game_player_counter that value cannot be retrieved and thus gives you less control. Before I wrote this tutorial I actually used the system to show the amount of players on an LCD display. That can not be achieved with game_player_counter. Using my method you could also grab that value and use it in game_text's for instance.

  7. #7
    Registered User
    Join Date
    Jan 2016
    Posts
    71

    Re: [Tutorial]Scalable monster health / Player amount detector

    Ok. Thank you. I also had the idea for a numerical display for the counter. Thanks for sharing. It would be interesting to see an Angelscript emulation of this. It would also be pretty interesting to use this concept in order to increase the number of max live children for squadmakers

  8. #8
    Administrator Hezus's Avatar  
    Manager
    Join Date
    Aug 2001
    Location
    The Netherlands
    Posts
    9,048

    Re: [Tutorial]Scalable monster health / Player amount detector

    Yeah, that would be possible. The key 'm_imaxlivechildren' handles that, so you can trigger_changevalue that.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •