Daz Posted January 27, 2014 Share Posted January 27, 2014 (edited) 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 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 January 28, 2014 by Guest Link to comment
Castillo Posted January 27, 2014 Share Posted January 27, 2014 I suggest you to make a table with them, then loop the table and create gates and colshapes. Link to comment
MTA Team 0xCiBeR Posted January 27, 2014 MTA Team Share Posted January 27, 2014 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 Link to comment
Daz Posted January 27, 2014 Author Share Posted January 27, 2014 Ok I am very knew to this so I need to make a table that loops ?? would this still follow the same layout you helped me with for the gates locked to teams. Link to comment
Daz Posted January 27, 2014 Author Share Posted January 27, 2014 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
MTA Team 0xCiBeR Posted January 27, 2014 MTA Team Share Posted January 27, 2014 You could store the team that it would be locked for in the table as a string. Link to comment
Daz Posted January 27, 2014 Author Share Posted January 27, 2014 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 0xCiBeR Posted January 27, 2014 MTA Team Share Posted January 27, 2014 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
Daz Posted January 28, 2014 Author Share Posted January 28, 2014 Hi im sorry I don't understand can somebody show me an example of 2 gates (locked to team)in the same lua. And which bits I should change thank you if anyone can Link to comment
MTA Team 0xCiBeR Posted January 28, 2014 MTA Team Share Posted January 28, 2014 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
DNL291 Posted January 28, 2014 Share Posted January 28, 2014 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
Daz Posted January 28, 2014 Author Share Posted January 28, 2014 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
MTA Team 0xCiBeR Posted January 28, 2014 MTA Team Share Posted January 28, 2014 That's because in my script i asumed you already created the doors. You have to create them using createObject Link to comment
Daz Posted January 28, 2014 Author Share Posted January 28, 2014 Still no luck 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
MTA Team 0xCiBeR Posted January 28, 2014 MTA Team Share Posted January 28, 2014 Change the event to onColShapeHit as suggested by DNL and store every colShape into a table. Link to comment
Daz Posted January 28, 2014 Author Share Posted January 28, 2014 a Looping table? because I can see a guide on youtube for that otherwise I don't really know what im doing Link to comment
Castillo Posted January 28, 2014 Share Posted January 28, 2014 -- 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
Daz Posted January 28, 2014 Author Share Posted January 28, 2014 Thank you for writing this code its extremely helpful and I understand it the gates open and close but im struggling to find where I can edit each gates colshape at because they are in weird places thank you again Link to comment
MTA Team 0xCiBeR Posted January 28, 2014 MTA Team Share Posted January 28, 2014 In SolidSnake's script, the colshape are being created at each gate position. Link to comment
Castillo Posted January 28, 2014 Share Posted January 28, 2014 -- 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
Daz Posted January 28, 2014 Author Share Posted January 28, 2014 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
Castillo Posted January 28, 2014 Share Posted January 28, 2014 The colshape uses same position as the gate, if it's still too high, change that "z - 1" to "z - 2" or more. Link to comment
Daz Posted January 28, 2014 Author Share Posted January 28, 2014 After a lot of experimenting and frustration I got it thanks to you guys I cant THANK YOU ENOUGH it works finallyyyyy Link to comment
MTA Team 0xCiBeR Posted January 28, 2014 MTA Team Share Posted January 28, 2014 You're Welcome man. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now