nick1995 Posted June 8, 2012 Share Posted June 8, 2012 Hey! I have looked in the wiki, but I don't know what to do... I am a beginning scripter, and I am editting scripts... I have a question, maybe someone can do it for me... This is one gate: function onstartup () gate = createObject ( 975, 1438.1025390625, -2879.2116699219, 2.5887410640717, 0, 0, 180) end addEventHandler ( "onResourceStart", getRootElement(), onstartup ) function move () moveObject ( gate, 2200, 1429.4974365234, -2879.0065917969, 2.5750021934509) end addCommandHandler("1", move) function move () moveObject ( gate, 2450, 1438.1025390625, -2879.2116699219, 2.5887410640717) end addCommandHandler("2", move) s1 = createMarker( -1529, 490, 7, "cylinder", 13.5, 255, 255, 255, 0) s2 = createBlip( 1438.7745361328, -2938.0595703125, 2.8496370315552,62) Now i want that the gate automatic open if there is a player, and automatic close if the player is leaving... Now its open by /1 And closing by /2 Maybe someone can do this, and explain what he have done so I can do it the next time by myself... Regards, Nick Link to comment
Axel Posted June 8, 2012 Share Posted June 8, 2012 You can eighter make a colshape in it and when a player hits it gets moved and when he leaves it get closed or i think you can use getDistanceBetweenPoints3D. https://wiki.multitheftauto.com/wiki/CreateColCircle https://wiki.multitheftauto.com/wiki/OnColShapeHit https://wiki.multitheftauto.com/wiki/OnColShapeLeave https://wiki.multitheftauto.com/wiki/Get ... enPoints3D Link to comment
DarkLink Posted June 8, 2012 Share Posted June 8, 2012 You can use col functions do detect when player reaches near gate, and when it enters the col, u call the move https://wiki.multitheftauto.com/wiki/CreateColTube Good luck Link to comment
Vision Posted June 8, 2012 Share Posted June 8, 2012 You also can use marker functiions https://wiki.multitheftauto.com/wiki/CreateMarker https://wiki.multitheftauto.com/wiki/OnMarkerHit https://wiki.multitheftauto.com/wiki/OnMarkerLeave Link to comment
nick1995 Posted June 8, 2012 Author Share Posted June 8, 2012 I was trying what Darklink says, but i can't... That was the reason why i ask of somebody wants to do it, so I can learn for the future... i will try, but its hard, but so far, it will not work... Link to comment
nick1995 Posted June 8, 2012 Author Share Posted June 8, 2012 local gate = createObject ( 975, 1438.1025390625, -2879.2116699219, 2.5887410640717, 0, 0, 180) local marker = createMarker(1438.1025390625, -2879.2116699219, 2.5887410640717, "cylinder", 6, 255, 255, 255, 0) function moveGate(hitPlayer, matchingDimension) if hasObjectPermissionTo(hitPlayer, "function.kickPlayer") then moveObject ( gate, 2200, 1429.4974365234, -2879.0065917969, 2.5750021934509) setTimer(moveBack, 2000, 1) end end addEventHandler("onMarkerHit", marker, moveGate) function moveBack() moveObject ( gate, 2450, 1438.1025390625, -2879.2116699219, 2.5887410640717) end s1 = createMarker( -1529, 490, 7, "cylinder", 13.5, 255, 255, 255, 0) s2 = createBlip( 1438.7745361328, -2938.0595703125, 2.8496370315552,62) Problem, if he open, he closed after 0.5 seconds... (I had look at a other script, and so I edit c:) The problem is... I can edit the timer, but I want that he close if the player is away... EDIT: I have now this: local gate = createObject ( 975, 1438.1025390625, -2879.2116699219, 2.5887410640717, 0, 0, 180) local marker = createMarker(1438.1025390625, -2865.44531, 2.5887410640717, "cylinder", 6, 255, 255, 255, 0) function moveGate(hitPlayer, matchingDimension) if hasObjectPermissionTo(hitPlayer, "function.kickPlayer") then moveObject ( gate, 2200, 1429.4974365234, -2879.0065917969, 2.5750021934509) setTimer(moveBack, 4000, 1) end end addEventHandler("onMarkerHit", marker, moveGate) function moveBack() moveObject ( gate, 2450, 1438.1025390625, -2879.2116699219, 2.5887410640717) end s1 = createMarker( -1529, 490, 7, "cylinder", 13.5, 255, 255, 255, 0) s2 = createBlip( 1438.7745361328, -2938.0595703125, 2.8496370315552,62) But the second problem... I can't go out anymore, because there isn't a marker ... Link to comment
Vision Posted June 8, 2012 Share Posted June 8, 2012 (edited) local gate = createObject ( 975, 1438.1025390625, -2879.2116699219, 2.5887410640717, 0, 0, 180) local marker = createMarker(1438.1025390625, -2865.44531, 2.5887410640717, "cylinder", 6, 255, 255, 255, 0) local marker2 = createMarker(1438.1025390625, -2886.79980, 2.5887410640717, "cylinder", 6, 255, 255, 255, 0) function moveGate(hitPlayer, matchingDimension) if hasObjectPermissionTo(hitPlayer, "function.kickPlayer") then moveObject ( gate, 2200, 1429.4974365234, -2879.0065917969, 2.5750021934509) setTimer(moveBack, 4000, 1) -- the gate will closes in 4 seconds end end addEventHandler("onMarkerHit", marker, moveGate) addEventHandler("onMarkerHit", marker2, moveGate) function moveBack() moveObject ( gate, 2450, 1438.1025390625, -2879.2116699219, 2.5887410640717) end s1 = createMarker( -1529, 490, 7, "cylinder", 13.5, 255, 255, 255, 0) s2 = createBlip( 1438.7745361328, -2938.0595703125, 2.8496370315552,62) Edited June 8, 2012 by Guest Link to comment
nick1995 Posted June 8, 2012 Author Share Posted June 8, 2012 I have now this, thanks to Stuvi: local gate = createObject ( 975, 1438.1025390625, -2879.2116699219, 2.5887410640717, 0, 0, 180) local marker = createMarker(1438.1025390625, -2865.44531, 2.5887410640717, "cylinder", 6, 255, 255, 255, 0) local marker2 = createMarker(1438.1025390625, -2886.79980, 2.5887410640717, "cylinder", 6, 255, 255, 255, 0) function moveGate(hitPlayer, matchingDimension) if hasObjectPermissionTo(hitPlayer, "function.kickPlayer") then moveObject ( gate, 2200, 1429.4974365234, -2879.0065917969, 2.5750021934509) end end addEventHandler("onMarkerHit", marker, moveGate) addEventHandler("onMarkerHit", marker2, moveGate) function moveBack() moveObject ( gate, 2450, 1438.1025390625, -2879.2116699219, 2.5887410640717) -- move back when the player leaves the marck end addEventHandler("onMarkerLeave", marker, moveBack) addEventHandler("onMarkerLeave", marker2, moveBack) s1 = createMarker( -1529, 490, 7, "cylinder", 13.5, 255, 255, 255, 0) s2 = createBlip( 1438.7745361328, -2938.0595703125, 2.8496370315552,62) But the marker is little bit away from the gate... But now is the problem, the gate closed to early... So i can't ride thougt the gate, because he is already closing :') Link to comment
Vision Posted June 8, 2012 Share Posted June 8, 2012 (edited) Copy my code again Edited June 8, 2012 by Guest Link to comment
nick1995 Posted June 8, 2012 Author Share Posted June 8, 2012 Copy my code again, about the marker you can change the position to near the gate I know, but i want that the marker a little bit away from the gate (see my script) so the gate is opening... But if you leave the marker is closing Link to comment
nick1995 Posted June 8, 2012 Author Share Posted June 8, 2012 I think this is the best option: local gate = createObject ( 975, 1438.1025390625, -2879.2116699219, 2.5887410640717, 0, 0, 180) local marker = createMarker(1438.1025390625, -2874.20654, 2.5887410640717, "cylinder", 6, 255, 255, 255, 0) setMarkerSize ( marker, 11.5 ) function moveGate(hitPlayer, matchingDimension) if hasObjectPermissionTo(hitPlayer, "function.kickPlayer") then moveObject ( gate, 2200, 1429.4974365234, -2879.0065917969, 2.5750021934509) end end addEventHandler("onMarkerHit", marker, moveGate) function moveBack() moveObject ( gate, 2450, 1438.1025390625, -2879.2116699219, 2.5887410640717) end addEventHandler("onMarkerLeave", marker, moveBack) s1 = createMarker( -1529, 490, 7, "cylinder", 13.5, 255, 255, 255, 0) s2 = createBlip( 1438.7745361328, -2938.0595703125, 2.8496370315552,62) Link to comment
myonlake Posted June 9, 2012 Share Posted June 9, 2012 Hold on, it's better to have it fully functioning without bugs, use this code. local gate = createObject(975, 1438.1025390625, -2879.2116699219, 2.5887410640717, 0, 0, 180) local marker = createMarker(1438.1025390625, -2874.20654, 2.5887410640717, "cylinder", 11.5, 255, 255, 255, 0) local s2 = createBlip(1438.7745361328, -2938.0595703125, 2.8496370315552, 62) local moving = false addEventHandler("onMarkerHit", marker, function moveGate(hitElement, matchingDimension) if getElementType(hitElement) == "player" and matchingDimension then if hasObjectPermissionTo(hitElement, "function.kickPlayer") then if moving ~= true then moveObject(gate, 2200, 1429.4974365234, -2879.0065917969, 2.5750021934509) moving = true end end end end ) addEventHandler("onMarkerLeave", marker, function moveBack(leaveElement, matchingDimension) if moving ~= false then if matchingDimension then moveObject(gate, 2450, 1438.1025390625, -2879.2116699219, 2.5887410640717) moving = false end end end ) Link to comment
nick1995 Posted June 9, 2012 Author Share Posted June 9, 2012 Thanks, i will try that! c: Link to comment
nick1995 Posted June 9, 2012 Author Share Posted June 9, 2012 Now i have: [2012-06-09 20:36:20] Starting night_club [2012-06-09 20:36:20] SCRIPT ERROR: night_club\gate.lua:7: '(' expected near 'moveGate' [2012-06-09 20:36:20] WARNING: Loading script failed: night_club\gate.lua:7: '(' expected near 'moveGate' [2012-06-09 20:36:20] night_club restarted successfully Link to comment
nick1995 Posted June 9, 2012 Author Share Posted June 9, 2012 You can fix this yourself. Right... You think i dont try something? Link to comment
Alex. Posted June 9, 2012 Share Posted June 9, 2012 It tells you exactly what you need to do, you need to add the bracket where it is expected. Link to comment
myonlake Posted June 10, 2012 Share Posted June 10, 2012 Not exactly. Function names aren't allowed when the function is made inside an event. local gate = createObject(975, 1438.1025390625, -2879.2116699219, 2.5887410640717, 0, 0, 180) local marker = createMarker(1438.1025390625, -2874.20654, 2.5887410640717, "cylinder", 11.5, 255, 255, 255, 0) local s2 = createBlip(1438.7745361328, -2938.0595703125, 2.8496370315552, 62) local moving = false addEventHandler("onMarkerHit", marker, function(hitElement, matchingDimension) if getElementType(hitElement) == "player" and matchingDimension then if hasObjectPermissionTo(hitElement, "function.kickPlayer") then if moving ~= true then moveObject(gate, 2200, 1429.4974365234, -2879.0065917969, 2.5750021934509) moving = true end end end end ) addEventHandler("onMarkerLeave", marker, function(leaveElement, matchingDimension) if moving ~= false then if matchingDimension then moveObject(gate, 2450, 1438.1025390625, -2879.2116699219, 2.5887410640717) moving = false end end end ) 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