Jump to content

[Help] Multi Gate Map.


Recommended Posts

Hi , I hope you all doing well ! 


I am working on Jail System , I've created a map, and the map contained a 22 cells 

So, I want to know the efficient way to make those gates open and closed with a bind key .
 

---------------------------------------------Jail Gates-------------------------------------------------------------------
local Gate1  = createObject ( 2930, 3433.6999511719,-2461,2.9000000953674,  0, 0, 90) setElementDimension (Gate1,3)
local Gate2  = createObject ( 2930, 3428.6000976562,-2461,2.9000000953674,  0, 0, 90 ) setElementDimension (Gate2,3)
local Gate3  = createObject ( 2930, 3423.6000976562,-2461,2.9000000953674,  0, 0, 90 ) setElementDimension (Gate3,3)
local Gate4  = createObject ( 2930, 3418.6000976562,-2461,2.9000000953674,  0, 0, 90 ) setElementDimension (Gate4,3)
local Gate5  = createObject ( 2930, 3413.6000976562,-2461,2.9000000953674,  0, 0, 90 ) setElementDimension (Gate5,3)
local Gate6  = createObject ( 2930, 3408.6000976562,-2461,2.9000000953674,  0, 0, 90 ) setElementDimension (Gate6,3)
local Gate7  = createObject ( 2930, 3403.6000976562,-2461,2.9000000953674,  0, 0, 90 ) setElementDimension (Gate7,3)
local Gate8  = createObject ( 2930, 3398.6000976562,-2461,2.9000000953674,  0, 0, 90 ) setElementDimension (Gate8,3)
--
local Gate9  = createObject ( 2930, 3394.1000976562,-2463.5,2.9000000953674,  0, 0, 125 ) setElementDimension (Gate9,3)
--
local Gate10 = createObject ( 2930, 3393.3000488281,-2466.3999023438,2.9000000953674,  0, 0, 0 ) setElementDimension (Gate10,3)
local Gate11 = createObject ( 2930, 3393.3999023438,-2471.1000976562,2.9000000953674,  0, 0, 0 ) setElementDimension (Gate11,3)
local Gate12 = createObject ( 2930, 3393.3999023438,-2476,2.9000000953674,  0, 0, 0 ) setElementDimension (Gate12,3)
local Gate13 = createObject ( 2930, 3393.3999023438,-2481.1000976562,2.9000000953674,  0, 0, 0 ) setElementDimension (Gate13,3)
--
local Gate14 = createObject ( 2930, 3393.8999023438,-2485.8999023438,2.9000000953674,  0, 0, 48 ) setElementDimension (Gate14,3)
--
local Gate15 = createObject ( 2930, 3398,-2488,2.9000000953674,  0, 0, -270 ) setElementDimension (Gate15,3)
local Gate16 = createObject ( 2930, 3403.1000976562,-2488,2.9000000953674,  0, 0, -270 ) setElementDimension (Gate16,3)
local Gate17 = createObject ( 2930, 3408.1999511719,-2488,2.9000000953674,  0, 0, -270 ) setElementDimension (Gate17,3)
local Gate18 = createObject ( 2930, 3413.3000488281,-2488,2.9000000953674,  0, 0, -270 ) setElementDimension (Gate18,3)
local Gate19 = createObject ( 2930, 3418.3999023438,-2488,2.9000000953674,  0, 0, -270 ) setElementDimension (Gate19,3)
local Gate20 = createObject ( 2930, 3423.5,-2488,2.9000000953674,  0, 0, -270 ) setElementDimension (Gate20,3)
local Gate21 = createObject ( 2930, 3428.6000976562,-2488,2.9000000953674,  0, 0, -270 ) setElementDimension (Gate21,3)
local Gate22 = createObject ( 2930, 3433.6999511719,-2488,2.9000000953674,  0, 0, -270 ) setElementDimension (Gate22,3)
-------------------------------------------------------------------------------------------------------------------------

also another thing , how could I reduce the https://wiki.multitheftauto.com/wiki/SetElementDimension into only one function .

 

if any one have a suggestion please kindly reply .

Regards .
 

Link to comment

Hi, this is how I'd do it:

 

local GatesData = { -- Create a table with all data for later use, also it looks cleaner :)
	{2930, 3433.6999511719,-2461,2.9000000953674, 0, 0, 90},
	{2930, 3428.6000976562,-2461,2.9000000953674, 0, 0, 90},
	{2930, 3423.6000976562,-2461,2.9000000953674, 0, 0, 90},
	{2930, 3418.6000976562,-2461,2.9000000953674, 0, 0, 90},
	{2930, 3413.6000976562,-2461,2.9000000953674, 0, 0, 90},
	{2930, 3408.6000976562,-2461,2.9000000953674, 0, 0, 90},
	{2930, 3403.6000976562,-2461,2.9000000953674, 0, 0, 90},
	{2930, 3398.6000976562,-2461,2.9000000953674, 0, 0, 90},
	{2930, 3394.1000976562,-2463.5,2.9000000953674, 0, 0, 125},
	{2930, 3393.3000488281,-2466.3999023438,2.9000000953674, 0, 0, 0},
	{2930, 3393.3999023438,-2471.1000976562,2.9000000953674, 0, 0, 0},
	{2930, 3393.3999023438,-2476,2.9000000953674, 0, 0, 0},
	{2930, 3393.3999023438,-2481.1000976562,2.9000000953674, 0, 0, 0},
	{2930, 3393.8999023438,-2485.8999023438,2.9000000953674, 0, 0, 48},
	{2930, 3398,-2488,2.9000000953674, 0, 0, -270},
	{2930, 3403.1000976562,-2488,2.9000000953674, 0, 0, -270},
	{2930, 3408.1999511719,-2488,2.9000000953674, 0, 0, -270},
	{2930, 3413.3000488281,-2488,2.9000000953674, 0, 0, -270},
	{2930, 3418.3999023438,-2488,2.9000000953674, 0, 0, -270},
	{2930, 3423.5,-2488,2.9000000953674, 0, 0, -270},
	{2930, 3428.6000976562,-2488,2.9000000953674, 0, 0, -270},
	{2930, 3433.6999511719,-2488,2.9000000953674, 0, 0, -270}
};

local JailGates = {}; -- This table we'll store 'gates' later

for i = 1, #GatesData do -- iterate through data to create gates
	local model,x,y,z,rx,ty,rz = unpack(GatesData[i]); --gather data
	local obj = createObject(model,x,y,z,rx,ty,rz); --crate object
	JailGates[#JailGates + 1] = obj; --store the object for later use 
	setElementDimension(obj, 3);
end

addCommandHandler("open", function()
	for i = 1, #JailGates do --iterate through gates 
		local rx, ry, rz = getElementRotation(JailGates[i]); --get the current rotation of the object 
		setElementRotation(JailGates[i], rx, ry, rz + 90); --turn the gates 90°, NOTE that this may not fit correctlly for every gate so you may have to do a workaround like different tables
	end
end);

This is not tested but it should work ;)

Edited by Tekken
typos :)
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...