Skip to content

Commit

Permalink
Add Spawn Life/Armor settings for dedicated server
Browse files Browse the repository at this point in the history
  • Loading branch information
rafalh committed Aug 17, 2024
1 parent c82ed3f commit 4cb9306
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ Configuration example:
$DF Vote Previous: true
// Duration of player invulnerability after respawn in ms (default is the same as in stock RF - 1500)
$DF Spawn Protection Duration: 1500
// Initial player life (health) after spawn
$DF Spawn Life: 100
// Initial player armor after spawn
$DF Spawn Armor: 0
// Enable hit-sounds
$DF Hitsounds: true
// Sound used for hit notification
Expand Down
20 changes: 20 additions & 0 deletions game_patch/multi/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ void load_additional_server_config(rf::Parser& parser)
if (parser.parse_optional("$DF Spawn Protection Duration:")) {
g_additional_server_config.spawn_protection_duration_ms = parser.parse_uint();
}

if (parser.parse_optional("$DF Spawn Life:")) {
g_additional_server_config.spawn_life = {parser.parse_float()};
}

if (parser.parse_optional("$DF Spawn Armor:")) {
g_additional_server_config.spawn_armor = {parser.parse_float()};
}

if (parser.parse_optional("$DF Hitsounds:")) {
g_additional_server_config.hit_sounds.enabled = parser.parse_bool();
if (parser.parse_optional("+Sound ID:")) {
Expand Down Expand Up @@ -534,7 +543,18 @@ FunHook<void(rf::Player*)> multi_spawn_player_server_side_hook{
if (!check_player_ac_status(player)) {
return;
}

multi_spawn_player_server_side_hook.call_target(player);

rf::Entity* ep = rf::entity_from_handle(player->entity_handle);
if (ep) {
if (g_additional_server_config.spawn_life) {
ep->life = g_additional_server_config.spawn_life.value();
}
if (g_additional_server_config.spawn_armor) {
ep->armor = g_additional_server_config.spawn_armor.value();
}
}
},
};

Expand Down
2 changes: 2 additions & 0 deletions game_patch/multi/server_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ struct ServerAdditionalConfig
VoteConfig vote_next;
VoteConfig vote_previous;
int spawn_protection_duration_ms = 1500;
std::optional<float> spawn_life;
std::optional<float> spawn_armor;
HitSoundsConfig hit_sounds;
std::map<std::string, std::string> item_replacements;
std::string default_player_weapon;
Expand Down

0 comments on commit 4cb9306

Please sign in to comment.