Jump to content

"onPlayerDamage" event bug


Recommended Posts

Posted

Hello there. I wanted to make something like a stun when you hit player with a cop nightstick. But I came across a very annoying bug. The event "onPlayerDamage" doesn't work correctly. I just made a check that you use the nightstick and a debug message showing that the event triggered. But it doesn't always work and while a source is on the run it won't trigger at all! I provided my simple script and hope you can help me with this issue.

function NightstickStun ( attacker, weapon, bodypart, loss ) 
    if ( weapon == 3 ) then 
outputChatBox("HIT!",getRootElement(),0,255,255) 
    end 
end 
addEventHandler ( "onPlayerDamage", getRootElement (), NightstickStun ) 

  • Moderators
Posted

1 > did you start the resource?

2 > Serverside event < it is server side just like headshot (looks like 90% at it)

3 > debugscript. Any thing?

4 > meta ????

Check it all pls, bevore you are going to say the code is wrong.

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted

This is just a simple code that doesn't have any error

it's just will out put 'HIT!' for everyone whenever any player attacks other player with nightstick.

CiTLh.png
Posted
1 > did you start the resource?

2 > Serverside event < it is server side just like headshot (looks like 90% at it)

3 > debugscript. Any thing?

4 > meta ????

Check it all pls, bevore you are going to say the code is wrong.

Of course, I checked that all because this simple code is a part of the huge police system script. And it works with about 90% chance just like TAPL said. The problem is that why doesn't it work with 100% chance and why doesn't it work when a source is moving?

Posted

This is known as desynchronization. When a player is running on your screen, the position and rotation aren't always 100% correct (especially if you or the target has a slow Internet connection and/or computer). Thus hitting them doesn't actually trigger the event, as you never hit them according to the server.

Retired

  • Moderators
Posted
It's very sad :( I suppose that it will happen even if I do it client-side, won't it?

Yes client side would be better.

Server side will only calculate this as a hit when it is visible at server side.

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...