Thread: [Entities] Lives

Results 1 to 2 of 2
  1. #1
    Craazy! the-middleman's Avatar  
    Artist
    Join Date
    Sep 2012
    Location
    Entity-Guide
    Posts
    514

    Standard Crate [Entities] Lives

    A lives system in your maps makes it so that players can not respawn after they died. In this tutorial I will show two ways of accomplishing this.

    The spectator room
    SC has no spectatormode. So the only thing you can do with dead players, is put them in a seperate room which I call the spectator room. If this is just a boring rectangular room then people will hate your map and leave the server. You should provide some possibility to observe the players who are still alive. Like trigger_cameras or a window to the map. The best would be to actually create a proper spectator-mode, like I did in lmsbath. However, that is complicated and will not be explained in this tutorial. You can of course also put other interesting minigames, or music in the specroom.

    Long story short: Give the spectators something to do or your map will be a failure.

    Method A: Deactivate respawn after one minute
    This method is really simple. After one minute you deactivate all info_player_start in your map and activate those in your spectatorroom.

    Pros:
    - Really simple
    - All players start at the same time
    - Can not be cheated

    Cons:
    - Players who join the game later (e.g. they were downloading the map) will have to spectate instantly, without a chance to play the map.
    - Every player has only one life

    Also the game will not end if all players are dead. So you must figure out some mechanism to end the map if everyone is in the specator room. The game_zone_player might be an idea.

    Method B: Individual lives using custom keyvalues

    Using custom keyvalues we can give each player his own lives. In the following example we will give each player 3 lives which means after the third death he will go to the spectator room. Note that for technical reasons we do not count lives but the respawns of each player. If a player dies but is then revived by another player, we do not want to count that as a life lost. Keep in mind that the first spawn when you join the server also counts as a respawn.
    The first part is really simple. After people died three times we send them to the specroom. We just need 3 entities:

    trigger_changevalue
    Name: game_playerspawn
    Destination entity: !activator
    Destination key: $i_respawns
    Source value: 1
    Action: Add
    Trigger after action: spec_condi
    This entity will increase a player´s $i_respawns everytime he respawns.

    trigger_condition
    Name: spec_condi
    Monitored entity: !activator
    Monitored key: $i_respawns
    Compare value: 4
    Comparator: >=
    Target for true case: goto_specroom
    Flags
    Cyclyc [x]
    Keep !activator [x]
    This entity will check a player´s $i_respawns and if that is greater or equal 4 it will send him to the specroom. Because 4 respawns is too much. That noob!

    trigger_changevalue
    Name: goto_specroom
    Destination entity: !activator
    Destination key: origin
    Source value: -352 104 -150
    Action: Replace
    Trigger after action: gameover_iter_relay
    This will teleport the player to the specroom. -352 104 -150 are the coordinates of the specroom in my map. You will have to adjust that for your map of course. Also when the first player goes to the specroom gameover_iter_relay will be triggered so now the map starts checking if any players are still alive.


    That was really simple. Now all players go to the specroom after they died three times. But to make the game end if all players are dead we need more entities:

    trigger_relay
    Name: gameover_iter_relay
    Target: gameover_iter
    Trigger state: On
    Flags
    Remove on fire [x]
    This activates gameover_iter when the first player has died three times.

    trigger_entity_iterator
    Name: gameover_iter
    Filter Entities by Classname: player
    Delay between Entities: 0.1
    Entity´s Trigger Target: count_players_condi
    Entity´s Trigger State: On
    Run mode: Toggle On/Off
    Trigger at end of each run: check_if_all_dead
    Delay before restarting: 5
    This entity goes through all the players and makes them trigger count_players_condi, then it fires check_if_all_dead. It repeats this process every 5 seconds.

    trigger_condition
    Name: count_players_condi
    Monitored entity: !activator
    Monitored key: $i_respawns
    Compare value: 4
    Comparator: >=
    Target for true case: count_dead_players
    Target for false case: count_total_players
    Flags
    Cyclyc [x]
    Keep !activator [x]
    This entity will check whether a player respawned 4 or more times. If so it will count him as a dead player. Otherwise it will add him to the total number of players.

    trigger_changevalue
    Name: count_dead_players
    Destination entity: gameover_iter
    Destination key: $i_deadplayers
    Source value: 1
    Action: Add
    Trigger after action: count_total_players
    This will count one dead player. We are storing that information as a custom keyvalue $i_deadplayers on the entity gameover_iter. We could store it on any other entity but who cares. After doing that we also trigger count_total_players because dead players are players after all.

    trigger_changevalue
    Name: count_total_players
    Destination entity: gameover_iter
    Destination key: $i_totalplayers
    Source value: 1
    Action: Add
    This counts the total number of players.

    trigger_condition
    Name: check_if_all_dead
    Monitored entity: gameover_iter
    Monitored key: $i_deadplayers
    Compare-entity: gameover_iter
    Compare-key: $i_totalplayers
    Comparator: ==
    Target for true case: all_dead
    Target for false case: reset_dead_count
    Flags
    Cyclyc [x]
    Keep !activator [x]
    This entity will check if $i_deadplayers is equal to $i_totalplayers. And if that is true then it will trigger all_dead. all_dead is an entity of your choice to end the map because the players all failed miserably. Otherwise it will trigger reset_dead_count.

    trigger_changevalue
    Name: reset_dead_count
    Destination entity: gameover_iter
    Destination key: $i_deadplayers
    Source value: 0
    Action: Replace
    Trigger after action: reset_total_count
    This resets the $i_deadplayers to 0 because in five seconds we want to check again, whether all players are dead or not.

    trigger_changevalue
    Name: reset_total_count
    Destination entity: gameover_iter
    Destination key: $i_totalplayers
    Source value: 0
    Action: Replace
    This does the same for $i_totalplayers.


    There you have it. Now all players can only spawn/respawn three times and if all players have used up all their lives the game will end. Of course you can easily change the number of lives per player. There are only two trigger_conditions where you need to change the Compare value.

    Pros:
    - Multiple lives per player
    - Game ends automatically when all players are dead

    Cons:
    - A little complicated for beginner mappers.
    - I did not test this with multiple players. It should work though.
    - Players can cheat on this system.

    About that last point: There are two ways how players can cheat on this map:
    One way is by simply rejoining the server. In this case your $i_respawns will be reset to 0. There is no real way to prevent this. Theoretically you could create an entitysystem that writes down the names of dead players and prevents them from using this trick. But then players could just rename themselves and the system would be broken again. Another solution would be, not to allow new players joining, like five minutes after the map has started. So you can stop the cheating at least a little.
    Another way how people could break this map is by not respawning after they have been killed. On a normal server you must press a button to respawn. If you dont touch any key your dead body will just lie there and the $i_respawns will not increase. One way to prevent this would be to put forcerespawn 1 into the maps cfg-file.


    Thats all folks! Let me know if you have questions or find errors.
    ZN progress:

  2. #2
    Mapper Nih's Avatar  
    Manager
    Join Date
    Dec 2002
    Location
    Denmark
    Posts
    5,484

    Re: [Entities] Lives

    I didn't read it all, but this is a nice thing to have a tutorial for. Nice work. The multiple lives thing looks perhaps a bit too exploitable though.

Posting Permissions

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