Jump to content

Help with HeadShot Teams


Recommended Posts

I have another question if it can be done so that people from the red team can shoot other players in the head (in the sense that it would kill other players)

 

-- server side
red = createTeam("RED", 255, 0 ,0)
blue = createTeam("BLUE" , 0, 255, 0)

-- client side

function RedTeamHeadShotDamage(player, valuedamage, bodypart)
	if bodypart==9 then
    	killPed(getLocalPlayer())
    else
    	cancelEvent()
    end
end

function SetRedTeamHeadShotOnly()
  	local redPlayers = getTeamFromName("BLUE")
  	local teamRed = getPlayersInTeam(redPlayers)
	for i, v in pairs(teamRed) do
    	addEventHandler("onClientPlayerDamage", v, RedTeamHeadShotDamage)
    end
end

SetRedTeamHeadShotOnly()

Something I mean, can it work?

Link to comment

This resource will make players who are in a different team give headshot to each other, but if they are from the same team nothing will happen.

Server.Lua

function MakePlayerHeadshot( attacker, weapon, bodypart, loss )
	if isElement(attacker) then
		if getElementType ( attacker ) == "player" then
			if getPlayerTeam( source ) ~= getPlayerTeam( attacker ) 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
	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
addEvent ( "onServerHeadshot", true )
addEventHandler( "onPlayerDamage", getRootElement(), MakePlayerHeadshot )
addEventHandler( "onServerHeadshot", getRootElement(), MakeHeadshot )

Client.Lua

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

meta.xml

<meta>
      <script src="Server.Lua" type="server" />
      <script src="Client.Lua" type="client" />
</meta>

 

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