Jump to content

[Ajuda] Portão


Recommended Posts

Boa Noite :)

Script:

local gate = createObject(975,-210.39,1148.0999755859,21.10000038147, 0, 0, 179.98345947266 ) 
  
function open( player ) 
    local playerName = getPlayerName( player ) 
    outputChatBox("#FFFFFF* #0066FF"..playerName.." #FFFFFFabre o portão",source,255,0,0,true) 
    moveObject(gate, 6000, -217.5,1148.0999755859,21.10000038147, 0, 0, 0 ) 
end 
  
addCommandHandler("abrir", open) 
  
function close( player ) 
    local playerName = getPlayerName( player ) 
    outputChatBox("#FFFFFF* #0066FF"..playerName.." #FFFFFFfecha o portão",source,255,0,0,true) 
    moveObject(gate, 6000, -210.39,1148.0999755859,21.10000038147, 0, 0, 0 ) 
end 
  
addCommandHandler("fechar", close) 
  

O que pretendo?:

- O portão abrir / fechar com range ou seja só quando estiver perto do portão é que o posso abrir, se estiver longe do portão não conseguirei abrir.

- Criar uma bind com o botão direito do MOUSE para abrir/fechar o portão.

Link to comment

tente:

local gate = createObject(975,-210.39,1148.0999755859,21.10000038147, 0, 0, 179.98345947266 ) 
local distanciaMax = 5 -- altere o 5 se quiser 
  
function open( player ) 
local x,y,z = getElementPosition(player) 
local a,b,c = getElementPosition(gate) 
local distancia = getDistanceBetweenPoints3D(x,y,z,a,b,c) 
if (distancia <= distanciaMax) then 
    local playerName = getPlayerName( player ) 
    outputChatBox("#FFFFFF* #0066FF"..playerName.." #FFFFFFabre o portão",source,255,0,0,true) 
    moveObject(gate, 6000, -217.5,1148.0999755859,21.10000038147, 0, 0, 0 ) 
else 
outputChatBox("Você esta muito longe",player) 
end 
 end 
addCommandHandler("abrir", open) 
  
function close( player ) 
local x,y,z = getElementPosition(player) 
local a,b,c = getElementPosition(gate) 
local distancia = getDistanceBetweenPoints3D(x,y,z,a,b,c) 
if (distancia <= distanciaMax) then 
    local playerName = getPlayerName( player ) 
    outputChatBox("#FFFFFF* #0066FF"..playerName.." #FFFFFFfecha o portão",source,255,0,0,true) 
    moveObject(gate, 6000, -210.39,1148.0999755859,21.10000038147, 0, 0, 0 ) 
else 
outputChatBox("Você esta muito longe",player) 
end 
end  
addCommandHandler("fechar", close) 
  

Link to comment

hm tente:

local gate = createObject(975,-210.39,1148.0999755859,21.10000038147, 0, 0, 179.98345947266 ) 
local distanciaMax = 5 -- altere o 5 se quiser 
local Aberto = false 
  
function open( player ) 
local x,y,z = getElementPosition(player) 
local a,b,c = getElementPosition(gate) 
local distancia = getDistanceBetweenPoints3D(x,y,z,a,b,c) 
if (distancia <= distanciaMax) then 
    local playerName = getPlayerName( player ) 
    outputChatBox("#FFFFFF* #0066FF"..playerName.." #FFFFFFabre o portão",source,255,0,0,true) 
    moveObject(gate, 6000, -217.5,1148.0999755859,21.10000038147, 0, 0, 0 ) 
    Aberto = not Aberto 
else 
outputChatBox("Você esta muito longe",player) 
end 
 end 
  
  
function close( player ) 
local x,y,z = getElementPosition(player) 
local a,b,c = getElementPosition(gate) 
local distancia = getDistanceBetweenPoints3D(x,y,z,a,b,c) 
if (distancia <= distanciaMax) then 
    local playerName = getPlayerName( player ) 
    outputChatBox("#FFFFFF* #0066FF"..playerName.." #FFFFFFfecha o portão",source,255,0,0,true) 
    moveObject(gate, 6000, -210.39,1148.0999755859,21.10000038147, 0, 0, 0 ) 
        Aberto = not Aberto 
else 
outputChatBox("Você esta muito longe",player) 
end 
end 
  
function troca(p) 
if (Aberto) then 
close(p) 
else 
open(p) 
end 
end 
  
  
addEventHandler("onResourceStart",resourceRoot, 
function() 
-- se n funfa use um timer: setTimer(function(), 
for k,v in ipairs(getElementsByType("player")) 
do 
bindKey(v,"mouse1","down",troca) 
-- end,1000,1) 
end  
 end) 

Link to comment

@manawydan Desculpe cara o primeiro código funcionou, eu é que me esqueci de dar restart no resource, desculpe!

Eu tentei este script para usar bindkey:

local gate = createObject(975,-210.39,1148.0999755859,21.10000038147, 0, 0, 179.98345947266 ) 
local distanciaMax = 6 -- altere o 5 se quiser 
  
function open( player ) 
local x,y,z = getElementPosition(player) 
local a,b,c = getElementPosition(gate) 
local distancia = getDistanceBetweenPoints3D(x,y,z,a,b,c) 
if (distancia <= distanciaMax) then 
    local playerName = getPlayerName( player ) 
    outputChatBox("#FFFFFF* #0066FF"..playerName.." #FFFFFFabre o portão",source,255,0,0,true) 
    moveObject(gate, 6000, -217.5,1148.0999755859,21.10000038147, 0, 0, 0 ) 
else 
outputChatBox("Você esta muito longe",player) 
end 
 end 
addCommandHandler("abrir", open) 
  
function close( player ) 
local x,y,z = getElementPosition(player) 
local a,b,c = getElementPosition(gate) 
local distancia = getDistanceBetweenPoints3D(x,y,z,a,b,c) 
if (distancia <= distanciaMax) then 
    local playerName = getPlayerName( player ) 
    outputChatBox("#FFFFFF* #0066FF"..playerName.." #FFFFFFfecha o portão",source,255,0,0,true) 
    moveObject(gate, 6000, -210.39,1148.0999755859,21.10000038147, 0, 0, 0 ) 
else 
outputChatBox("Você esta muito longe",player) 
end 
end 
addCommandHandler("fechar", close) 
  
function thisResourceStart () 
    local players = getElementsByType ( "player" ) 
    for _,this_player in ipairs(players) do 
        bindKey ( this_player, "mouse2", "down", open, close ) 
    end 
end 
addEventHandler ("onResourceStart", resourceRoot, thisResourceStart) 

Link to comment

Tente isto:

local gate = createObject(975,-210.39,1148.0999755859,21.10000038147, 0, 0, 179.98345947266 ) 
local distanciaMax = 12 -- altere o 5 se quiser 
  
local openState = false 
function open( player ) 
local x,y,z = getElementPosition(player) 
local a,b,c = getElementPosition(gate) 
local distancia = getDistanceBetweenPoints3D(x,y,z,a,b,c) 
    if (distancia <= distanciaMax) then 
        if (openState == false) then 
            local playerName = getPlayerName( player ) 
            outputChatBox("#FFFFFF* #0066FF"..playerName.." #FFFFFFabre o portão",player,255,0,0,true) 
            moveObject(gate, 6000, -217.5,1148.0999755859,21.10000038147, 0, 0, 0 ) 
            openState = true 
        else 
            outputChatBox("O portão já está aberto",player, 225, 0, 0) 
        end 
    else 
        outputChatBox("Você esta muito longe",player, 225, 0, 0) 
    end 
end 
  
addEventHandler( "onResourceStart", resourceRoot, 
    function () 
        for _,player in ipairs(getElementsByType"player") do 
            bindKey(player, "mouse2", "down", open) 
            bindKey(player, "mouse2", "down", close) 
        end 
    end 
) 
  
addEventHandler( "onPlayerJoin", root, 
    function () 
        for _,player in ipairs(getElementsByType"player") do 
            bindKey(player, "mouse2", "down", open) 
            bindKey(player, "mouse2", "down", close) 
        end 
    end 
) 
  
function close( player ) 
local x,y,z = getElementPosition(player) 
local a,b,c = getElementPosition(gate) 
local distancia = getDistanceBetweenPoints3D(x,y,z,a,b,c) 
    if (distancia <= distanciaMax) then 
        if (openState == true) then 
            local playerName = getPlayerName( player ) 
            outputChatBox("#FFFFFF* #0066FF"..playerName.." #FFFFFFfecha o portão",player,255,0,0,true) 
            moveObject(gate, 6000, -210.39,1148.0999755859,21.10000038147, 0, 0, 0 ) 
            openState = false 
        else 
            outputChatBox("O portão já está fechado",player, 225, 0, 0) 
        end 
    else 
        outputChatBox("Você esta muito longe",player, 225, 0, 0) 
    end 
end 
  

Link to comment
local gate = createObject(975,-210.39,1148.0999755859,21.10000038147, 0, 0, 179.98345947266 ) 
local distanciaMax = 12 -- altere o 5 se quiser 
  
function open( player ) 
local x,y,z = getElementPosition(player) 
local a,b,c = getElementPosition(gate) 
local distancia = getDistanceBetweenPoints3D(x,y,z,a,b,c) 
    if (distancia <= distanciaMax) then 
        local playerName = getPlayerName( player ) 
        outputChatBox("#FFFFFF* #0066FF"..playerName.." #FFFFFFabre o portão",player,255,0,0,true) 
        moveObject(gate, 6000, -217.5,1148.0999755859,21.10000038147, 0, 0, 0 ) 
        bindKey(player, "mouse2", "down", close) 
        unbindKey(player, "mouse2", "down", open) 
    else 
        outputChatBox("Você esta muito longe",player, 225, 0, 0) 
    end 
end 
  
addEventHandler( "onResourceStart", resourceRoot, 
    function () 
        for _,player in ipairs(getElementsByType"player") do 
            bindKey(player, "mouse2", "down", open) 
        end 
    end 
) 
  
addEventHandler( "onPlayerJoin", root, 
    function () 
        for _,player in ipairs(getElementsByType"player") do 
            bindKey(player, "mouse2", "down", open) 
        end 
    end 
) 
  
function close( player ) 
local x,y,z = getElementPosition(player) 
local a,b,c = getElementPosition(gate) 
local distancia = getDistanceBetweenPoints3D(x,y,z,a,b,c) 
    if (distancia <= distanciaMax) then 
        local playerName = getPlayerName( player ) 
        outputChatBox("#FFFFFF* #0066FF"..playerName.." #FFFFFFfecha o portão",player,255,0,0,true) 
        moveObject(gate, 6000, -210.39,1148.0999755859,21.10000038147, 0, 0, 0 ) 
        bindKey(player, "mouse2", "down", open) 
        unbindKey(player, "mouse2", "down", close) 
    else 
        outputChatBox("Você esta muito longe",player, 225, 0, 0) 
    end 
end 

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