Ragnar Posted July 23, 2019 Share Posted July 23, 2019 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 Lord Henry Posted July 23, 2019 Other Languages Moderators Share Posted July 23, 2019 OnPlayerWasted não usa aqueles parâmetros de função. No seu caso, daria pra deixar sem parâmetro nenhum. 1 Link to comment
Ragnar Posted July 23, 2019 Author Share Posted July 23, 2019 7 minutes ago, Lord Henry said: OnPlayerWasted não usa aqueles parâmetros de função. No seu caso, daria pra deixar sem parâmetro nenhum. Ficaria addEventHandler ( "onPlayerWasted", unassignTeam ) Link to comment
Other Languages Moderators Lord Henry Posted July 23, 2019 Other Languages Moderators Share Posted July 23, 2019 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) 1 Link to comment
Ragnar Posted July 23, 2019 Author Share Posted July 23, 2019 Foi, agora o problema é, depois de morto não volta mais ao team (só se der restart), e só seta apenas 1 jogador Link to comment
Other Languages Moderators Lord Henry Posted July 23, 2019 Other Languages Moderators Share Posted July 23, 2019 (edited) 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 July 24, 2019 by Lord Henry 1 Link to comment
Ragnar Posted July 24, 2019 Author Share Posted July 24, 2019 Ok Como faço que esses comando dependa de outro recurso? exemplo: Freeroam, caso ele esteja desativado, ele não irá funcionar... somente quando estiver ativo Link to comment
Other Languages Moderators Lord Henry Posted July 24, 2019 Other Languages Moderators Share Posted July 24, 2019 (edited) 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 July 24, 2019 by Lord Henry 1 Link to comment
Ragnar Posted July 24, 2019 Author Share Posted July 24, 2019 Muito obrigado, @Lord Henry Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now