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)