Mikhail Posted October 8, 2018 Share Posted October 8, 2018 (edited) Hello, i create 2 commands, one to open and one to close a bar (like a gate) I run the command /openbar once and it's all well, its rotated 90 degrees, but if I execute it again it rotates another 90 degrees more, and so on the same to close the bar. What should I do when I execute the command a second time , the bar does not open more than what was opened? same for close. Edited October 8, 2018 by Mikhail Link to comment
Moderators IIYAMA Posted October 8, 2018 Moderators Share Posted October 8, 2018 Define the static start and end orientation and transform to there. Just like a train on a railroad, it can only move between the stations but not further or sidewards. Link to comment
LyricalMM Posted October 8, 2018 Share Posted October 8, 2018 (edited) Use element data like local isRotated = getElememtData(object, "rotated") if isRotated then --code to set to initial position setElementData(object, "rotated", 0) --or false else --code to set the object to open position setElememtData(object, "rotated", 1) --or true end Idk if this would work but give it a try Edited October 8, 2018 by LyricalMM Link to comment
Z4Zy Posted October 8, 2018 Share Posted October 8, 2018 Server Side :- gate = --[ create a gate here ]-- gateOpen = false -- gate is closed by default addCommandHandler("openGate", function (player,command) if gateOpen ~= true then --[ set gate's position when opened ] -- outputChatBox("Gate Opened !",player,255,255,0) gateOpen = true elseif gateOpen == true then outputChatBox("Gate already opened !",player,255,0,0) end end addCommandHandler("closeGate", function (player,command) if gateOpen == true then --[ set gate's position when closed ] -- outputChatBox("Gate Closed !",player,255,255,0) gateOpen = false else outputChatBox("Gate already closed !",player,255,0,0) end end I think you are finding a thing like above. if so, then above is a sample that doesn't tested and completed yet. Link to comment
Mikhail Posted October 8, 2018 Author Share Posted October 8, 2018 11 hours ago, IIYAMA said: Define the static start and end orientation and transform to there. Just like a train on a railroad, it can only move between the stations but not further or sidewards. what is the syntax for define cordinates ? Link to comment
Mikhail Posted October 8, 2018 Author Share Posted October 8, 2018 (edited) @DeadthStrock very nice! its work to the first test, that was i needed. but i have a question.. what is the difference between this syntax: (its from wiki) Spoiler function consoleCreateMarker ( playerSource, commandName ) -- If a player triggered it (rather than the admin) then if ( playerSource ) then -- Get that player's position local x, y, z = getElementPosition ( playerSource ) -- Create a size 2, red checkpoint marker at their position createMarker ( x, y, z, "checkpoint", 2, 255, 0, 0, 255 ) -- Output it in his chat box outputChatBox ( "You got a red marker", playerSource ) end end -- Attach the 'consoleCreateMarker' function to the "createmarker" command addCommandHandler ( "createmarker", consoleCreateMarker ) and your syntax? (my command fix) Spoiler addCommandHandler("abrirfcpd", function (player,command) if gateOpen ~= true then moveObject ( barrafc, 1000, -215.89999, 1008, 19.5, 0, 90, 0 ) outputChatBox("Gate Opened !",player,255,255,0) gateOpen = true elseif gateOpen == true then outputChatBox("Gate already opened !",player,255,0,0) end end) @N3xT Spoiler barrafc = createObject ( 968, -215.89999, 1008, 19.5, 0, 269.5, 358 ) x,y,z = getElementPosition (barrafc) asd = barrafc function barrafcpd () moveObject ( barrafc, 1000, -215.89999, 1008, 19.5, 0, 90, 0 ) barrafc = asd outputChatBox("Se abrio la barrera", source, 255, 0, 0) if barrafc == asd then addEventHandler("onPlayerCommand",root, function(asd) if (asd == "abrirfcpd") then cancelEvent() end end) end end addCommandHandler ( "abrirfcpd", barrafcpd ) when I saw the examples that they gave me above, my script was completely incoherent I was using "cancelEvent" to stop the command, I think it was never going to work like that because I canceled it completely. its work with the script of DeadthStrock In any case I ask you, were you going to give a script similar to that of DeadthStrock? because I'd like to see your way of writing the code too, you always learn something new! do not laugh at my script poeple lol Edited October 8, 2018 by Mikhail 1 Link to comment
Z4Zy Posted October 8, 2018 Share Posted October 8, 2018 48 minutes ago, Mikhail said: @DeadthStrock very nice! its work to the first test, that was i needed. but i have a question.. what is the difference between this syntax: (its from wiki) Hide contents function consoleCreateMarker ( playerSource, commandName ) -- If a player triggered it (rather than the admin) then if ( playerSource ) then -- Get that player's position local x, y, z = getElementPosition ( playerSource ) -- Create a size 2, red checkpoint marker at their position createMarker ( x, y, z, "checkpoint", 2, 255, 0, 0, 255 ) -- Output it in his chat box outputChatBox ( "You got a red marker", playerSource ) end end -- Attach the 'consoleCreateMarker' function to the "createmarker" command addCommandHandler ( "createmarker", consoleCreateMarker ) and your syntax? (my command fix) Reveal hidden contents addCommandHandler("abrirfcpd", function (player,command) if gateOpen ~= true then moveObject ( barrafc, 1000, -215.89999, 1008, 19.5, 0, 90, 0 ) outputChatBox("Gate Opened !",player,255,255,0) gateOpen = true elseif gateOpen == true then outputChatBox("Gate already opened !",player,255,0,0) end end) Actually, Difference 01 :- The code that you have got from wiki will create a red marker near the player who command. And my code with your command fix will helps to move a certain object when a player command. Difference 02 :- The code that you have got from wiki has written the function separately from "addCommandHandler" event. As well as that function has given a name 'consoleCreateMarker'. And you can see.. that name has put into the 'addCommandHandler' event. But my code with your command fix has directly insert the function into the 'addCommandHandler' event without a function name. That's all I saw as different between that 2 codes. And note that my sample code is a simple code just generated by me. Link to comment
Moderators IIYAMA Posted October 8, 2018 Moderators Share Posted October 8, 2018 2 hours ago, Mikhail said: what is the syntax for define cordinates ? The most basic lua syntax for that would be: (without tables) local posX1, posY1, posZ1, rotX1, rotY1, rotZ1 = 2445, 788789, 768879, 0, 90, 0 local posX2, posY2, posZ2, rotX2, rotY2, rotZ2 = 2445, 788789, 768879, 0, 0, 0 moveObject ( barrafc, 1000, posX1, posY1, posZ1, rotX1, rotY1, rotZ1 ) -- A to B moveObject ( barrafc, 1000, posX2, posY2, posZ2, rotX2, rotY2, rotZ2 ) -- B to A 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