TTT-2 / TTT2

Trouble in Terrorist Town 2 for Garry's Mod (gmod)
https://steamcommunity.com/sharedfiles/filedetails/?id=1357204556
178 stars 74 forks source link

Pickup Entites: Problem when picking up entities in close range #861

Closed TimGoll closed 2 years ago

TimGoll commented 3 years ago

Version

The TTT2 version doesn't seem to matter. This problem occured ever since GMod added its own pickupsystem that we use, maybe even longer.

Description

This is a pretty vague description for now, because it has to be investigated further. These information were collected together with @TheSuspect2306.

We noticed the bug when trying to pick up a soda can. This doesn't cause problems normally, however it breaks if the player is in really close range with the entity. It then tries to teleport the entity to the player. This is no behaviour that is added in the super soda addon. In fact I noticed something similar when playing TTT. Sometimes, when picking up a weapon, it stays afloat in the air without being added to the inventory. This problem could be caused by the same bug. This has to be investigated more.

While investigating the super soda problem @TheSuspect2306 quickly noticed that returning false in GM:PlayerCanPickupWeapon prevents this problem. Now here lies the problem. We now know for a fact that calling the hook manually causes entities to move under certain conditions. However we don't know why. And we don't know the conditions. There is nothing in the hook that indicates such a behaviour (we should take a look at the registered hook list to confirm that no other addon initiates this teleporting). This has to be investigated further, maybe the guys over at Facepunch can help more with this.

The relevant code in the super soda addon shows a usecase of the aforementioned function. While this specific bug could be fixed by moving the check further down, the underlying bug would still persist.

TimGoll commented 2 years ago

I found the issue, it is caused by this part in GM:PlayerCanPickupWeapon: https://github.com/TTT-2/TTT2/blob/d76aa1b313d3766ef279cba252a233317e948e26/gamemodes/terrortown/gamemode/server/sv_weaponry.lua#L81-L90

image Bottle starts floating if soda pickup is prohibited by soda addon

image Doesn't happen without these lines

TimGoll commented 2 years ago

fixed in dev