Jump to content

Desconectar e dar kill


Recommended Posts

Boa Tarde estou tentando fazer uma função que quando jogador leve o dano de quem atirou e dar disconnect ele da o kill para quem atirou so que nao estou conseguindo podem me ajuda a ver a onde estou errando?

addEventHandler ( "onPlayerQuit", getRootElement(), function (quitType,killer)
    if quitType == "Quit" or quitType == "Timed out" then
        local playerAccount = getPlayerAccount(source)
        if playerAccount and getElementData (source, "antiRelogWork") == true then
            setAccountData(playerAccount, "antiRelogWork", false)
			if killer then
			    setElementData(killer,"murders",getElementData(killer,"murders")+1)
				outputDebugString("Player Killer")
			end
        end 
    end 
end )

 

Link to comment
  • Other Languages Moderators

Não é possível matar o jogador que já desconectou. Mas você pode salvar no jogador que saiu do server o último jogador que deu dano nele. Então marque como +1 kill como data no jogador que estava marcado no momento em que este jogador desconectar.

function saveAttacker (attacker, weapon, bodypart, loss)
	if attacker and getElementType (attacker) == "player" then -- Se o último dano recebido foi por um jogador, então:
		setElementData (source, "attacker", attacker) -- Salva o jogador que deu dano nele como data.
	elseif attacker and getElementType (attacker) == "vehicle" then -- Se o último dano recebido foi por um veículo, então:
		setElementData (source, "attacker", getVehicleController (attacker)) -- Salva o motorista do veículo como data.
	end
end
addEventHandler ("onPlayerDamage", getRootElement(), saveAttacker)

function quitKill (quitType, reason, responsibleElement)
	local killer = getElementData (source, "attacker") -- Variável killer recebe o jogador que atacou por último este jogador que saiu do server.
	if isElement (killer) then -- Se o jogador que atacou por último ainda existe, então:
    	local kills = getElementData (killer, "kills") -- Variável kills recebe a quantidade de kills deste jogador que atacou por último.
		if not kills then -- Se não há nenhuma kill, então é 0.
			kills = 0
		end
		setElementData (killer, "kills", kills + 1) -- Adiciona mais uma kill no jogador que atacou por último e salva esse novo valor como data.
    end
end
addEventHandler ("onPlayerQuit", getRootElement(), quitKill)

function removeLastAttacker (ammo, attacker, weapon, bodypart, stealth) -- Adiciona +1 kill no jogador que matou alguém. E remove o último atacante do jogador que morreu para evitar kill duplicada.
	if getElementData (source, "attacker") then
		setElementData (source, "attacker", false)
	end
	if attacker then
		if getElementType (attacker) == "vehicle" then
			attacker = getVehicleController (attacker)
			local kills = getElementData (attacker, "kills")
			if not kills then
				kills = 0
			end
			setElementData (attacker, "kills", kills + 1)
		elseif getElementType (attacker) == "player" then
			local kills = getElementData (attacker, "kills")
			if not kills then
				kills = 0
			end
			setElementData (attacker, "kills", kills + 1)
		end
	end
end
addEventHandler ("onPlayerWasted", getRootElement(), removeLastAttacker)

Não cheguei a testar. Nos avise se der certo ou não.

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