]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Player templates: Added weapon dropping.
authorLyberta <lyberta@lyberta.net>
Tue, 22 Aug 2017 22:05:39 +0000 (01:05 +0300)
committerLyberta <lyberta@lyberta.net>
Tue, 22 Aug 2017 22:05:39 +0000 (01:05 +0300)
player-template-example.cfg
qcsrc/server/playertemplates.qc
qcsrc/server/playertemplates.qh

index 73763644422764ff6f35d5f280e0642743aaab9d..b97e846110f61b8103d1e026f8a42e5e7a554275 100644 (file)
@@ -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.
index e2de131e74f4c2402dbf8e129c8176e30e7b0273..3ee9f1163176f371c04eb24bf358ac49be0ed629 100644 (file)
@@ -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);
+}
index 619c1b79fc8fdfe21bc665bf23330aa12da31660..71cc62dab9b7e8d565f90ce0a803a60af41168d9 100644 (file)
@@ -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);