D3vZ Posted February 26, 2014 Share Posted February 26, 2014 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
manawydan Posted February 26, 2014 Share Posted February 26, 2014 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
manawydan Posted February 26, 2014 Share Posted February 26, 2014 na bind use bindKey Link to comment
D3vZ Posted February 26, 2014 Author Share Posted February 26, 2014 Não funcionou, não apresenta erros, mas não fez o que pretendia Link to comment
manawydan Posted February 26, 2014 Share Posted February 26, 2014 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
D3vZ Posted February 26, 2014 Author Share Posted February 26, 2014 @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
manawydan Posted February 26, 2014 Share Posted February 26, 2014 tente meu segundo codigo, mas acho q o seu funfa (nao tenho certeza) Link to comment
D3vZ Posted February 26, 2014 Author Share Posted February 26, 2014 O bindkey não está funcionando, e assim agora não consigo nem abrir nem fechar o portão Link to comment
manawydan Posted February 26, 2014 Share Posted February 26, 2014 pensei q ia funfa, tente usa o timer Link to comment
DNL291 Posted February 26, 2014 Share Posted February 26, 2014 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
D3vZ Posted February 26, 2014 Author Share Posted February 26, 2014 A bindKey não funciona Link to comment
DNL291 Posted February 26, 2014 Share Posted February 26, 2014 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
D3vZ Posted February 26, 2014 Author Share Posted February 26, 2014 Não está funcionando Link to comment
DNL291 Posted February 26, 2014 Share Posted February 26, 2014 Testei o código e está funcionando sem qualquer problema. Link to comment
D3vZ Posted February 26, 2014 Author Share Posted February 26, 2014 Cara me desculpe, realmente tem razão Eu é que tinha mais um gate com o nome "gate1" e ele não deixava que o script funcionasse correctamente Me desculpe cara! Mas obrigado pelo apoio! Vlw! (: Link to comment
DNL291 Posted February 26, 2014 Share Posted February 26, 2014 Sem problemas. De nada. 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