Jump to content

Headshot


ZeyadGTX

Recommended Posts

I use this Headshot but i want to make when player gets headshot his head removes untill respawn because his head returns again before spawn

Client :

function sendHeadshot ( attacker, weapon, bodypart, loss ) 
    if attacker == getLocalPlayer() then 
        if bodypart == 9 then 
            triggerServerEvent( "onServerHeadshot", getRootElement(), source, attacker, weapon, loss ) 
            setElementHealth ( source, 0 ) 
            setPedHeadless( source, true ) 
        end 
    end 
end 
addEventHandler ( "onClientPedDamage", getRootElement(), sendHeadshot ) 
addEventHandler ( "onClientPlayerDamage", getRootElement(), sendHeadshot ) 
  

Server :

function MakePlayerHeadshot( attacker, weapon, bodypart, loss ) 
    if getElementType ( attacker ) == "ped" then 
        if bodypart == 9 then 
            triggerEvent( "onPlayerHeadshot", source, attacker, weapon, loss ) 
            setPedHeadless ( source, true ) 
            killPed( source, attacker, weapon, bodypart ) 
            setTimer( BackUp, 900, 1, source ) 
        end 
    end 
end 
  
function MakeHeadshot( source, attacker, weapon, loss ) 
    triggerEvent( "onPlayerHeadshot", source, attacker, weapon, loss ) 
    killPed( source, attacker, weapon, 9 ) 
    setPedHeadless ( source, true ) 
    setTimer( BackUp, 900, 1, source ) 
end 
  
function BackUp( source )    
    if getElementType ( source ) == "player" then 
        setPedHeadless ( source, false ) 
    end 
end 
  
function outputHeadshotIcon (killer, weapon, bodypart) 
    if bodypart == 9 then 
        cancelEvent() 
        local r2,g2,b2 = getTeamColor ( getPlayerTeam( killer ) ) 
        local r1,g1,b1 = getTeamColor ( getPlayerTeam( source ) ) 
        exports.killmessages:outputMessage ( 
        {getPlayerName(killer),{"padding",width=3},{"icon",id=weapon},{"padding",width=3},{"icon",id=256},{"padding",width=3},{"color",r=r1,g=g1,b=b1},getPlayerName(source) }, getRootElement(),r2,g2,b2)               
    end 
end 
addEvent ( "onServerHeadshot", true ) 
addEventHandler( "onPlayerDamage", getRootElement(), MakePlayerHeadshot ) 
addEventHandler( "onPlayerKillMessage", getRootElement(), outputHeadshotIcon ) 
addEventHandler( "onServerHeadshot", getRootElement(), MakeHeadshot ) 
  

Link to comment

In backUp function edit this

setPedHeadless(source, true) 
 
 
MOD NOTE: Editing in Ab-47's comment from 2019 for knownledgebase, but to get rid of a bump
 
Ab-47 said;

You don't need a client side to trigger server side, all you need to do is keep the server side and do the following:

Your backup timer I assume was incase the headless was changed by something else whilst being killed, so that shouldn't be false otherwise in 900 ms the ped/player would have it's head back. I added onPlayerSpawn to give the person their head back. This is really all you need and it works fine, I tested it myself.

📋
function MakePlayerHeadshot( attacker, weapon, bodypart, loss ) 
    if (not attacker or attacker == source) then return end
    if bodypart == 9 then 
        triggerEvent( "onPlayerHeadshot", source, attacker, weapon, loss ) 
        setPedHeadless ( source, true ) 
        killPed( source, attacker, weapon, bodypart ) 
        setTimer( BackUp, 900, 1, source ) 
    end 
end 
addEventHandler( "onPlayerDamage", getRootElement(), MakePlayerHeadshot ) 
  
function BackUp( source )    
    if getElementType ( source ) == "player" then 
        setPedHeadless ( source, true ) 
    end 
end 

function spawnPlayer()
    if (isPedHeadless(source)) then
        setPedHeadless(source, false)
    end
end
addEventHandler("onPlayerSpawn", root, spawnPlayer)
  
function outputHeadshotIcon (killer, weapon, bodypart) 
    if bodypart == 9 then 
        cancelEvent() 
        local r2,g2,b2 = getTeamColor ( getPlayerTeam( killer ) ) 
        local r1,g1,b1 = getTeamColor ( getPlayerTeam( source ) ) 
        exports.killmessages:outputMessage ( 
        {getPlayerName(killer),{"padding",width=3},{"icon",id=weapon},{"padding",width=3},{"icon",id=256},{"padding",width=3},{"color",r=r1,g=g1,b=b1},getPlayerName(source) }, getRootElement(),r2,g2,b2)            
    end 
end 
addEventHandler( "onPlayerKillMessage", getRootElement(), outputHeadshotIcon )
	
Link to comment

I tried That But The head doesn't return if spawned the player is headLess

function MakePlayerHeadshot( attacker, weapon, bodypart, loss ) 
    if getElementType ( attacker ) == "ped" then 
        if bodypart == 9 then 
            triggerEvent( "onPlayerHeadshot", source, attacker, weapon, loss ) 
            setPedHeadless ( source, true ) 
            killPed( source, attacker, weapon, bodypart ) 
            setTimer( BackUp, 900, 1, source ) 
        end 
    end 
end 
  
function MakeHeadshot( source, attacker, weapon, loss ) 
    triggerEvent( "onPlayerHeadshot", source, attacker, weapon, loss ) 
    killPed( source, attacker, weapon, 9 ) 
    setPedHeadless ( source, true ) 
    setTimer( BackUp, 900, 1, source ) 
end 
  
function BackUp( source )    
    if getElementType ( source ) == "player" then 
        setPedHeadless ( source, true ) 
    end 
end 
  
function outputHeadshotIcon (killer, weapon, bodypart) 
    if bodypart == 9 then 
        cancelEvent() 
        local r2,g2,b2 = getTeamColor ( getPlayerTeam( killer ) ) 
        local r1,g1,b1 = getTeamColor ( getPlayerTeam( source ) ) 
        exports.killmessages:outputMessage ( 
        {getPlayerName(killer),{"padding",width=3},{"icon",id=weapon},{"padding",width=3},{"icon",id=256},{"padding",width=3},{"color",r=r1,g=g1,b=b1},getPlayerName(source) }, getRootElement(),r2,g2,b2)               
    end 
end 
addEvent ( "onServerHeadshot", true ) 
addEventHandler( "onPlayerDamage", getRootElement(), MakePlayerHeadshot ) 
addEventHandler( "onPlayerKillMessage", getRootElement(), outputHeadshotIcon ) 
addEventHandler( "onServerHeadshot", getRootElement(), MakeHeadshot ) 
  

Link to comment
  
function sendHeadshot ( attacker, weapon, bodypart, loss ) 
    if attacker ~= source then 
        if bodypart == 9 then 
            triggerServerEvent( "onServerHeadshot", getRootElement(), source, attacker, weapon, loss ) 
            setElementHealth ( source, 0 ) 
            setPedHeadless( source, true ) 
        end 
    end 
end 
addEventHandler ( "onClientPedDamage", getRootElement(), sendHeadshot ) 
addEventHandler ( "onClientPlayerDamage", getRootElement(), sendHeadshot ) 
  
  

Link to comment
  
function sendHeadshot ( attacker, weapon, bodypart, loss ) 
    if attacker ~= source then 
        if bodypart == 9 then 
            triggerServerEvent( "onServerHeadshot", getRootElement(), source, attacker, weapon, loss ) 
            setElementHealth ( source, 0 ) 
            setPedHeadless( source, true ) 
        end 
    end 
end 
addEventHandler ( "onClientPedDamage", getRootElement(), sendHeadshot ) 
addEventHandler ( "onClientPlayerDamage", getRootElement(), sendHeadshot ) 
  
  

Really smart...

Just use in the backup timer the value(time in milliseconds) that the player takes to respawn

Link to comment
Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...