Jump to content

headshot


TheMagicano

Recommended Posts

hey i was make headshot script for sniper but i was want it when player get headshot just lose 100hp from his heals can anyone help me please?

Spoiler

addEvent "onPlayerHeadshot"
addEventHandler("onPlayerDamage", getRootElement(),
    function (attacker, weapon, bodypart, loss)
        if bodypart == 9 and weapon == 34 then
            local result = triggerEvent("onPlayerHeadshot", source, attacker, weapon, loss)
            if result == true then
                killPed(source, attacker, weapon, bodypart)
                setPedHeadless( source, true )
                setTimer( BackUp, 900, 1, source )
            end
        end
    end
)
    function BackUp( source )   
    if getElementType ( source ) == "player" then
        setPedHeadless ( source, false )
    end
end

 

Link to comment
5 hours ago, TheMagicano said:

hey i was make headshot script for sniper but i was want it when player get headshot just lose 100hp from his heals can anyone help me please? 

  Hide contents

addEvent "onPlayerHeadshot"
addEventHandler("onPlayerDamage", getRootElement(),
    function (attacker, weapon, bodypart, loss)
        if bodypart == 9 and weapon == 34 then
            local result = triggerEvent("onPlayerHeadshot", source, attacker, weapon, loss)
            if result == true then
                killPed(source, attacker, weapon, bodypart)
                setPedHeadless( source, true )
                setTimer( BackUp, 900, 1, source )
            end
        end
    end
)
    function BackUp( source )   
    if getElementType ( source ) == "player" then
        setPedHeadless ( source, false )
    end
end

 

Do you want me to lose 100 hp instead, to die?
Link to comment
6 minutes ago, TheMagicano said:

I put this line in which function?

First of all, where did you get the script from? If it is stolen, I'm not going to give you support. It seems that you don't know the basis of scripting, so I assume this is not yours. If it is, I'm sorry ^_^

Edited by Peti
Link to comment
16 minutes ago, Peti said:

First of all, where did you get the script from? If it is stolen, I'm not going to give you support. It seems that you don't know the basis of scripting, so I assume this is not yours. If it is, I'm sorry ^_^

lol? someone shere it in our community https://community.multitheftauto.com/index.php?p=resources and i edited somethings in it like weapon..

Edited by TheMagicano
Link to comment

Ok, you're legit. I'm sorry. I was bieng skeptical because you mention that you were making a headshot script, but it wasn't yours.

Here you have your needed support:
 

addEvent("onPlayerHeadshot")
addEventHandler("onPlayerDamage", getRootElement(),
    function (attacker, weapon, bodypart, loss)
        if bodypart == 9 and weapon == 34 then
            local result = triggerEvent("onPlayerHeadshot", source, attacker, weapon, loss)
            if result == true then
				setElementHealth ( source, getElementHealth(source) - 100 ) 
				if isPlayerDead ( source ) == true then 					
					killPed(source, attacker, weapon, bodypart)
					setPedHeadless( source, true )
					setTimer( BackUp, 900, 1, source )
				end
            end
        end
    end
)
function BackUp( source )   
    if getElementType ( source ) == "player" then
        setPedHeadless ( source, false )
    end
end 

 

Edited by Peti
Link to comment

 

3 hours ago, Peti said:

Do you have any errors or something to work with? It should work.

Did you add the script at mtaserver.conf?

Try without brackets like the original


addEvent "onPlayerHeadshot" 

oh sorry, it's working fine. but i was mean it's still same like first time. when i shot player in his head while he using armour he dead directly

Link to comment
8 hours ago, TheMagicano said:

 

oh sorry, it's working fine. but i was mean it's still same like first time. when i shot player in his head while he using armour he dead directly

you want player lose his armour instead of dying ??

if you mean that :

-- Client

addEventHandler( 'onClientPlayerDamage' , root , 
	function( attacker , weapon , bodypart )
		if( weapon == 34 and bodypart == 9 )then
			if( getPedArmor( source ) == 0 )  then
				setPedHeadless( source , true )			
				timer = setTimer( function( source ) setPedHeadless( source , false ) ; end , 2000 , 1 , source )
				triggerServerEvent( 'killPed' , source , attacker , weapon , bodypart ) 
			else
				cancelEvent( true )
				triggerServerEvent( 'removeArmour' , source )
			end
		end
	end
)
-- Server

addEvent( 'removeArmour' , true )
addEventHandler( 'removeArmour' , root , 
	function( )
		setPedArmor( source , 0 )
	end
)

addEvent( 'killPed' , true )
addEventHandler( 'killPed' , root , 
	function( ) 
		killPed( source , attacker , weapon , bodypart )
	end
)

 

  • Thanks 1
Link to comment
1 hour ago, KillerX said:

you want player lose his armour instead of dying ??

if you mean that :


-- Client

addEventHandler( 'onClientPlayerDamage' , root , 
	function( attacker , weapon , bodypart )
		if( weapon == 34 and bodypart == 9 )then
			if( getPedArmor( source ) == 0 )  then
				setPedHeadless( source , true )			
				timer = setTimer( function( source ) setPedHeadless( source , false ) ; end , 2000 , 1 , source )
				triggerServerEvent( 'killPed' , source , attacker , weapon , bodypart ) 
			else
				cancelEvent( true )
				triggerServerEvent( 'removeArmour' , source )
			end
		end
	end
)

-- Server

addEvent( 'removeArmour' , true )
addEventHandler( 'removeArmour' , root , 
	function( )
		setPedArmor( source , 0 )
	end
)

addEvent( 'killPed' , true )
addEventHandler( 'killPed' , root , 
	function( ) 
		killPed( source , attacker , weapon , bodypart )
	end
)

 

thank you so much but theres small bug in it, its make bug in jobs like police can kill police with headshot

Link to comment
Quote

thank you so much but theres small bug in it, its make bug in jobs like police can kill police with headshot 

It isn't a bug, it doesn't even programmed in the code. You need to add teams to your script if you want to cancel the event from certain players to others.

Btw, try to give details next time, you didn't mention armour. Instead you said this:

Quote

hey i was make headshot script for sniper but i was want it when player get headshot just lose 100hp from his heals can anyone help me please?

 

Good luck.

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