Jump to content

onPlayerDamage - not triggering.


ds1-e

Recommended Posts

  • Scripting Moderators

Hey. Why script don't trigger server-side event onPlayerDamage? I decided to try server-side variation of this event.

function onClientPlayerDamage(attacker, weapon, bodypart, loss)
	cancelEvent()
end
addEventHandler("onClientPlayerDamage", getLocalPlayer(), onClientPlayerDamage)

function onPlayerDamage(attacker, weapon, bodypart, loss)
	outputDebugString("y")
end
addEventHandler("onPlayerDamage", getRootElement(), onPlayerDamage)

 

Link to comment
  • Moderators

because the MTA developers decided to consider cancelled events as 'it never happened`.

onPayerDamage is a delayed/streamed version of onClientPlayerDamage

Edited by IIYAMA
  • Thanks 1
Link to comment
  • Scripting Moderators
2 hours ago, IIYAMA said:

because the MTA developers decided to consider cancelled events as 'it never happened`.

onPayerDamage is a delayed/streamed version of onClientPlayerDamage

 

Oh well, so i should with onClientPlayerDamage?

  • Like 1
Link to comment
  • Moderators
function onClientPlayerDamage(...)
	cancelEvent()
	triggerLatentServerEvent("onPlayerDamage_", localPlayer, ...)
end
addEventHandler("onClientPlayerDamage", getLocalPlayer(), onClientPlayerDamage)

 

addEvent("onPlayerDamage_", true)-- fake event onPlayerDamage_ = security
addEventHandler("onPlayerDamage_", root, 
function (...) 
	triggerEvent("onPlayerDamage", client, ...)
end)

It can be faked, but you might need to figure out a way to reduction data.

 

@majqq

 

For example buffer up till 100 ms, before sending the message

This will reduce a lot in case of fire/minigun/Spraycan/Fire Extinguisher damage: (NOTE: surprisingly the minigun also fires a bullet every frame)

 

How much reduction do you want for that scenario? Do the maths!

local sendingDelay = 100 -- ms
local fps = 60

local timeSlice  = 1000 / fps
local dataReduction = sendingDelay / timeSlice
print("~" .. (dataReduction - 1 ) .. " x times LESS per " .. sendingDelay .. "ms")

https://www.lua.org/cgi-bin/demo

 

Edited by IIYAMA
  • Thanks 1
Link to comment
  • Scripting Moderators
9 hours ago, IIYAMA said:

function onClientPlayerDamage(...)
	cancelEvent()
	triggerLatentServerEvent("onPlayerDamage_", localPlayer, ...)
end
addEventHandler("onClientPlayerDamage", getLocalPlayer(), onClientPlayerDamage)

 


addEvent("onPlayerDamage_", true)-- fake event onPlayerDamage_ = security
addEventHandler("onPlayerDamage_", root, 
function (...) 
	triggerEvent("onPlayerDamage", client, ...)
end)

It can be faked, but you might need to figure out a way to reduction data.

 

@majqq

 

For example buffer up till 100 ms, before sending the message

This will reduce a lot in case of fire/minigun/Spraycan/Fire Extinguisher damage: (NOTE: surprisingly the minigun also fires a bullet every frame)

 

How much reduction do you want for that scenario? Do the maths!


local sendingDelay = 100 -- ms
local fps = 60

local timeSlice  = 1000 / fps
local dataReduction = sendingDelay / timeSlice
print("~" .. (dataReduction - 1 ) .. " x times LESS per " .. sendingDelay .. "ms")

https://www.lua.org/cgi-bin/demo

 

 

That's cool, i'll try it out soon, also with your other solutions for sounds, explosion damage etc., ty :D I have used your way to synchronize data from server-side table -> client. For me works well, but until i'll finish my scripts, i am testing stuff alone. I am impatient to test how it will works with players on server :)

I wanna exclude using elementData in my scripts (atleast in 99%), by creating temporary data system, within tables + trigger/triggerLatent.

By the way as we are in topic about player damage. Using server-side variation of this event should improve hitboxes? Or it's about configuring it here - https://wiki.multitheftauto.com/wiki/Sync_interval_settings

Bullet sync, latency reduction, threadnet, bandwidth_reduction, and also this?

Edited by majqq
Link to comment
  • Moderators

As far as I know these settings are only used for sync element orientations.

 

 

p.s you might also reduce data like this:

function onClientPlayerDamage(attacker, weapon, bodypart, loss)
	local newHealth = getElementHealth(localPlayer)
  
	if newHealth > 0 then -- is not dead
		local oldHealth = newHealth + loss
		setElementHealth(localPlayer, oldHealth) -- reset
	else -- is dead
		cancelEvent()
		triggerLatentServerEvent("onPlayerDamage_", localPlayer, attacker, weapon, bodypart, loss)
	end
end
addEventHandler("onClientPlayerDamage", localPlayer, onClientPlayerDamage)

 

p.s this might also be needed serverside.

addEvent("onPlayerDamage", false) --remote disabled

 

  • Thanks 1
Link to comment

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...