From f9ed6ea72156283fcf42f2b28bca3687a0f30d61 Mon Sep 17 00:00:00 2001 From: Lyberta Date: Wed, 23 Aug 2017 01:05:39 +0300 Subject: [PATCH] Player templates: Added weapon dropping. --- player-template-example.cfg | 2 ++ qcsrc/server/playertemplates.qc | 23 +++++++++++++++++++++++ qcsrc/server/playertemplates.qh | 17 +++++++++++++++-- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/player-template-example.cfg b/player-template-example.cfg index 7376364442..b97e846110 100644 --- a/player-template-example.cfg +++ b/player-template-example.cfg @@ -25,6 +25,8 @@ set g_player_template_example_random_start_bullets "default" "How much bullets d set g_player_template_example_random_start_rockets "default" "How much rockets does the player get with random start rocket-based weapon" set g_player_template_example_random_start_cells "default" "How much cells does the player get with random start cell-based weapon" +set g_player_template_example_drop_weapons "default" "Whether the player can drop weapons by throwing them or by dying" + // Item pickup section // Variables in this section define what happens during item pickup. // Player can get health, armor and/or ammo on top of or instead of an item. diff --git a/qcsrc/server/playertemplates.qc b/qcsrc/server/playertemplates.qc index e2de131e74..3ee9f11631 100644 --- a/qcsrc/server/playertemplates.qc +++ b/qcsrc/server/playertemplates.qc @@ -75,6 +75,10 @@ string PlayerTemplate_GetDefaultCvarName(string variable) { return "g_random_start_plasma"; } + case "drop_weapons": + { + return "g_weapon_throwable"; + } case "health_regen_factor": { return "g_balance_health_regen"; @@ -125,6 +129,7 @@ float PlayerTemplate_GetDefaultFloatValue(string variable) case "random_start_rockets": case "random_start_cells": case "random_start_plasma": + case "drop_weapons": case "health_regen_factor": case "health_regen_linear": case "health_rot_factor": @@ -368,6 +373,11 @@ void PlayerTemplate_PlayerSpawn(entity player, string template) } } +bool PlayerTemplate_ForbidThrowCurrentWeapon(string template) +{ + return !PlayerTemplate_GetFloatValue(template, "drop_weapons"); +} + float PlayerTemplate_PlayerRegen(entity player, string template) { if (template == "default") @@ -1077,3 +1087,16 @@ float PlayerTemplate_Damage_Calculate(entity attacker, string attackertemplate, damage /= PlayerTemplate_GetFloatValue(victimtemplate, "defense_scale"); return damage; } + +void PlayerTemplate_PlayerDies(entity player, string template) +{ + if (template == "default") + { + return; + } + if (PlayerTemplate_GetFloatValue(template, "drop_weapons")) + { + return; + } + player.weapons = WEPSET(Null); +} diff --git a/qcsrc/server/playertemplates.qh b/qcsrc/server/playertemplates.qh index 619c1b79fc..71cc62dab9 100644 --- a/qcsrc/server/playertemplates.qh +++ b/qcsrc/server/playertemplates.qh @@ -51,11 +51,16 @@ float PlayerTemplate_GivePlayerItem(entity player, string template, // =========================== Hook handlers ================================= /// \brief Setups the player during spawn according to the given template. -/// \param[in] player Player to setup. +/// \param[in,out] player Player to setup. /// \param[in] template Name of the template. /// \return No return. void PlayerTemplate_PlayerSpawn(entity player, string template); +/// \brief Forbids weapon dropping according to the given template. +/// \param[in] template Name of the template. +/// \return Value to pass to mutator hook. +bool PlayerTemplate_ForbidThrowCurrentWeapon(string template); + /// \brief Regenerates player health according to the given template. /// \param[in] player Player to regenerate. /// \param[in] template Name of the template. @@ -63,7 +68,7 @@ void PlayerTemplate_PlayerSpawn(entity player, string template); float PlayerTemplate_PlayerRegen(entity player, string template); /// \brief Gives player items according to the given template. -/// \param[in] player Player to give items to. +/// \param[in,out] player Player to give items to. /// \param[in] item Item which player has picked up. /// \param[in] template Name of the template. /// \return Enum value to pass to mutator hook. @@ -79,3 +84,11 @@ float PlayerTemplate_ItemTouch(entity player, entity item, string template); /// \return Adjusted damage. float PlayerTemplate_Damage_Calculate(entity attacker, string attackertemplate, entity victim, string victimtemplate, float deathtype, float damage); + +/// \brief Strips the player of their weapons if the player is not allowed to +/// drop them. +/// \param[in,out] player Player to work with. +/// \param[in] template Name of the template. +/// \return No return. +/// \note You must hook with CBC_ORDER_FIRST in order for this to be effective. +void PlayerTemplate_PlayerDies(entity player, string template); -- 2.39.5