Jump to content

[HELP!] Making Multiple Gates IN one lua Locked to Team


Daz

Recommended Posts

Is it possible to make multiple gates in a single lua

I have tried it and they are interfering with each other and messing up.

Like one gate will teleport to the other etc

:|

If you know how to make multiple gates work in the same lua please help thanks :D

here is the lua I am using

  
-- 1ST GATE VEHICLE SECTION MILITARY BASE. 
col  = createColTube (110.199, 1757.300, 17, 20, 3) -- enter your cooderates here for your colshape please note 10 and 3 is to do with the size of the shape.  
  
door = createObject ( 980, 110.299, 1756.400, 19.399, 0, 0, 90) -- enter the ID of the object followed by the coordinates 
  
-- note the rotx y and z may not be required so you just remove these. x y and z is where you would put your cordinates. 
  
  
  
function Open ( pla ) 
  
    if ( getElementType ( pla ) == "player" ) then 
  
        local team = getPlayerTeam ( pla ) 
  
        local teamName = ( team and getTeamName ( team ) or "" ) 
  
        if ( teamName == "Desert Eagles" ) then 
  
            moveObject ( door, 2200, 110.299, 1756.400, 25.5 ) -- here is where you enter the coordinatess of the new location of the object, 2200 = the speed of the movent. 
  
        end 
  
    end 
  
end 
  
addEventHandler ( "onColShapeHit", col, Open) 
  
  
  
function Close ( pla ) 
  
    if ( getElementType ( pla ) == "player" ) then 
  
        local team = getPlayerTeam ( pla ) 
  
        local teamName = ( team and getTeamName ( team ) or "" ) 
  
        if ( teamName == "Desert Eagles" ) then 
  
            moveObject ( door, 2951, 110.299, 1756.400, 19.399 ) -- here is where you copy the coordinates of the orginal location of the object, 2951 = the timer of movent. 
  
        end 
  
    end 
  
end 
  
addEventHandler ( "onColShapeLeave", col, Close ) 
  
  
------------------------------------------------------------------------------------------------------------------------------------------------ 
  
--2nd Gate 
  
col1  = createColTube (290.600, 1821.400, 17.600, 20, 3) -- enter your cooderates here for your colshape please note 10 and 3 is to do with the size of the shape.  
  
door1 = createObject ( 980, 290.700, 1821.099, 19.399, 0, 0, 89.999) -- enter the ID of the object followed by the coordinates 
  
-- note the rotx y and z may not be required so you just remove these. x y and z is where you would put your cordinates. 
  
  
  
function Open ( pla ) 
  
    if ( getElementType ( pla ) == "player" ) then 
  
        local team = getPlayerTeam ( pla ) 
  
        local teamName = ( team and getTeamName ( team ) or "" ) 
  
        if ( teamName == "Desert Eagles" ) then 
  
            moveObject ( door1, 2200, 290.700, 1821.099, 25.5 ) -- here is where you enter the coordinatess of the new location of the object, 2200 = the speed of the movent. 
  
        end 
  
    end 
  
end 
  
addEventHandler ( "onColShapeHit", col, Open) 
  
  
  
function Close ( pla ) 
  
    if ( getElementType ( pla ) == "player" ) then 
  
        local team = getPlayerTeam ( pla ) 
  
        local teamName = ( team and getTeamName ( team ) or "" ) 
  
        if ( teamName == "Desert Eagles" ) then 
  
            moveObject ( door1, 2951, 290.700, 1821.099, 19.399 ) -- here is where you copy the coordinates of the orginal location of the object, 2951 = the timer of movent. 
  
        end 
  
    end 
  
end 
  
addEventHandler ( "onColShapeLeave", col1, Close ) 
  
  

Edited by Guest
Link to comment
I think an example would be:
  
local cols = { 
{110.199, 1757.300, 17, 20, 3}, 
{110.199, 1757.300, 17, 20, 3} 
} 
for _, v in ipairs(cols) do 
local x,y,z,rad,height = unpack(v) 
createColTube(x,y,z,rad,height) 
end 
  

with this example how would I make it locked to a team like my original lua if you know?

Link to comment
You could store the team that it would be locked for in the table as a string.

Like this ?

  
 if ( getElementType ( pla ) == "player" ) then 
14.  
15.        local team = getPlayerTeam ( pla ) 
16.  
17.        local teamName = ( team and getTeamName ( team ) or "" ) 
18.  
19.        if ( teamName == "Desert Eagles" ) then 
  
  
  

Link to comment
  • MTA Team

I meant storing the name you compare in the table like this:

  
local cols = { 
{"TEAM1",110.199, 1757.300, 17, 20, 3}, 
{"TEAM2",110.199, 1757.300, 17, 20, 3} 
} 

And the unpack would be something like this:

  
for _, v in ipairs(cols) do 
local teamname,x, y, z, rad,height  = unpack ( v ) 
tubes = createColTube(x,y,z,rad,height) 
setElementData(tubes,"team",teamname) 
end 

Link to comment
  • MTA Team

Try something like this...

  
  
local cols = { 
{"Military",110.199, 1757.300, 17, 20, 3}, 
{"TEAM2",110.199, 1757.300, 17, 20, 3}  
} 
  
for _, v in ipairs(cols) do 
  
local name,x, y, z, rad,h  = unpack ( v )  
tubes = createColTube(x, y, z, rad,h)  
  
setElementData(tubes,"team",name) 
  
end 
  
addEventHandler("onMarkerHit",tubes, 
  
function (hit,dim) 
  
if getElementType(hit) == 'player' then 
                                          
local team = getPlayerTeam(hit) 
  
local teamname = getTeamName(team) 
  
if 'Military' == getElementData(source,"team") then 
moveObject ( door, 2200, 110.299, 1756.400, 25.5 ) 
end 
end 
end) 

Link to comment
Try something like this...
  
  
local cols = { 
{"Military",110.199, 1757.300, 17, 20, 3}, 
{"TEAM2",110.199, 1757.300, 17, 20, 3}  
} 
  
for _, v in ipairs(cols) do 
  
local name,x, y, z, rad,h  = unpack ( v )  
tubes = createColTube(x, y, z, rad,h)  
  
setElementData(tubes,"team",name) 
  
end 
  
addEventHandler("onMarkerHit",tubes, 
  
function (hit,dim) 
  
if getElementType(hit) == 'player' then 
                                          
local team = getPlayerTeam(hit) 
  
local teamname = getTeamName(team) 
  
if 'Military' == getElementData(source,"team") then 
moveObject ( door, 2200, 110.299, 1756.400, 25.5 ) 
end 
end 
end) 

'tubes' will only return a colshape, since, it's being stored in a variable. Use a table to store each colshape.

Also, 'onMarkerHit' is called only for markers created using createMarker. Use onColShapeHit instead.

Link to comment

I filled out that template you give me maybe I am putting wrong coordinates for different places

but no gate showed

  
  
local cols = { 
  
{"Military",256.399, 1843.699, 9.899, 20, 3}, 
  
{"TEAM2",256.399, 1843.699, 9.899, 20, 3}  
  
} 
  
  
  
for _, v in ipairs(cols) do 
  
  
  
local name,256.399, 1843.699, 9.899  = unpack ( v )  -----??????? what is this 
  
tubes = createColTube(256.399, 1846.699, 7.900, 5, 3)  
  
  
  
setElementData(tubes,"team",name) 
  
  
  
end 
  
  
  
addEventHandler("onMarkerHit",tubes, 
  
  
  
function (hit,dim) 
  
  
  
if getElementType(hit) == 'player' then 
  
                                          
  
local team = getPlayerTeam(hit) 
  
  
  
local teamname = getTeamName(team) 
  
  
  
if 'Military' == getElementData(source,"team") then 
  
moveObject ( door, 2200, 256.399, 1843.699, 13 ) 
  
end 
  
end 
  
end) 
  

Link to comment

Still no luck :cry:

  
door = createObject ( 3037, 256.399, 1843.699, 9.899, 0, 0, 0) 
  
local cols = { 
  
{"Military",256.399, 1843.699, 9.899, 20, 3}, 
  
{"TEAM2",256.399, 1843.699, 9.899, 20, 3}  
  
} 
  
  
  
for _, v in ipairs(cols) do 
  
  
  
local name,256.399, 1843.699, 9.899  = unpack ( v )  -----??????? what is this 
  
tubes = createColTube(256.399, 1846.699, 7.900, 5, 3)  
  
  
  
setElementData(tubes,"team",name) 
  
  
  
end 
  
  
  
addEventHandler("onMarkerHit",tubes, 
  
  
  
function (hit,dim) 
  
  
  
if getElementType(hit) == 'player' then 
  
                                          
  
local team = getPlayerTeam(hit) 
  
  
  
local teamname = getTeamName(team) 
  
  
  
if 'Military' == getElementData(source,"team") then 
  
moveObject ( door, 2200, 256.399, 1843.699, 13 ) 
  
end 
  
end 
  
end) 

Link to comment
-- team, object model, position and rotation, move to position 
local gates = 
    { 
        { "Desert Eagles", 980, { 110.299, 1756.400, 19.399, 0, 0, 90 }, { 110.299, 1756.400, 25.5 } }, 
        { "Desert Eagles", 980, { 290.700, 1821.099, 19.399, 0, 0, 89.999 }, { 290.700, 1821.099, 25.5 } } 
    } 
local gateData = { } -- A table to store the gates data 
  
addEventHandler ( "onResourceStart", resourceRoot, 
    function ( ) 
        for _, data in ipairs ( gates ) do -- Loop our gates table 
            local team, model, posRot, moveTo = unpack ( data ) -- Unpack the gate data 
            local x, y, z, rx, ry, rz = unpack ( posRot ) -- Unpack the gate position and rotation 
            local mx, my, mz = unpack ( moveTo ) -- Unpack the position to where it has to move 
            local object = createObject ( model, x, y, z, rx, ry, rz ) -- Create the gate object 
            local colshape = createColTube ( x, y, z - 0.5, 20, 3 ) -- Create the gate colshape 
            if ( colshape ) then -- If the colshape was created 
                addEventHandler ( "onColShapeHit", colshape, onGateColshape ) -- Add the event handler for when hit the colshape 
                addEventHandler ( "onColShapeLeave", colshape, onGateColshape ) -- Add the event handler for when leave the colshape 
                gateData [ colshape ] = -- Use the colshape as index to store the gate data 
                    { 
                        object = object, 
                        team = team, 
                        x = x, 
                        y = y, 
                        z = z, 
                        mx = mx, 
                        my = my, 
                        mz = mz 
                    } 
            end 
        end 
    end 
) 
  
function onGateColshape ( hitElement, matchD ) 
    if ( matchD ) then -- If the dimension matches 
        local data = gateData [ source ] -- Get the gate data using the colshape as index ( source ) 
        if ( data ) then -- If there was data 
            local team = getPlayerTeam ( hitElement ) -- Get the player team 
            local teamName = ( team and getTeamName ( team ) or "" ) -- Get the team name 
            if ( teamName == data.team ) then -- If the player team matches the gate team 
                if ( eventName == "onColShapeHit" ) then -- If the event name is 'onColShapeHit' 
                    moveObject ( data.object, 2200, data.mx, data.my, data.mz ) -- Open the gate 
                else -- If the event name is 'onColShapeLeave' 
                    moveObject ( data.object, 2200, data.x, data.y, data.z ) -- Close the gate 
                end 
            end 
        end 
    end 
end 

I added comments so you know what each line does.

Link to comment
-- team, object model, position and rotation, move to position 
local gates = 
    { 
        { "Desert Eagles", 980, { 110.299, 1756.400, 19.399, 0, 0, 90 }, { 110.299, 1756.400, 25.5 } }, 
        { "Desert Eagles", 980, { 290.700, 1821.099, 19.399, 0, 0, 89.999 }, { 290.700, 1821.099, 25.5 } } 
    } 

There you add/remove/change gates.

Link to comment

The only problem im finding is that the colshape is above ground im trying to change the Z coord for it but doesn't make a difference I think the colshape is spawning itself halfway up the Gate./

local colshape = createColTube ( x, y, z - 1, 10, 17 ) -- Create the gate colshape

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