kevin433 Posted February 28, 2010 Share Posted February 28, 2010 Hi, I've made a GUI where you can lock and open your car even if you're standing outside of it, but it just works the half way. When I open it it says 0 = Not locked. When I then close it it says 0 = Not locked. I don't know why. Can anyone please help me? checkowner.lua function OpenCar() local spieler = getLocalPlayer() if(isPedInVehicle(spieler)) then local vehicle = getPedOccupiedVehicle(spieler) if(getElementData(vehicle, "Owner") == getPlayerName(spieler)) then if(getElementData(vehicle,"Locked") == 1) then setElementData(vehicle, "Locked", 0) setVehicleLocked(vehicle, false) CarLockSound() triggerServerEvent("SC", getLocalPlayer(), vehicle) end end else local x, y, z = getElementPosition ( spieler ) local rot = getPedRotation ( spieler ) local radius = 4 local lx = x + math.sin ( math.rad ( -rot ) ) * radius local ly = y + math.cos ( math.rad ( -rot ) ) * radius local hit, hx, hy, hy, element = processLineOfSight ( x, y, z, lx, ly, z ) if (hit and getElementType(element) == "vehicle") then if(getElementData(element,"Owner") == getPlayerName(spieler)) then if(getElementData(element, "Locked") == 1) then setElementData(element, "Locked", 0) setVehicleLocked(element, false) CarLockSound() triggerServerEvent("SC", getLocalPlayer(), element) end end end end end function CloseCar() local spieler = getLocalPlayer() if(isPedInVehicle(spieler)) then local vehicle = getPedOccupiedVehicle(spieler) if(getElementData(vehicle, "Owner") == getPlayerName(spieler)) then if(getElementData(vehicle,"Locked") == 0) then setElementData(vehicle, "Locked", 1) setVehicleLocked(vehicle, true) CarLockSound() triggerServerEvent("SC", getLocalPlayer(), vehicle) end end else local x, y, z = getElementPosition ( spieler ) local rot = getPedRotation ( spieler ) local radius = 4 local lx = x + math.sin ( math.rad ( -rot ) ) * radius local ly = y + math.cos ( math.rad ( -rot ) ) * radius local hit, hx, hy, hy, element = processLineOfSight ( x, y, z, lx, ly, z ) if (hit and getElementType(element) == "vehicle") then if(getElementData(element,"Owner") == getPlayerName(spieler)) then if(getElementData(element, "Locked") == 0) then setElementData(element, "Locked", 1) setVehicleLocked(element, true) CarLockSound() triggerServerEvent("SC", getLocalPlayer(), element) end end end end end SaveCarLock for the triggerServerEvent function SaveCarLock(id) local vid = getElementID(id) local vlocked = getElementData(id, "Locked") executeSQLQuery("UPDATE Vehicles SET Locked = ? WHERE CarID = ?",vlocked, vid) outputChatBox(getElementData(id, "Locked")) end addEvent("SC", true) addEventHandler( "SC", getRootElement(),SaveCarLock) Link to comment
Buffalo Posted February 28, 2010 Share Posted February 28, 2010 (edited) because you lock it only client side, other players will still be able to enter it. executeSQLQuery Returns a table with the result of the query if it was a SELECT query, or false if otherwise. Shouldn't you use executeSQLUpdate ? Edited February 28, 2010 by Guest Link to comment
kevin433 Posted February 28, 2010 Author Share Posted February 28, 2010 I changed the Query now to Update... I'm executing isVehicleLocked client side. I thought that it didn't was nesaccary to post the whole checkowner.lua. Here is the whole: function OpenCar() local spieler = getLocalPlayer() if(isPedInVehicle(spieler)) then local vehicle = getPedOccupiedVehicle(spieler) if(getElementData(vehicle, "Owner") == getPlayerName(spieler)) then if(getElementData(vehicle,"Locked") == 1) then setElementData(vehicle, "Locked", 0) setVehicleLocked(vehicle, false) CarLockSound() triggerServerEvent("SC", getLocalPlayer(), vehicle) end end else local x, y, z = getElementPosition ( spieler ) local rot = getPedRotation ( spieler ) local radius = 4 local lx = x + math.sin ( math.rad ( -rot ) ) * radius local ly = y + math.cos ( math.rad ( -rot ) ) * radius local hit, hx, hy, hy, element = processLineOfSight ( x, y, z, lx, ly, z ) if (hit and getElementType(element) == "vehicle") then if(getElementData(element,"Owner") == getPlayerName(spieler)) then if(getElementData(element, "Locked") == 1) then setElementData(element, "Locked", 0) setVehicleLocked(element, false) CarLockSound() triggerServerEvent("SC", getLocalPlayer(), element) end end end end end function CloseCar() local spieler = getLocalPlayer() if(isPedInVehicle(spieler)) then local vehicle = getPedOccupiedVehicle(spieler) if(getElementData(vehicle, "Owner") == getPlayerName(spieler)) then if(getElementData(vehicle,"Locked") == 0) then setElementData(vehicle, "Locked", 1) setVehicleLocked(vehicle, true) CarLockSound() triggerServerEvent("SC", getLocalPlayer(), vehicle) end end else local x, y, z = getElementPosition ( spieler ) local rot = getPedRotation ( spieler ) local radius = 4 local lx = x + math.sin ( math.rad ( -rot ) ) * radius local ly = y + math.cos ( math.rad ( -rot ) ) * radius local hit, hx, hy, hy, element = processLineOfSight ( x, y, z, lx, ly, z ) if (hit and getElementType(element) == "vehicle") then if(getElementData(element,"Owner") == getPlayerName(spieler)) then if(getElementData(element, "Locked") == 0) then setElementData(element, "Locked", 1) setVehicleLocked(element, true) CarLockSound() triggerServerEvent("SC", getLocalPlayer(), element) end end end end end function CreateKeyPicture() KeyBild = guiCreateStaticImage(0.86,0.4,0.0859,0.1829,"pictures/key.png",true) guiSetAlpha(KeyBild,1) CloseButton = guiCreateButton(0.3232,0.3544,0.3737,0.1392,"",true,KeyBild) guiSetAlpha(CloseButton,0.5) OpenButton = guiCreateButton(0.3333,0.7532,0.3737,0.1582,"",true,KeyBild) guiSetAlpha(OpenButton,0.5) guiSetVisible(KeyBild, false) addEventHandler("onClientGUIClick", CloseButton, CloseCar, false) addEventHandler("onClientGUIClick", OpenButton, OpenCar, false) end function ShowCarKey() if(guiGetVisible(KeyBild) == true) then guiSetVisible(KeyBild, false) showCursor(false) else guiSetVisible(KeyBild, true) showCursor(true) end end function checkvehicleowner(player) if(getElementData(source, "Locked") == 1 and isVehicleLocked(source) == true) then if(getElementData(source, "Owner") == getPlayerName(player)) then setVehicleLocked(source, true) setElementData(source, "Locked", 1) else setVehicleLocked(source, true) setElementData(source, "Locked", 1) end else end end addEventHandler("onClientVehicleStartEnter", getRootElement(), checkvehicleowner) 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