Jump to content

[HELP] Trigger


WelCome

Recommended Posts

Hello i want create a new hitbox-system but i have little problem with headshot :/

 

-client 

function returining(endZ)

return triggerServerEvent("daj_cos",localPlayer,endZ)
end


addEventHandler("onClientPlayerWeaponFire",getLocalPlayer(),function(weapon, ammo, ammoInClip,endX,endY,endZ,hitElement)
if not getElementType(hitElement)=="player" then return end
if returining(endZ)<0.3 then
outputChatBox("true")
end
end)

-server

addEvent("daj_cos",true)
addEventHandler("daj_cos",root,function(endZ)
for i,v in pairs(getElementsByType("player")) do
local x,y,z = getElementPosition(v)
local distance = getDistanceBetweenPoints3D(_,_,z,_,_,endZ)
return distance
end
end)

 

Link to comment
  • Moderators

You can not use return to send information to the other side. Sending information cost time(ping) and the code doesn't wait for that.

 

Think about about ping pong. You hit a ping pong ball with a bat and it takes some time before it comes back to you.

You need two trigger events to make this work + restructure code.

Link to comment

:facepalm:

client

addEventHandler("onClientPlayerWeaponFire",getLocalPlayer(),function(weapon, ammo, ammoInClip,endX,endY,endZ,hitElement)
triggerServerEvent("daj_cos",localPlayer,endZ,hitElement)
end)

server

addEvent("daj_cos",true)
addEventHandler("daj_cos",root,function(endZ,hitElement)
local x,y,z = getElementPosition(hitElement)
if getDistanceBetweenPoints3D(_,_,z,_,_,endZ)<1.0 then
killPed(hitElement)
end
end)

db : Bad argument getDistanceBetweenPoints3D [ Expected vector3 at argument 1, got nil]

Edited by WelCome
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...