Closed Kefta closed 4 years ago
Bumping to ping @robotboy655 to fullfil the request, but also to point out that just binding Weapon_Equip itself is a lil bit unsafe, it doesn't have the necessary checks that BumpWeapon does to check for duplicate weapon and the sort.
So in my opinion, if these were bound to Lua, they should have the checks inside of the Lua binds themselves.
And of course preventing shit like equipping a weapon that someone is still holding and etc.
The checks should probably just go in Weapon_Equip itself for safety.
Added NPC:DropWeapon and its arguments as well as backported the arguments to the player DropWeapon functions.
The workaround described in https://github.com/Facepunch/garrysmod-issues/issues/4049 wouldn't work in our scenario because of the GM:PlayerCanPickupWeapon
, which is called automatically for the weapons that are in a defined range. If you wanna (like we do) pick up a weapon out of this range (e.g. while looking at them), this is not a valid "solution". I thought about a workaround (teleporting this weapon to the player, ...), but any way seems to be ugly / provisionally. The only way currently is to decrease the range :/
For anyone interested, we've implemented our pickup in a really hacky way, since robotboy said we have to use the GM:PlayerCanPickupWeapon
hook.
First, there is the problem that the hook only tries to pickup entities in a really small area, our pickup systems works in a bigger radius. Therefore we teleport the weapons to the playerposition. But since teleporting weapons to the feet can glitch them in the ground / in ground near entities, we had to teleport them to chest height.
This created another problem: Our pickupsystem features an autodrop to fastswitch weapons. To minimize the collisions the physics of the weapon that is picked up is disabled. Also it is rendered transparently to eliminate the problem that there is a weapon in your face.
Additionally we added a feature to disable autopickup. All these problems created a really big system that is quite hacky but robust. It supports addons that return false in the PlayerCanPickupWeapon
hook, supports autopickup, supports direct weapon switch and much more. All of it is wrapped in a PLAYER:PickupWeapon(wep)
function.
In case you try to achieve something similar, feel free to take a look at our implementation:
The pickup function and an extended give function: https://github.com/TTT-2/TTT2/blob/master/gamemodes/terrortown/gamemode/server/sv_player_ext.lua#L1056
Some internal pickup functions: https://github.com/TTT-2/TTT2/blob/master/gamemodes/terrortown/gamemode/server/sv_weapon_pickup.lua
The modified pickup hook: https://github.com/TTT-2/TTT2/blob/master/gamemodes/terrortown/gamemode/server/sv_weaponry.lua#L31
Some modifications to the equip Hook: https://github.com/TTT-2/TTT2/blob/master/gamemodes/terrortown/gamemode/server/sv_weaponry.lua#L656
So why would you want a binding of Weapon_Equip
over BumpWeapon
?
Added Player.PickupWeapon( wep, onlyAmmo ) = bool success
Added NPC:PickupWeapon
( wep ) = bool
And with that this is fulfilled. NPC:PickupWeapon
does not have an ammo only argument and will drop NPC's current weapon.
Why is the NPC version lacking an ammoonly arg?
Because it's completely useless since NPCs have infinite ammo?
But NPCs are CBaseCombatCharacter
s which all have an ammo table, none of whose functions are binded to Lua for NPCs (GetAmmoCount and the like). Where are they given infinite ammo?
Also, it doesn't make sense for PickupWeapon to drop the NPCs current weapon, they can hold multiple weapons: https://github.com/Facepunch/garrysmod-requests/issues/1237. Seems like we're missing a lot of CBaseCombatCharacter
bindings for NPCs.
Have you ever seen a HL2 NPC run out of ammo?
They don't consume ammo.
That's only if you use reload events, they consume ammo with custom SWEPs.
These are the core events that add and remove weapons from the player's inventory. Lua access to them would allow for custom weapon drops without having to recreate ents, direct trading of weapons between players and NPCs, and an alternative
give
concommand for weapons that wouldn't rely on pickup rules.Equip: https://github.com/VSES/SourceEngine2007/blob/43a5c90a5ada1e69ca044595383be67f40b33c61/src_main/game/server/basecombatcharacter.cpp#L1981 EquipAmmoOnly (would be better as a parameter in the Lua version): https://github.com/VSES/SourceEngine2007/blob/43a5c90a5ada1e69ca044595383be67f40b33c61/src_main/game/server/basecombatcharacter.cpp#L2083 Drop: https://github.com/VSES/SourceEngine2007/blob/43a5c90a5ada1e69ca044595383be67f40b33c61/src_main/game/server/basecombatcharacter.cpp#L1813