Jump to content

Kill player when Rammed by a car


Recommended Posts

-- client
    function check( attacker, weapon )
    local theVehicle = getPedOccupiedVehicle ( getLocalPlayer )
    if getElementType ( weapon ) == "Rammed" then
	triggerServerEvent ( "kill", resourceRoot, attacker )
    else
    end
	end
    addEventHandler("onPlayerDamage"", root, check)
-- server 
function kill(attacker)
outputChatBox("Collided.", source)
killPed(source, attacker)
end
addEvent( "kill", true )
addEventHandler( "kill", resourceRoot, kill ) -- Bound to this resource only, saves on CPU usage.
addCommandHandler("col", kill )-- this  is just to test the kill  

Hi i am trying to make a script that kills player instantly  when hit by a car, can anyone pls  help me out :) 

nevermind my mistake xDDDDD

 

topic close xD

Edited by TheGrimReaper
Link to comment

onPlayerDamage is a server event so you have to use onClientPlayerDamage

-- client
function check( attacker, weapon )
	if getElementType ( attacker ) == "vehicle" and weapon == 49 then
	-- check if attacker was vehicle and damage type was Rammed (49).
		triggerServerEvent ( "onVehicleKill", source, getVehicleController( attacker ) ) 
		-- trigger the kill event sending the player that was hit as the source and the attacker (vehicle) controller.
	end
end
addEventHandler("onClientPlayerDamage", root, check)

 

-- server
function killPlayer(attacker)
	killPed(source, attacker, 49)
	--we use the source which is the localPlayer that was rammed
	-- the attacker is the vehicle's controller
	-- and we set the weeapon to 49 which is the damage type of being rammed
end
addEvent( "onVehicleKill", true )
addEventHandler( "onVehicleKill", root, killPlayer )

 

Edited by Mr.Loki
  • Thanks 1
Link to comment
-- server 
function check ( attacker, weapon, bodypart, loss ) 
    if ( weapon == 49 ) then 
        killPed ( source, attacker, weapon, bodypart, false ) 
    end 
end 
addEventHandler ( "onPlayerDamage", getRootElement (), check ) 
  

yes bro i figured out later , and i wrote this more optimized code xD but thanks for the help man , it was helpful too :)  

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