Jump to content

Ajuda com setPlayerTeam/createTeam


Recommended Posts

Olá,

 

Estou tentando fazer um recurso que seta o jogador e cria o team no TAB ao pressionar /navio e navio1. E ao morrer removerá o jogador desse team.

já tentei usando:

removePlayerFromTeam
setPlayerTeam
createTeam
function assignNewTeam ( source, commandName, theTeam )
  local theTeam = createTeam ("R7", 0, 255, 0)
  if theTeam then
    setPlayerTeam ( source, theTeam )
  end
end
addCommandHandler ( "navio", assignNewTeam )

function assignNewTeam2 ( source, commandName, theTeam )
  local theTeam = createTeam ("PCC", 255, 0, 0)
  if theTeam then
    setPlayerTeam ( source, theTeam )
  end
end
addCommandHandler ( "navio2", assignNewTeam2 )

function unassignTeam ( source, commandName )
  local theTeam = getPlayerTeam ( source )
  if theTeam then
  setPlayerTeam ( source, nil )
  end
end
--addCommandHandler ( "takeawaymyteam", unassignTeam )
addEventHandler ( "onPlayerWasted", getRootElement(), unassignTeam )

 

O mais próximo que consegui chegar foi através desse, porem, não sei se é a forma mais correta.

O erro dele é que só seta apenar 1 jogador ao team, e se o jogador morrer ele não será removido.

Link to comment
  • Other Languages Moderators

Eu disse parâmetro de função e não parâmetro de evento.

function unassignTeam ()
	local theTeam = getPlayerTeam (source)
	if theTeam then
		setPlayerTeam (source, nil)
	end
end
addEventHandler ("onPlayerWasted", root, unassignTeam)

 

  • Thanks 1
Link to comment
  • Other Languages Moderators

A sua função do /navio e do /navio2 ficam tentando criar o time cada vez que alguém usa o comando. Na segunda vez ele dará erro, pois o time já existe.

function assignNewTeam (source, commandName)
	local theTeam -- Cria a variável do time mas não atribui valor nenhum a ela de propósito.
	if (getTeamFromName ("R7")) then -- Se já existe um time com o nome "R7", então:
		theTeam = getTeamFromName ("R7") -- A variável recebe o time que já existe.
	else -- Se não existe nenhum time com esse nome criado, então:
		theTeam = createTeam ("R7", 0, 255, 0) -- Cria o time e coloca ele nessa variável.
	end
	setPlayerTeam (source, theTeam) -- Coloca o player que digitou o comando nesse time.
end
addCommandHandler ("navio", assignNewTeam)

 

Edited by Lord Henry
  • Thanks 1
Link to comment
  • Other Languages Moderators

Da pra fazer com isso:

function isResourceRunning (resourceName)
	local res = getResourceFromName (resourceName)
	if (res) then
		if (getResourceState (res) == "running") then
			return true
		else
			return false
		end
	end
end

Adicione essa função acima no seu script.

Depois quando quiser verificar se o resource Freeroam está ligado ou não, basta verificar com:

if (isResourceRunning ("freeroam")) then -- Se o resource freeroam está ativo, então:
    -- Faz alguma coisa
end

Sua função vai ficar assim:

function assignNewTeam (source, commandName)
	if (isResourceRunning ("freeroam")) then
		local theTeam -- Cria a variável do time mas não atribui valor nenhum a ela de propósito.
		if (getTeamFromName ("R7")) then -- Se já existe um time com o nome "R7", então:
			theTeam = getTeamFromName ("R7") -- A variável recebe o time que já existe.
		else -- Se não existe nenhum time com esse nome criado, então:
			theTeam = createTeam ("R7", 0, 255, 0) -- Cria o time e coloca ele nessa variável.
		end
		setPlayerTeam (source, theTeam) -- Coloca o player que digitou o comando nesse time.
	end
end
addCommandHandler ("navio", assignNewTeam)
Edited by Lord Henry
  • Thanks 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...