Jump to content

Ayuda con este script!


Matty

Recommended Posts

Bueno... Holas, hice este simple script de abrir una reja con la ayuda de la wiki de mta.. pero nose como hacer para que la reja vuelva a su posicion inicial.. aca el code:

function gate() 
  gatec1 = createObject(7017, 1521.6103515625, 1789.4267578125, 7.57905626297, 0, 90, 0) 
end 
  
function move () 
  moveObject(gatec1, 4000, 1527.1838378906, 1789.4267578125, 7.57905626297, 0, 0, 0) 
end 
  
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), gate) 
addCommandHandler ( "abrir", move ) 

la posición inicial seria la de gatec1

Apenas estoy aprendiendo a manejarme con estas cosas... Espero que me den una ayudita :D

Link to comment
function gate() 
  gatec1 = createObject(7017, 1521.6103515625, 1789.4267578125, 7.57905626297, 0, 90, 0) 
end 
  
function move () 
  moveObject(gatec1, 4000, 1527.1838378906, 1789.4267578125, 7.57905626297, 0, 0, 0) 
end 
  
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), gate) 
addCommandHandler ( "abrir", move ) 
  
  
addCommandHandler ( "cerrar", function() 
moveObject(gatec1, 4000, 1521.6103515625, 1789.4267578125, 7.57905626297, 0, 90, 0) 
end 
) 

C:

Link to comment

creo que asi no me manejo mucho con los timers, proba esto :

function gate() 
  gatec1 = createObject(7017, 1521.6103515625, 1789.4267578125, 7.57905626297, 0, 90, 0) 
end 
  
function move () 
  moveObject(gatec1, 4000, 1527.1838378906, 1789.4267578125, 7.57905626297, 0, 0, 0) 
setTimer(cerrar,3000,1) 
end 
  
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), gate) 
addCommandHandler ( "abrir", move ) 
  
  
function cerrar() 
moveObject(gatec1, 4000, 1521.6103515625, 1789.4267578125, 7.57905626297, 0, 90, 0) 
end 
  

Link to comment
gatec1 = createObject(7017, 1521.6103515625, 1789.4267578125, 7.57905626297, 0, 90, 0) 
gatec1marker = createMarker ( 1521.6103515625, 1789.4267578125, 7.57905626297,'cylinder', 15, 0, 0, 255, 0) 
  
function open(hitPlayer) 
  moveObject (gatec1, 4000, 1527.1838378906, 1789.4267578125, 7.57905626297) 
end 
addEventHandler("onMarkerHit",gatec1marker , open) 
  
function close(hitPlayer) 
  moveObject (gatec1,3000,1521.6103515625, 1789.4267578125, 7.57905626297) 
end 
addEventHandler ("onMarkerLeave",gatec1marker,close) 

prueba esto y si te gusta. Con marcadores. Nomas editale el tamaño del marker

Link to comment
gatec1 = createObject(7017, 1521.6103515625, 1789.4267578125, 7.57905626297, 0, 90, 0) 
gatec1marker = createMarker ( 1521.6103515625, 1789.4267578125, 7.57905626297,'cylinder', 15, 0, 0, 255, 0) 
  
function open(hitPlayer) 
  moveObject (gatec1, 4000, 1527.1838378906, 1789.4267578125, 7.57905626297) 
end 
addEventHandler("onMarkerHit",gatec1marker , open) 
  
function close(hitPlayer) 
  moveObject (gatec1,3000,1521.6103515625, 1789.4267578125, 7.57905626297) 
end 
addEventHandler ("onMarkerLeave",gatec1marker,close) 

prueba esto y si te gusta. Con marcadores. Nomas editale el tamaño del marker

Gracias @Yakuza357 por tu respuesta... Pero ahora busco como hacerle para que el cmd funcione solo serca de la reja ;)

Link to comment
  
gatec1 = createObject(7017, 1521.6103515625, 1789.4267578125, 7.57905626297, 0, 90, 0) 
gatec1marker = createMarker ( 1521.6103515625, 1789.4267578125, 7.57905626297,'cylinder', 15, 0, 0, 255, 0) 
  
function abrir() 
moveObject (gatec1, 4000, 1527.1838378906, 1789.4267578125, 7.57905626297) 
end 
  
function open(hitPlayer) 
  addCommandHandler("abrir",abrir) 
end 
addEventHandler("onMarkerHit",gatec1marker , open) 

proba esto.

Link to comment

Creo que seria haci

gatec1 = createObject(7017, 1521.6103515625, 1789.4267578125, 7.57905626297, 0, 90, 0) 
gatec1marker = createMarker ( 1521.6103515625, 1789.4267578125, 7.57905626297,'cylinder', 15, 0, 0, 255, 0) 
  
function abrir() 
moveObject (gatec1, 4000, 1527.1838378906, 1789.4267578125, 7.57905626297) 
end 
  
function open(hitPlayer) 
  addCommandHandler("abrir",abrir) 
end 
addEventHandler("onMarkerHit",getRootElement(),open) 

Link to comment

No entendi muy bien lo que quisistes hacer pero proba haci

gatec1 = createObject(7017, 1521.6103515625, 1789.4267578125, 7.57905626297, 0, 90, 0) 
gatec1marker = createMarker ( 1521.6103515625, 1789.4267578125, 7.57905626297,'cylinder', 15, 0, 0, 255, 0) 
  
function abrir() 
moveObject (gatec1, 4000, 1527.1838378906, 1789.4267578125, 7.57905626297) 
end 
  
function open(hitPlayer) 
  addCommandHandler("abrir",abrir) 
end 
addEventHandler("onMarkerHit",getRootElement(),abrir) 

Link to comment
gatec1 = createObject(7017, 1521.6103515625, 1789.4267578125, 7.57905626297, 0, 90, 0) 
  
  
  
addEventHandler( "onElementClicked", resourceRoot, 
function( button, state, player ) 
    if button == "left" and state == "up" then 
        local x, y, z = getElementPosition( player ) 
        if getDistanceBetweenPoints3D( x, y, z, getElementPosition( source ) ) < 5 and getElementDimension( player ) == getElementDimension( source ) then 
        moveObject (gatec1, 4000, 1527.1838378906, 1789.4267578125, 7.57905626297) 
        end 
    end 
end 
) 

Mira esto no se si te servira pero se mueve la puerta cuando el persona esta cerca de ella y presiona encima de ella con el boton izquierdo del rato espero que te sirva.

Link to comment
gatec1 = createObject(7017, 1521.6103515625, 1789.4267578125, 7.57905626297, 0, 90, 0) 
gatec1marker = createMarker ( 1521.6103515625, 1789.4267578125, 7.57905626297,'cylinder', 15, 0, 0, 255, 0) 
  
function enablecommand (hitPlayer) 
if (hitPlayer == gatec1maker) then 
addCommandHandler("open",open) 
end 
end 
addEventHandler("onMarkerHit",gatec1marker , enablecommand) 
function disablecommand(hitPlayer) 
  removeEventHandler("onMarkerHit",gatec1marker , enablecommand) 
end 
addEventHandler ("onMarkerLeave",gatec1marker,disablecommand) 
  
function open() 
  moveObject (gatec1, 4000, 1527.1838378906, 1789.4267578125, 7.57905626297) 
end 
  
function close(hitPlayer) 
  moveObject (gatec1,3000,1521.6103515625, 1789.4267578125, 7.57905626297) 
end 
addEventHandler ("onMarkerLeave",gatec1marker,close) 

Nose si funcione pero intenta

Link to comment

Ya lo arregle, este es de comando y hay otros que se abren automáticamente con un marker invisible, como la de Yakuza357.

door = createObject (7017, 1521.6103515625, 1789.4267578125, 7.57905626297, 0, 90, 0 ) 
  
function opendoor() 
  
moveObject (door,  4000, 1527.1838378906, 1789.4267578125, 7.57905626297, 0, 0, 0) 
end 
  
addCommandHandler("abrir", opendoor) 
  
function closedoor() 
  
moveObject (7017, 1521.6103515625, 1789.4267578125, 7.57905626297, 0, 90, 0) 
end 
  
addCommandHandler("cerrar", closedoor) 

Link to comment
Ya lo arregle, este es de comando y hay otros que se abren automáticamente con un marker invisible, como la de Yakuza357.
door = createObject (7017, 1521.6103515625, 1789.4267578125, 7.57905626297, 0, 90, 0 ) 
  
function opendoor() 
  
moveObject (door,  4000, 1527.1838378906, 1789.4267578125, 7.57905626297, 0, 0, 0) 
end 
  
addCommandHandler("abrir", opendoor) 
  
function closedoor() 
  
moveObject (7017, 1521.6103515625, 1789.4267578125, 7.57905626297, 0, 90, 0) 
end 
  
addCommandHandler("cerrar", closedoor) 

@JuegosPato No es eso lo que buscaba pero gracias por tomarte el tiempo.

Gracias a los que me ayudaron y a la Wiki de MTA pude lograr que el cmd de abrir la reja funcione solo de serca.

El code:

gatec1 = createObject(7017, 1521.6103515625, 1789.4267578125, 7.57905626297, 0, 90, 0) 
gatec1marker = createMarker ( 1521.6103515625, 1789.4267578125, 7.57905626297,'cylinder', 15, 0, 0, 255, 100) 
  
  
function enablecommand (hitPlayer) 
if (hitPlayer) then 
 addCommandHandler("open",open) 
end 
end 
addEventHandler("onMarkerHit",gatec1marker , enablecommand) 
  
  
function disablecommand(leaveElement) 
if (leaveElement) then 
  removeEventHandler("onMarkerHit",gatec1marker , enablecommand) 
end 
end 
addEventHandler ("onMarkerLeave",gatec1marker,disablecommand) 
  
function open() 
  moveObject (gatec1, 4000, 1527.1838378906, 1789.4267578125, 7.57905626297) 
end 

Solo faltaría que se cierre automáticamente como en este code:

function gate() 
  gatec1 = createObject(7017, 1521.6103515625, 1789.4267578125, 7.57905626297, 0, 90, 0) 
end 
  
function move () 
  moveObject(gatec1, 4000, 1527.1838378906, 1789.4267578125, 7.57905626297, 0, 0, 0) 
setTimer(cerrar,3000,1) 
end 
  
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), gate) 
addCommandHandler ( "abrir", move ) 
  
  
function cerrar() 
moveObject(gatec1, 4000, 1521.6103515625, 1789.4267578125, 7.57905626297, 0, 90, 0) 
end 
  

echo por @ElMota

Link to comment
gatec1 = createObject(7017, 1521.6103515625, 1789.4267578125, 7.57905626297, 0, 90, 0) 
gatec1marker = createMarker ( 1521.6103515625, 1789.4267578125, 7.57905626297,'cylinder', 15, 0, 0, 255, 100) 
  
  
function enablecommand (hitPlayer) 
if (hitPlayer) then 
 addCommandHandler("open",open) 
end 
end 
addEventHandler("onMarkerHit",gatec1marker , enablecommand) 
  
  
function disablecommand(leaveElement) 
if (leaveElement) then 
  removeEventHandler("onMarkerHit",gatec1marker , enablecommand) 
end 
end 
addEventHandler ("onMarkerLeave",gatec1marker,disablecommand) 
  
function open() 
  moveObject (gatec1, 4000, 1527.1838378906, 1789.4267578125, 7.57905626297) 
  setTimer(autoclose, 5000, 1) 
end 
  
function autoclose () 
  moveObject (gatec1, 1521.6103515625, 1789.4267578125, 7.57905626297, 0, 90, 0) 
end 

Link to comment
function disablecommand(leaveElement) 
if (leaveElement) then 
  removeCommandHandler ( "open", leaveElement ) 
end 
end 
addEventHandler ("onMarkerLeave",gatec1marker,disablecommand) 

Coloca esto en vez del otro que había.

Juaass...Me funco, gracias @Alexs_Steel y a todos los que me ayudaron y respondieron...

Link to comment
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...