Both an annoying bug and a gigantic problem with SWEP:Deploy( )

So, I’ve hit a huge snag with the deploy function with my weapon base, and it’s the sheer fact that SWEP:Deploy( ) is apparently a shared function that does literally nothing clientside. It straight up will not do anything.

function SWEP:Deploy( )
    print( "This will not print clientside. Ever." )
    return true

So, what I thought would be the solution ends up bringing up another problem. My first instinct was to jump to net messages, but they’re completely useless because of one fatal flaw:

function SWEP:Deploy( )
	net.Start( "deployMsg" )
	net.Send( self.Owner )
        return true

net.Receive( "deployMsg", function( length, client )
	print( LocalPlayer( ):GetActiveWeapon( ) )
end )

If you run that code, you’ll get the weapon you’re switching from instead of the weapon you’re switching to.

I’ve done some Googling around and found that there’s a bunch of people that have had this problem, and I’ve found few solutions with no application towards what I’m looking to do with my weapon base, which is run a function with a couple paramaters:

self.timeBeforeNextMode = CurTime( ) + deployTime -- deployTime is just the length of the deploy animation declared in self:Deploy( )
self:Controls( "none", CurTime( ).

If someone can help me provide a solution, I’d be extremely grateful.

Assuming you are correct and it isn’t called clientside (don’t have access to test myself right now), you could call it yourself using SWEP:CallOnClient

[lua]function SWEP:Deploy()
if SERVER then
self:CallOnClient(“Deploy”,"") --can add some parameters as the second string here
if CLIENT then
print( “This should print clientside. Always.” )

You rule, dude. That solves the problem perfectly.

The only question I have now is should I leave this open? I do think this is a legitimate bug and the Next Moaner’s Version Club or whatever it’s called isn’t up anymore.

You’re right; I think this is a new bug as I believe it worked fine in the past.

I opened an issue-report for you linking back to this thread. I’m sure this can be marked as solve now that this exists:

Thank you!

It’s a weird one really. Deploy does get called clientside, but only on a multiplayer server, when the player manually changes weapons (it will not be called if the server forces the player to switch weapons).

CallOnClient is a viable workaround but you should use it only when in a singleplayer session (you can check that using game.SinglePlayer). Otherwise Deploy should be already called clientside in most cases.

I’m running a multiplayer dedicated server; still could not get it to print on Deploy on the clientside regardless of whether I switched to it manually, or it was switched to via code.

It used to work; I commented out old code in Deploy for my old weapon-holster system before I changed that horrid system and went a much better route.

Still works for me. But yeah the fact that it’s not reliable at all really sucks. I think it has always been like that, at least it was already that way 2 years ago.

It’s been like this forever, at least in GMod 13. I have been bugging Garry about this, but he said it is prediction and it won’t be fixed.

Next time you mention it to him, can you point out that people don’t just make shooty bullet guns with SWEPs, and might need to actually run Lua on the client for more than just prediction sometimes?

hook.Add(“PlayerSwitchWeapon”, “_hooknameIforgot”, function(ply, _, wep)
if ply == LocalPlayer() then
if IsValid(wep) and wep.Deploy then

Clientside? I don’t even know if this hook is called when Deploy isn’t. A really hacky method would be to hook Tick and check if your active weapon entity has changed and then call Deploy on it.