Jump to content

Help with moveObjects() function


Recommended Posts

Hi again, guys.

How you can see, I'm still trying make something with Lua. Yeah, that's hard for me.

I'm trying make a "gate movement". So I maked this code:

  
-- PORTUGUES -- 
-- Nome: AbrePortoes.lua 
-- Funcao: automatiza o movimento de portoes 
-- Autor: Stanley Sathler - Ingame: |MS-13|F|-Sathler 
  
-- ENGLISH -- 
-- Name: OpenGates.lua 
-- Function: automates the movement of gates 
-- Author: Stanley Sathler - Ingame: |MS-13|F|-Sathler 
  
local portao_interior_1 = getElementByID("portao_interior_1") 
local portao_interior_2 = getElementByID("portao_interior_2") 
  
local zona_portao = createColTube(213.0, 1875.0, 12.10, 5.0, 5.0) 
  
function AbrePortao(jogador, na_dimensao) 
    moveObject(portao_interior_1, 3000, 219.899, 1785.59, 12.10) 
    moveObject(portao_interior_2, 3000, 207.699, 1785.59, 12.10) 
end 
addEventHandler("onColShapeHit", zona_portao, AbrePortao) 
  
function FechaPortao(jogador, na_dimensao) 
    moveObject(portao_interior_1, 3000, 216.799, 1785.59, 12.10) 
    moveObject(portao_interior_2, 3000, 211.199, 1785.59, 12.10) 
end 
addEventHandler("onColShapeLeave", zona_portao, FechaPortao) 
  

The objective is move the gate by side (your original position is the same of the indicated on "FechaPortao()" function). But he's moving to the bottom of the map (y position), and not x position. Anyone knows what I do? ):

Thank you for attention,

Stanley Sathler.

Link to comment

Don't listen to tropez,

The problem is that the "getElementByID" function is incorrect,

First you have to make a gate by using "createObject()" and you could use the map editor to help you and save the gates in a file.

after doing this, just copy and paste the gate position and model Id in to the script( the createObject(Model ID, GATE position))

then the gates would start moving after the player hit the colTube.

Link to comment

Don't listen to Jaysds1.

The problem is that Jaysds1 can't read: objects move fine, just not in the right direction. so what is the point of createObject()?

getElementByID() is made for getting elements by ID that is specified in a map file.

code looks good, check gate position values in your map file maybe.

Link to comment

Hey guys, calm down! What is this? This is a forum, a comunnity. :)

-

I've working in the code and I'm right: the gate is moving in y position, and not in x.

I use a getElementPosition for see the inicial position of the gate. And use an outputChatBox() for show the position later of movement. The X is the same of the initial, but the Y is: 1802.511.

I'm lost ):

Link to comment

There is the updated code:

-- PORTUGUES -- 
-- Nome: AbrePortoes.lua 
-- Funcao: automatiza o movimento de portoes 
-- Autor: Stanley Sathler - Ingame: |MS-13|F|-Sathler 
  
-- ENGLISH -- 
-- Name: OpenGates.lua 
-- Function: automates the movement of gates 
-- Author: Stanley Sathler - Ingame: |MS-13|F|-Sathler 
  
local portao_interior_1 = getElementByID("portao_interior_1") 
local portao_interior_2 = getElementByID("portao_interior_2") 
local posX, posY, posZ = getElementPosition(portao_interior_1) 
  
local zona_portao = createColTube(213.0, 1875.0, 12.10, 5.0, 5.0) 
  
function AbrePortao(jogador, na_dimensao) 
    moveObject(portao_interior_1, 5000, 216.80000305176, 1875.5999755859, 12.10000038147) 
    moveObject(portao_interior_2, 5000, 211.19999694824, 1875.5999755859, 12.10000038147) 
    outputChatBox("Local 1: "..posX.." | "..posY.." | "..posZ.."", getRootElement()) 
end 
addEventHandler("onColShapeHit", zona_portao, AbrePortao) 
  
function FechaPortao(jogador, na_dimensao) 
    moveObject(portao_interior_1, 5000, 216.799, 1785.59, 12.10) 
    moveObject(portao_interior_2, 5000, 211.199, 1785.59, 12.10) 
    posX, posY, posZ = getElementPosition(portao_interior_1) 
    outputChatBox("Local 2: "..posX.." | "..posY.." | "..posZ.."", getRootElement())     
end 
addEventHandler("onColShapeLeave", zona_portao, FechaPortao) 
  

NOTE: in this code, later of movement the code takes only portao_interior_1 position (because I won't use this part of the code)

And here, the part of .map with gates objects:

<object id="portao_interior_1" doublesided="true" model="2951" interior="0" dimension="0" posX="216.80000305176" posY="1875.5999755859" posZ="12.10000038147" rotX="0" rotY="0" rotZ="0"></object> 
    <object id="portao_interior_2" doublesided="true" model="2951" interior="0" dimension="0" posX="211.19999694824" posY="1875.5999755859" posZ="12.10000038147" rotX="0" rotY="0" rotZ="0"></object> 
  

Link to comment

eh, judging by the first script posted and a map file, you got your Y position wrong in script.

map file: 1875.5999755859

script: 1785.59

you can drop 0.0099755859, no big deal, im talking about 90 units difference between 1785 and 1875.

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