sUp5rET.png

Help! My gate request isn't getting done!

Chaoss

The real MVP
Scripted gates are a perk that we offer to players that show support to MTA:RP through donation. Therefore we charge VIP Points for gates to be added to the server.

Our current gate scripter is MTA | Legend(dsmoked), as you can see these requests are not being completed in a timely matter. On behalf of the staff here at MTA:RP we apologize for any inconvenience this may have caused you. We want all of our players to get the quality service that they so deserve, which is why I will be looking for another person that has knowledge on gate scripting.

Don't know how to script gates? I have included a lua file that has details on how to make them. You simply need to fill in the blanks for the gates.
This is a example from a gate on Richmond. Everything with "--" is commented out and there to help you understand how it works.
Code:
local objectID = 980 --Place the object ID here
local originalX,originalY,originalZ = 282.39999389648,-1319.9000244141,55.639999389648 --Place the coords of the gate here
local rotationX,rotationY,rotationZ = 0,358.70007324219,34.5 --Place the rotations of the gate here

local moveX,moveY,moveZ = 282.39999389648,-1319.9000244141,50 --Place the coords to move the gate to here
local moveRotX,moveRotY,moveRotZ = 0,0,0 --Place the rotations for the gate here (if you do not want it to rotate, put: 0,0,0)

local keyID = 576 --Put the ID of the house here! Note: This only works for houses, not for bussinesses

local timeToMoveGate = 2000 --Put the time it takes to open/close the gate here (in milliseconds)
local timeToStayOpen = 4000 --Put the time that the gate stays open until it closes (in milliseconds)

local command = "gate" --Put the command name you want to use here
local distanceFromGate = 25 --Put the minimal distance from the gate to open it here

--#######################################################
--####   DO NOT EDIT ANYTHING BELOW HERE             ####
--#######################################################
local gateState = false --Leave this at false, you don't need to edit this

thisGate = createObject(objectID,originalX,originalY,originalZ,rotationX,rotationY,rotationZ) --Creates the object and names it 'thisGate'

exports.pool:allocateElement(thisGate) --Let's just leave this here, okay?

local function resetGateState() --Function to reset the state of the gate
	gateState = false --Sets the gate state to closed
end

local function closeThisGate() --Function to close the gate
	moveObject(thisGate,timeToMoveGate,originalX,originalY,originalZ,0 - moveRotX,0 - moveRotY,0 - moveRotZ) --Moves the gate back to the original position
	setTimer(resetGateState,timeToStayOpen,timeToMoveGate) --Resets the state of the gate after the gate has moved back to it's original position
end

local function useGate(thePlayer, commandName) --Function that triggers the gate
	local posX,posY,posZ = getElementPosition(thePlayer) --Gets the position of the gate
	local distance = getDistanceBetweenPoints3D(originalX,originalY,originalZ,posX,posY,posZ) --Gets the distance between the player and the original position of the gate
	
	if(distance <= distanceFromGate and gateState == false and exports.global:hasItem(thePlayer, 4, keyID)) then --Checks if the player is near enough and if the gate is not open/opening/closing
		gateState = false --Sets the gate to open/opening/closing
		moveObject(thisGate,timeToMoveGate,moveX,moveY,moveZ,moveRotX,moveRotY,moveRotZ) --Moves the object to the location that is wanted
		setTimer(closeThisGate,timeToMoveGate + timeToStayOpen,1) --Sets the times to close the gate again
	end
end
addCommandHandler(command, useGate)

If you are interested in helping out with gates you can send me a PM here on the forums. But make sure you know what you are doing before talking to me about it. Test your scripts locally first!

I don't have time to go through all the gate requests myself, so that's why I am spending the time to help you understand how they are done. If you have questions you can reply below and I will get to answering them. Chances are, someone else has the same question to ask.

Thanks for reading.
 

Penguin

Donator
Donator
How would i make a gate that stays open until i close it? Also, I would like to make it so two gates to open at the same time.
 

Chaoss

The real MVP
How would i make a gate that stays open until i close it? Also, I would like to make it so two gates to open at the same time.

Good question!
Code:
local objGateh1 = createObject(975, 1803.0999755859, -1721.8000488281, 14.199999809265, 0, 0, 180)
local objGateh2 = createObject(975, 1761.0999755859, -1699.0999755859, 14.10000038147, 0, 0, 90)

local open = false
local which = 0
local function resetOpenState()
	open = false
end

local function closedoor()
	setTimer(resetOpenState, 3000, 1)
	if (which==1) then
		moveObject(objGateh1, 3000, 1803.0999755859, -1721.8000488281, 14.199999809265, 0, 0, 0)
	elseif (which==2) then
		moveObject(objGateh2, 3000, 1761.0999755859, -1699.0999755859, 14.10000038147, 0, 0, 0)
	end
end

local function useGate(thePlayer, commandName, ...)
	local x, y, z = getElementPosition(thePlayer)
	local distance = getDistanceBetweenPoints3D(1803.0999755859, -1721.8000488281, 14.199999809265, x, y, z)
	local distance1 = getDistanceBetweenPoints3D(1761.0999755859, -1699.0999755859, 14.10000038147, x, y, z)
	local password = table.concat({...})
	
	if (distance <= 20) and (open == false) then
		which = 1
		open = true
		moveObject(objGateh1, 3000, 1795.0999755859, -1721.8000488281, 14.199999809265, 0, 0, 0)
		setTimer(closedoor, 7000, 1)
	elseif (distance1 <= 20) and (open == false) then
		which = 2
		open = true
		moveObject(objGateh2, 3000, 1761.0999755859, -1694.0999755859, 14.10000038147, 0, 0, 0)
		setTimer(closedoor, 7000, 1)
	end
end
addCommandHandler("gate", useGate)
That code makes multiple gates and open/closes them on a timer. If you do not want a timer to close you can change it to this:
Code:
local objGateh1 = createObject(975, 1803.0999755859, -1721.8000488281, 14.199999809265, 0, 0, 180) 
local objGateh2 = createObject(975, 1761.0999755859, -1699.0999755859, 14.10000038147, 0, 0, 90)

local open = false
local which = 0
local function resetOpenState()
	open = false
end

local function closedoor()
	setTimer(resetOpenState, 3000, 1)
	if (which==1) then
		moveObject(objGateh1, 3000, 1803.0999755859, -1721.8000488281, 14.199999809265, 0, 0, 0)
	elseif (which==2) then
		moveObject(objGateh2, 3000, 1761.0999755859, -1699.0999755859, 14.10000038147, 0, 0, 0)
	end
end

local function useGate(thePlayer, commandName, ...)
	local x, y, z = getElementPosition(thePlayer)
	local distance = getDistanceBetweenPoints3D(1803.0999755859, -1721.8000488281, 14.199999809265, x, y, z)
	local distance1 = getDistanceBetweenPoints3D(1761.0999755859, -1699.0999755859, 14.10000038147, x, y, z)
	local password = table.concat({...})
	
	if (distance <= 20) and (open == false) then
		which = 1
		open = true
		moveObject(objGateh1, 3000, 1795.0999755859, -1721.8000488281, 14.199999809265, 0, 0, 0)
    elseif (distance <= 20) and (open == true) then
        closedoor()
	elseif (distance1 <= 20) and (open == false) then
		which = 2
		open = true
		moveObject(objGateh2, 3000, 1761.0999755859, -1694.0999755859, 14.10000038147, 0, 0, 0)
    elseif (distance1 <= 20) and (open == true) then
                closedoor()
	end
end
addCommandHandler("gate", useGate)
That will open both doors with /gate and keep them open until you do the command again.
Notice how the script checks if open = true. That will check if the gate is open and if it is, it will close it. Fairly simple
 

Mach2

Server Supervisor
Staff member
Server Supervisor
I have it down, but how do I get my X, Y, Z on a local server?
 

Mach2

Server Supervisor
Staff member
Server Supervisor
And the Rotation, but on local servers, I don't have house IDs so I will figure that out later.
 

MTA|Legend

Donator
Donator
Blah I'm sorry about this problem lately. I have been having trouble with Notepad++ and other Software on my computer. I have to wait until my Internet get's cut on, because if I try to download it now using my phone it would usually take the minimum of 56 hours... not including that my computer does Random Updates. So sorry that I haven't told you all this.
 
sUp5rET.png
Top