joedajoester Posted February 2, 2015 Share Posted February 2, 2015 Hi, so im trying to have the command "spatula" attach objects (which it does) and then when i type "spatula" again i want it to remove the objects only if they are attached. Spent a few hours on this but i get no error and only the removing part doesnt work. function addspatula (player) local spatula = 0 if spatula == 0 then car1gate1 = createObject(971, 0, 0, 5) car1gate2 = createObject(971, 0, 0, 5) car2gate1 = createObject(971, 0, 0, 5) car2gate2 = createObject(971, 0, 0, 5) vehicle = getPedOccupiedVehicle(player) attachElements( car1gate1, vehicle, 0.4, 6.2, -0.6, 90, 90, 90 ) attachElements( car1gate2, vehicle, 0.4, 13.2, -0.6, 90, 90, 90 ) addVehicleUpgrade ( vehicle, 1087 ) addVehicleUpgrade ( vehicle, 1087 ) else removeElements( car1gate1, vehicle, 0.4, 6.2, -0.6, 90, 90, 90 ) removeElements( car1gate2, vehicle, 0.4, 13.2, -0.6, 90, 90, 90 ) end end addCommandHandler("spatula", addspatula) Link to comment
Jaysds1 Posted February 2, 2015 Share Posted February 2, 2015 (edited) Here try this: local gates = { car1gate1 = createObject(971, 0, 0, 5), car1gate2 = createObject(971, 0, 0, 5), car2gate1 = createObject(971, 0, 0, 5), car2gate2 = createObject(971, 0, 0, 5) } function addspatula (player) local vehicle = getPedOccupiedVehicle(player) if not vehicle then return outputChatBox("You need to be in a vehicle!",player) end local spatula = getElementData(player,"spatula") or false if spatula == false then attachElements( gates.car1gate1, vehicle, 0.4, 6.2, -0.6, 90, 90, 90 ) attachElements( gates.car1gate2, vehicle, 0.4, 13.2, -0.6, 90, 90, 90 ) addVehicleUpgrade ( vehicle, 1087 ) addVehicleUpgrade ( vehicle, 1087 ) else removeElements( gates.car1gate1, vehicle, 0.4, 6.2, -0.6, 90, 90, 90 ) removeElements( gates.car1gate2, vehicle, 0.4, 13.2, -0.6, 90, 90, 90 ) end spatula = not spatula setElementData(player,"spatula",spatula) end addCommandHandler("spatula", addspatula) Basically, you forgot to change the variable value. I put comments in there for you Edited February 2, 2015 by Guest Link to comment
joedajoester Posted February 2, 2015 Author Share Posted February 2, 2015 Here try this:function addspatula (player) local spatula = 0 if spatula == 0 then car1gate1 = createObject(971, 0, 0, 5) car1gate2 = createObject(971, 0, 0, 5) car2gate1 = createObject(971, 0, 0, 5) car2gate2 = createObject(971, 0, 0, 5) vehicle = getPedOccupiedVehicle(player) attachElements( car1gate1, vehicle, 0.4, 6.2, -0.6, 90, 90, 90 ) attachElements( car1gate2, vehicle, 0.4, 13.2, -0.6, 90, 90, 90 ) addVehicleUpgrade ( vehicle, 1087 ) addVehicleUpgrade ( vehicle, 1087 ) spatula = 1 --set it to something other than 0 so it could detach else removeElements( car1gate1, vehicle, 0.4, 6.2, -0.6, 90, 90, 90 ) removeElements( car1gate2, vehicle, 0.4, 13.2, -0.6, 90, 90, 90 ) spatula = 0 --Set it to 0 for attaching again end end addCommandHandler("spatula", addspatula) Basically, you forgot to change the variable value. I put comments in there for you Thanks for the quick reply, however it still doesn't remove the objects Link to comment
Jaysds1 Posted February 2, 2015 Share Posted February 2, 2015 I've edited the code again, Should've read the code properly instead of skimming it... It should work now! Link to comment
joedajoester Posted February 2, 2015 Author Share Posted February 2, 2015 I've edited the code again,Should've read the code properly instead of skimming it... It should work now! Still not removing the gates when i type "spatula" This is a tough bugger lol. http://imgur.com/gENUtDp Link to comment
ALw7sH Posted February 2, 2015 Share Posted February 2, 2015 there's no function with this name "removeElements" Link to comment
Bean666 Posted February 2, 2015 Share Posted February 2, 2015 i think removeElements must be destroyElement there's no such thing as removeElements. Try replacing the removelements function with this: destroyElement( car1gate1, vehicle, 0.4, 6.2, -0.6, 90, 90, 90 ) destroyElement( car1gate2, vehicle, 0.4, 13.2, -0.6, 90, 90, 90 ) Link to comment
ALw7sH Posted February 2, 2015 Share Posted February 2, 2015 ithink he want to detach the object not to remove it if you want to do what i said use this function detachElements Link to comment
Jaysds1 Posted February 2, 2015 Share Posted February 2, 2015 Yea, I keep missing simple information like that... local gates = { car1gate1 = createObject(971, 0, 0, 5), car1gate2 = createObject(971, 0, 0, 5), car2gate1 = createObject(971, 0, 0, 5), car2gate2 = createObject(971, 0, 0, 5) } function addspatula (player) local vehicle = getPedOccupiedVehicle(player) if not vehicle then return outputChatBox("You need to be in a vehicle!",player) end local spatula = getElementData(player,"spatula") or false if spatula == false then attachElements( gates.car1gate1, vehicle, 0.4, 6.2, -0.6, 90, 90, 90 ) attachElements( gates.car1gate2, vehicle, 0.4, 13.2, -0.6, 90, 90, 90 ) addVehicleUpgrade ( vehicle, 1087 ) addVehicleUpgrade ( vehicle, 1087 ) else detachElements( gates.car1gate1, vehicle) detachElements( gates.car1gate2, vehicle) end spatula = not spatula setElementData(player,"spatula",spatula) end addCommandHandler("spatula", addspatula) Link to comment
joedajoester Posted February 2, 2015 Author Share Posted February 2, 2015 Thank you for all your help everyone, it works! 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