Jump to content

Como ficar imortal após tp por 3 sec


Recommended Posts

Posted (edited)

Como ficar imortal após tp por 3 sec?

Atualmente esse é meu sistema de tp 
gostaria de deixar ele melhor adicionando um tempo de 3 segundos imortal após dar o tp

não entendo mt de script ent pode parecer burrice

 

function tpCJ( source )
	setElementPosition(source, 2466.6005859375, -1669.8226318359, 13.474987983704)
	setElementRotation(source, 0, 0, 0)
	outputChatBox("#FF3C00[ Teleporte ] #FF3C00 jogador "..getPlayerName(source).." #FF3C00foi para o CJ. [ /cj ]", root, 255, 255, 255, true)
end
addCommandHandler("cj", tpCJ)

function tpShp( source )
	setElementPosition(source, 1129.2374267578, -1468.4719238281, 15.740354537964)
	setElementRotation(source, 0, 0, 0)
	outputChatBox("#FF3C00[ Teleporte ] #FF3C00 jogador "..getPlayerName(source).." #FF3C00foi para o Shopping. [ /shp ]", root, 255, 255, 255, true)
end
addCommandHandler("shp", tpShp)

function tpCnc( source )
	setElementPosition(source, 552.06091308594, -1260.3699951172, 17.2421875)
	setElementRotation(source, 0, 0, 0)
	outputChatBox("#FF3C00[ Teleporte ] #FF3C00 jogador "..getPlayerName(source).." #FF3C00foi para a Concessionária. [ /conce ]", root, 255, 255, 255, true)
end
addCommandHandler("conce", tpCnc)

function tpFav( source )
	setElementPosition(source, 2159.4169921875, -979.93322753906, 70.526741027832)
	setElementRotation(source, 0, 0, 0)
	outputChatBox("#FF3C00[ Teleporte ] #FF3C00 jogador "..getPlayerName(source).." #FF3C00foi para a Favela da Aldeia. [ /aldeia ]", root, 255, 255, 255, true)
end
addCommandHandler("aldeia", tpFav)

function tpArms( source )
	setElementPosition(source, 2162.638671875, -1732.4927978516, 17.281345367432)
	setElementRotation(source, 0, 0, 0)
	outputChatBox("#FF3C00[ Teleporte ] #FF3C00 jogador "..getPlayerName(source).." #FF3C00foi para a Loja de Armas. [ /ljarmas ]", root, 255, 255, 255, true)
end
addCommandHandler("ljarmas", tpArms)

function tpPvp( source )
	setElementPosition(source, 437.10000610352, -6549.2001953125, 14.300000190735)
	setElementRotation(source, 0, 0, 0)
	outputChatBox("#FF3C00[ Teleporte ] #FF3C00 jogador "..getPlayerName(source).." #FF3C00foi jogar pvp. [ /pvp ]", root, 255, 255, 255, true)
end
addCommandHandler("pvp", tpPvp)

 

Edited by Lord Henry
Script convertido de HTML para Lua.
  • Moderators
Posted (edited)

Você pode melhorar seu código utilizando tabelas e loop em vez de ficar adicionando cada comando em uma função separada.

Para deixar o jogador imortal, basta colocar uma elementData nele e verificar se ele tem essa data no client. Se tiver, cancela qualquer dano que ele recebe.

server.lua

local teleportes = { -- [comando] = {x, y, z, nome},
    ["cj"] = {2466.6, -1669.82, 13.475, "o CJ"},
    ["shp"] = {1129.24, -1468.47, 15.74, "o Shopping"},
    ["conce"] = {552.06, -1260.37, 17.24, "a Concessionária"},
    ["aldeia"] = {2159.42, -979.93, 17.24, "a Favela da Aldeia"},
    ["ljarmas"] = {2162.64, -1732.49, 17.28, "a Loja de Armas"},
    ["pvp"] = {437.1, -6549.2, 14.3, "a Área de PvP"},
}

local imortais = {}

function telePlayer (thePlayer, cmd) -- Função que é ativada pelo addCommandHandler.
    if teleportes[cmd] then -- Se o comando utilizado existe na tabela, então:
        if imortais[thePlayer] then -- Se o jogador ainda está imortal, então nada acontece.
            outputChatBox("Aguarde 3 segundos para teleportar novamente.", thePlayer, 255, 60, 0)
            return
        else
            imortais[thePlayer] = true -- Adiciona o jogador na tabela de imortais.
            setElementAlpha(thePlayer, 150) -- Deixa o player translúcido (fantasma) pra mostrar que está imortal.
            setElementData(thePlayer, "imortal", true) -- Coloca essa elementData nele pra deixá-lo imortal.
            setTimer(function() -- Depois de 3 segundos, tira o jogador da tabela de imortais, deixa ele opaco novamente e remove a data de imortal dele.
                imortais[thePlayer] = nil
                setElementAlpha(thePlayer, 255)
                removeElementData(thePlayer, "imortal")
            end, 3000, 1)
        end
        local x, y, z, nome = unpack(teleportes[cmd]) -- Pega as infos desse item da tabela e separa em variáveis.
        setElementPosition(thePlayer, x, y, z, true) -- Teleporta o player.
        -- setElementRotation(thePlayer, 0, 0, 0)
        outputChatBox("[Teleporte] O jogador #ffffff"..getPlayerName(thePlayer).." #FF3C00foi para "..nome..". [/"..cmd.."]", root, 255, 60, 0, true) -- Manda essa mensagem pra todo mundo.
    end
end

for cmd,v in pairs (teleportes) do -- Faz um loop pela tabela, adicionando todos os addCommandHandlers.
    addCommandHandler(cmd, telePlayer)
end

client.lua

addEventHandler ("onClientPlayerDamage", root, function ()
    if getElementData(source, "imortal") then -- Se o jogador que tomou dano tem essa elementData, então cancela o dano e nada acontece.
        cancelEvent()
    end
end)
 
addEventHandler ("onClientPlayerStealthKill", localPlayer, function (targetPlayer)
    if getElementData (targetPlayer, "imortal") then -- Se o jogador que está sendo alvo da facada fatal tiver essa elementData, impede que ele tome a facada e nada acontece.
        cancelEvent()
    end
end)

 

Edited by Lord Henry
  • Thanks 1

Eu te ajudei ou achou meu comentário útil? Não esqueça de deixar um Thanksspacer.png

Minhas contribuições para a comunidade: LordHenry - MTA Wiki Profile
Inscreva-se no meu canal do YouTube: Lord Henry - Entertainment
Discord Oficial do MTA: https://mtasa.com/discord
Blacklist e Whitelist de Scripters: Planilha

Por favor, não me envie mensagens privadas solicitando suporte. Crie um tópico no fórum em vez disso.

Posted
1 hour ago, Lord Henry said:

Você pode melhorar seu código utilizando tabelas e loop em vez de ficar adicionando cada comando em uma função separada.

Para deixar o jogador imortal, basta colocar uma elementData nele e verificar se ele tem essa data no client. Se tiver, cancela qualquer dano que ele recebe.

server.lua

local teleportes = { -- [comando] = {x, y, z, nome},
    ["cj"] = {2466.6, -1669.82, 13.475, "o CJ"},
    ["shp"] = {1129.24, -1468.47, 15.74, "o Shopping"},
    ["conce"] = {552.06, -1260.37, 17.24, "a Concessionária"},
    ["aldeia"] = {2159.42, -979.93, 17.24, "a Favela da Aldeia"},
    ["ljarmas"] = {2162.64, -1732.49, 17.28, "a Loja de Armas"},
    ["pvp"] = {437.1, -6549.2, 14.3, "a Área de PvP"},
}

local imortais = {}

function telePlayer (thePlayer, cmd) -- Função que é ativada pelo addCommandHandler.
    if teleportes[cmd] then -- Se o comando utilizado existe na tabela, então:
        if imortais[thePlayer] then -- Se o jogador ainda está imortal, então nada acontece.
            outputChatBox("Aguarde 3 segundos para teleportar novamente.", thePlayer, 255, 60, 0)
            return
        else
            imortais[thePlayer] = true -- Adiciona o jogador na tabela de imortais.
            setElementAlpha(thePlayer, 150) -- Deixa o player translúcido (fantasma) pra mostrar que está imortal.
            setElementData(thePlayer, "imortal", true) -- Coloca essa elementData nele pra deixá-lo imortal.
            setTimer(function() -- Depois de 3 segundos, tira o jogador da tabela de imortais, deixa ele opaco novamente e remove a data de imortal dele.
                imortais[thePlayer] = nil
                setElementAlpha(thePlayer, 255)
                removeElementData(thePlayer, "imortal")
            end, 3000, 1)
        end
        local x, y, z, nome = unpack(teleportes[cmd]) -- Pega as infos desse item da tabela e separa em variáveis.
        setElementPosition(thePlayer, x, y, z, true) -- Teleporta o player.
        -- setElementRotation(thePlayer, 0, 0, 0)
        outputChatBox("[Teleporte] O jogador #ffffff"..getPlayerName(thePlayer).." #FF3C00foi para "..nome..". [/"..cmd.."]", root, 255, 60, 0, true) -- Manda essa mensagem pra todo mundo.
    end
end

for cmd,v in pairs (teleportes) do -- Faz um loop pela tabela, adicionando todos os addCommandHandlers.
    addCommandHandler(cmd, telePlayer)
end

client.lua

addEventHandler ("onClientPlayerDamage", root, function ()
    if getElementData(source, "imortal") then -- Se o jogador que tomou dano tem essa elementData, então cancela o dano e nada acontece.
        cancelEvent()
    end
end)
 
addEventHandler ("onClientPlayerStealthKill", localPlayer, function (targetPlayer)
    if getElementData (targetPlayer, "imortal") then -- Se o jogador que está sendo alvo da facada fatal tiver essa elementData, impede que ele tome a facada e nada acontece.
        cancelEvent()
    end
end)

 

Cara mt obg

to procurando alguns lugares pra estudar um pouco de script, cê, tem alguma recomendação?

  • Moderators
Posted

Eu te ajudei ou achou meu comentário útil? Não esqueça de deixar um Thanksspacer.png

Minhas contribuições para a comunidade: LordHenry - MTA Wiki Profile
Inscreva-se no meu canal do YouTube: Lord Henry - Entertainment
Discord Oficial do MTA: https://mtasa.com/discord
Blacklist e Whitelist de Scripters: Planilha

Por favor, não me envie mensagens privadas solicitando suporte. Crie um tópico no fórum em vez disso.

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