Jump to content

setElementHealth ACL


Recommended Posts

  • Moderators

Basta saber usar a função de comando "addCommandHandler" e obter os jogadores do grupo conforme foi dito acima.

Aqui um código que fiz:

local grupo = "BOPE"

addCommandHandler( "vida", function( player )
	local BOPEPlayers = getPlayersFromACL( grupo ) or {}
	-- avisa o jogador que digitou o comando se não tiver ninguém da ACL no server
	if #BOPEPlayers == 0 then
		return outputChatBox( "Não há jogadores nesse grupo!", player )
	end
	
	-- loop nos jogadores do grupo
	for i, aclPlayer in ipairs( BOPEPlayers ) do
		setElementHealth( aclPlayer, getPedMaxHealth(aclPlayer) )
	end
end )


-- retorna uma tabela com todos jogadores online em uma ACL
function getPlayersFromACL( g )
	local players = {}
	for _, player in pairs( getElementsByType("player") ) do
		if isPlayerInACL( player, tostring(g) ) then
			table.insert( players, player )
		end
	end
	return players
end

-- Função útil que verifica se o jogador está em determinada ACL
-- https://wiki.multitheftauto.com/wiki/IsPlayerInACL
function isPlayerInACL(player, acl)
   local accountName = getAccountName( getPlayerAccount(player) )
   if accountName ~= "guest" and type( aclGetGroup(acl) ) == "userdata" then
      return isObjectInACLGroup( "user."..accountName, aclGetGroup(acl) )
   end
   return false
end

-- https://wiki.multitheftauto.com/wiki/GetPedMaxHealth
function getPedMaxHealth(ped)
    -- Output an error and stop executing the function if the argument is not valid
    assert(isElement(ped) and (getElementType(ped) == "ped" or getElementType(ped) == "player"), "Bad argument @ 'getPedMaxHealth' [Expected ped/player at argument 1, got " .. tostring(ped) .. "]")

    -- Grab his player health stat.
    local stat = getPedStat(ped, 24)

    -- Do a linear interpolation to get how many health a ped can have.
    -- Assumes: 100 health = 569 stat, 200 health = 1000 stat.
    local maxhealth = 100 + (stat - 569) / 4.31

    -- Return the max health. Make sure it can't be below 1
    return math.max(1, maxhealth)
end

 

Edited by DNL291
  • 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...