hook.Add seemingly does nothing when inside SWEP:SecondaryAttack/PrimaryAttack
13 replies, posted
function SWEP:SecondaryAttack()
hook.Add( "HUDPaint", "HUDPaint_DrawABox", function()
surface.SetDrawColor( 0, 0, 0, 128 )
surface.DrawRect( 0, 0, 128, 128 )
end )
end
why am i so bad at this shit
SecondaryAttack will only run on the client in single-player, and even then it's not always guaranteed. You should network to the client.
I understood none of that
HUDPaint is a clientside hook. SecondaryAttack is only guarenteed to be called serverside. Network to the client from SecondaryAttack to add the hook.
I'm really just messing around in singleplayer right now, but what makes the Clienside version of SecondaryAttack bad?
It's never called on the client in single-player, and only for prediction reasons in multi-player - in other words, it doesn't have to be called.
By the way you're wording this it sounds like SecondaryAttack shouldn't be used
There's nothing wrong with SecondaryAttack, but if you want to do something on the client from it, you should network.
Please bear with me here.
So SecondaryAttack wont run on a clientside lua script?
SecondaryAttack will always run serverside. It will run clientside in multi-player only (it will NEVER run clientside in single-player), but it should only be used for prediction matters (which is linked above). If you want to do something like add a clientside hook from SecondaryAttack, network to the client from the server.
Still confused to why it would run Clientside in multiplayer if it's for handling things like firing bullets
The prediction page explains that - the client will also "fire the bullet" to make it appear instantly and smoothly, regardless of server ping. It's not needed in single-player since the client has server information instantly.
Oh I know about that, I'm just saying wouldn't the fire bullet command also have to run on the server so it could relay damage to other clients?
yes, it runs on both. on server, it fires the bullet and networks it to everyone except who shot it ( except in SP ). Client is only visible on the shooting client.
Sorry, you need to Log In to post a reply to this thread.