Facepunch / garrysmod-issues

Garry's Mod issue tracker
137 stars 56 forks source link

Think hook of the tool `X` gets run one last time after deploy of tool `Y` #5931

Closed dvdvideo1234 closed 2 weeks ago

dvdvideo1234 commented 2 weeks ago

Please try running a different branch and verifying your game file integrity before reporting an issue.

Verification completed successfully ( all branches below ) and tested for every beta with and without addons:

Details

The TOOL:Think() routine is called one last time for tool X after user switches from tool X to tool Y. The current game version running is:

] version
Protocol version 24
Exe version 2023.06.28 (garrysmod)
Exe build: 19:41:45 Jun 17 2024 (9354) (4000)
GMod version 2024.07.05, branch: x86-64, multicore: 1
Windows 64bit

Steps to reproduce

  1. Install the MASTER version of the TA tool
  2. Start Gmod and load random map ( I used flatgrass. Any branch/map will do )
  3. Pick up the TA tool. The ghost gets drawn. Normal behavior here.
  4. Press 1 to select the crowbar. The ghost is removed via RemoveEntityDelay and gone after the given time. All OK here too
  5. Pick up any other random tool. The TA ghosting is re-triggered for one frame and the ghost is drawn

Details about the issue and the current workaround can be found here: https://github.com/dvdvideo1234/TrackAssemblyTool/issues/58

### Tasks
- [ ] https://github.com/dvdvideo1234/TrackAssemblyTool/issues/58
- [ ] https://github.com/wiremod/advduplicator/issues/91
Grocel commented 2 weeks ago

This also causes this issue: https://github.com/wiremod/advduplicator/issues/91

It is important to note that this behavior is kinda unexpected as it makes the TOOL:Think() call bypass TOOL:Deploy() and TOOL:Holster(). This causes construction and/or deconstruction logic not being checked/called in the right order.

robotboy655 commented 2 weeks ago

Core issue aside, your issue could be solved with 3 lines of code, by properly implementing base TOOL hooks:

function TOOL:ReleaseGhostEntity()
    asmlib.ClearGhosts()
end
robotboy655 commented 2 weeks ago

Core issue being just the network delay to update gmod_toolmode convar clientside, from the server, to switch the toolmode clientside.

It's not "calling think on the old tool while a new one is active", it's just that the toolmode switch clientside is delayed.

dvdvideo1234 commented 2 weeks ago

Sorry.. Clicked the close by mistake

robotboy655 commented 2 weeks ago

Ok, I have made some changes to how tool switching works, it should now call Tool:Holster on the old tool clientside when swtiching tools. This was previously only happening serverside, and only when using gmod_tool concommand. (As opposed to gmod_toolmode convar)