player.try_get_weapon
a.k.a. player.get_weaponThis function can be used to access a player's readied or holstered weapon.
When Bungie and 343i use this function, they often manually clear
the object variable they are assigning to before calling the function.
That functionality is automated in this Megalo dialect: calling the
function with the name get_weapon
will compile in an
assignment to no_object before the call, while calling
the function with the name try_get_weapon
will not.
This function returns object. Calling this function without storing its return value in a variable is an error.
Arguments
- which
-
Any one of the following values
- primary
- The weapon that the player is currently using
- secondary
- The weapon that the player has holstered.
Example
-- -- Delete the player's weapon if it is not a Gravity Hammer: -- for each player do global.object[0] = current_player.get_weapon(secondary) if not global.object[0].is_of_type(gravity_hammer) then global.object[0].delete() end global.object[0] = current_player.get_weapon(primary) if not global.object[0].is_of_type(gravity_hammer) then global.object[0].delete() end end