Jump to content

[Help] Event for punching/kicking a vehicle


Olle Risk

Recommended Posts

Hello, I'm trying to set a wanted level on players who commit crimes but I got stuck with the case where a player stand on top of a vehicle and kick it constantly as well as pushing a vehicle from the side with fists or meele weapons. Is there any event available for such attacks?

I already tried these:

onClientVehicleDamage 
onPlayerWeaponFire 

Any ideas?

Link to comment

You can use this.

  
rootElement = getRootElement() 
  
function vandalismveh (player, vehicle) 
local x, y, z = getElementPosition ( player ) 
local xv, yv, zv = getElementPosition ( vehicle )  
if getDistanceBetweenPoints3D ( x, y, z, xv, yv, zv ) == 1 then 
setPlayerWantedLevel ( player, 1 ) 
end 
addEventHandler( "OnClientPlayerWeaponFire", rootElement, vandalismveh ) 
  
  

Link to comment

Nope, it doesn't trigger when I punch the vehicle or stand on top of it kicking on it. I'm looking for an event that trigger on such actions, I'm using a separate system to manage wanted levels so that's pretty much just 1 line of code for me, I just need help to find a trigger (event) for that piece of code to do what I want.

Link to comment

use a on vehicle damage event from client or server side and check if there's attacker and if attacker is a player and if getPedWeapon player == 0(fist) then --do your code

example:

  
-- client 
function handleDamage(attacker,weapon) 
   if attacker and getElementType(attacker) == "player" and weapon and weapon == 0 then -- if attacker is player and fist was used 
      triggerServerEvent("onPlayerWantedLevelUpdate",attacker,1) -- give him 1 star [has to be serverside so we use trigger] 
   end; 
end; 
addEventHandler("onClientVehicleDamage",root,handleDamage); 
  
-- server 
function setWanted(level) 
   setPlayerWantedLevel(client,level) 
end; 
addEvent("onPlayerWantedLevelUpdate",true); 
addEventHandler("onPlayerWantedLevelUpdate",root,setWanted); 

edit: you can rewrite some parts of this code to turn it into your event for fist hitting a vehicle

just edit client side function to your own needs

Link to comment
I tried with "onClientVehicleDamage" earlier but it doesn't seem to trigger on those specific cases I described even if the vehicle do get's damaged, I'll do a few more tests and reply later if it doesn't works. Thanks anyway.

You've said in first post that you're unable to get event when player gets on top of car and starts hitting it and for other melee weapons you could store their ids and then in client script check if table[weapon] and then triggerServerEvent

but for the first case(player being on top of car and hitting it) the script works fine for me

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