FastDriver Posted March 8, 2015 Share Posted March 8, 2015 Dear fellows, As the tittle says i downloaded a carlocker from the community and started editing it because we've a carshop and we only want the owner to be able to lock his own car and not other people well so i started editing i added things and now there are no errors is debugscript nothing the script starts but if i use the command /lock the car wont be locked. can anyone help me please? function lockCar(playerSource, player) local carID = getPedOccupiedVehicle(playerSource) if (carID) and (isVehicleLocked(carID)) and (getVehicleOccupant(carID) == playerSource) then local owner = getElementData(carID, "owner") if owner and owner == playerSource then local username = getAccountName(getPlayerAccount(player)) if username then local unlocked = setVehicleLocked(carID, false) if (unlocked) then outputChatBox("#7D7D7DCAR MANAGER: #DEDEDEYour " .. getVehicleName(carID) .. " has been successfully unlocked!", playerSource, 255, 255, 255, true) else outputChatBox("#7D7D7DCAR MANAGER: #DEDEDEYour " .. getVehicleName(carID) .. " was not unlocked successfully!", playerSource, 255, 255, 255, true) end elseif not (carID) then elseif not (isVehicleLocked(carID)) and (getVehicleOccupant(carID) == playerSource) then local owner = getElementData(carID, "owner") if owner and owner == playerSource then local username = getAccountName(getPlayerAccount(player)) if username then local locked = setVehicleLocked(carID, true) if (locked) then outputChatBox("#7D7D7DCAR MANAGER: #DEDEDEYour " .. getVehicleName(carID) .. " has been successfully locked!", playerSource, 255, 255, 255, true) else outputChatBox("#7D7D7DCAR MANAGER: #DEDEDEYour " .. getVehicleName(carID) .. " was not locked successfully!", playerSource, 255, 255, 255, true) end end end end end end end addCommandHandler("lock", lockCar) function unlockOnExit(thePlayer, seat, jacker) if (seat == 0) and (thePlayer) and (isVehicleLocked(source)) then local unlocked = setVehicleLocked(source, false) if (unlocked) then outputChatBox("#7D7D7DCAR MANAGER: #DEDEDEYour " .. getVehicleName(source) .. " has been successfully unlocked!", thePlayer, 255, 255, 255, true) end end end addEventHandler("onVehicleExit", getRootElement(), unlockOnExit) Thanks in advance Greetz FastDriver Link to comment
roaddog Posted March 8, 2015 Share Posted March 8, 2015 function lockCar(playerSource, command) local carID = getPedOccupiedVehicle(playerSource) if (carID) and (isVehicleLocked(carID)) and (getVehicleOccupant(carID) == playerSource) then local owner = getElementData(carID, "owner") if owner and owner == playerSource then local username = getAccountName(getPlayerAccount(player)) if username then local unlocked = setVehicleLocked(carID, false) if (unlocked) then outputChatBox("#7D7D7DCAR MANAGER: #DEDEDEYour " .. getVehicleName(carID) .. " has been successfully unlocked!", playerSource, 255, 255, 255, true) else outputChatBox("#7D7D7DCAR MANAGER: #DEDEDEYour " .. getVehicleName(carID) .. " was not unlocked successfully!", playerSource, 255, 255, 255, true) end end end else local owner = getElementData(carID, "owner") if owner and owner == playerSource then local username = getAccountName(getPlayerAccount(player)) if username then local locked = setVehicleLocked(carID, true) if (locked) then outputChatBox("#7D7D7DCAR MANAGER: #DEDEDEYour " .. getVehicleName(carID) .. " has been successfully locked!", playerSource, 255, 255, 255, true) else outputChatBox("#7D7D7DCAR MANAGER: #DEDEDEYour " .. getVehicleName(carID) .. " was not locked successfully!", playerSource, 255, 255, 255, true) end end end end addCommandHandler("lock", lockCar) function unlockOnExit(thePlayer, seat, jacker) if (seat == 0) and (thePlayer) and (isVehicleLocked(source)) then local unlocked = setVehicleLocked(source, false) if (unlocked) then outputChatBox("#7D7D7DCAR MANAGER: #DEDEDEYour " .. getVehicleName(source) .. " has been successfully unlocked!", thePlayer, 255, 255, 255, true) end end end addEventHandler("onVehicleExit", getRootElement(), unlockOnExit) Link to comment
FastDriver Posted March 8, 2015 Author Share Posted March 8, 2015 Well thank you for trying to help me i added it in and tested it but it still didn't lock or neither say something in the chat Link to comment
roaddog Posted March 9, 2015 Share Posted March 9, 2015 function lockCar(playerSource, command) local carID = getPedOccupiedVehicle(playerSource) if (carID) and (isVehicleLocked(carID)) and (getVehicleOccupant(carID) == playerSource) then local owner = getElementData(carID, "owner") if owner == getPlayerName(playerSource) then local username = getAccountName(getPlayerAccount(playerSource)) if username then local unlocked = setVehicleLocked(carID, false) if (unlocked) then outputChatBox("#7D7D7DCAR MANAGER: #DEDEDEYour " .. getVehicleName(carID) .. " has been successfully unlocked!", playerSource, 255, 255, 255, true) else outputChatBox("#7D7D7DCAR MANAGER: #DEDEDEYour " .. getVehicleName(carID) .. " was not unlocked successfully!", playerSource, 255, 255, 255, true) end end end else local owner = getElementData(carID, "owner") if owner == getPlayerName(playerSource) then local username = getAccountName(getPlayerAccount(playerSource)) if username then local locked = setVehicleLocked(carID, true) if (locked) then outputChatBox("#7D7D7DCAR MANAGER: #DEDEDEYour " .. getVehicleName(carID) .. " has been successfully locked!", playerSource, 255, 255, 255, true) else outputChatBox("#7D7D7DCAR MANAGER: #DEDEDEYour " .. getVehicleName(carID) .. " was not locked successfully!", playerSource, 255, 255, 255, true) end end end end addCommandHandler("lock", lockCar) function unlockOnExit(thePlayer, seat, jacker) if (seat == 0) and (thePlayer) and (isVehicleLocked(source)) then local unlocked = setVehicleLocked(source, false) if (unlocked) then outputChatBox("#7D7D7DCAR MANAGER: #DEDEDEYour " .. getVehicleName(source) .. " has been successfully unlocked!", thePlayer, 255, 255, 255, true) end end end addEventHandler("onVehicleExit", getRootElement(), unlockOnExit) Try this, May I know how did you store the "owner" data? is it stored with their account or player name? Link to comment
FastDriver Posted March 9, 2015 Author Share Posted March 9, 2015 function lockCar(playerSource, command) local carID = getPedOccupiedVehicle(playerSource) if (carID) and (isVehicleLocked(carID)) and (getVehicleOccupant(carID) == playerSource) then local owner = getElementData(carID, "owner") if owner == getPlayerName(playerSource) then local username = getAccountName(getPlayerAccount(playerSource)) if username then local unlocked = setVehicleLocked(carID, false) if (unlocked) then outputChatBox("#7D7D7DCAR MANAGER: #DEDEDEYour " .. getVehicleName(carID) .. " has been successfully unlocked!", playerSource, 255, 255, 255, true) else outputChatBox("#7D7D7DCAR MANAGER: #DEDEDEYour " .. getVehicleName(carID) .. " was not unlocked successfully!", playerSource, 255, 255, 255, true) end end end else local owner = getElementData(carID, "owner") if owner == getPlayerName(playerSource) then local username = getAccountName(getPlayerAccount(playerSource)) if username then local locked = setVehicleLocked(carID, true) if (locked) then outputChatBox("#7D7D7DCAR MANAGER: #DEDEDEYour " .. getVehicleName(carID) .. " has been successfully locked!", playerSource, 255, 255, 255, true) else outputChatBox("#7D7D7DCAR MANAGER: #DEDEDEYour " .. getVehicleName(carID) .. " was not locked successfully!", playerSource, 255, 255, 255, true) end end end end addCommandHandler("lock", lockCar) function unlockOnExit(thePlayer, seat, jacker) if (seat == 0) and (thePlayer) and (isVehicleLocked(source)) then local unlocked = setVehicleLocked(source, false) if (unlocked) then outputChatBox("#7D7D7DCAR MANAGER: #DEDEDEYour " .. getVehicleName(source) .. " has been successfully unlocked!", thePlayer, 255, 255, 255, true) end end end addEventHandler("onVehicleExit", getRootElement(), unlockOnExit) Try this, May I know how did you store the "owner" data? is it stored with their account or player name? This also didn't work and about the question it's stored with their account, thanks for helping me btw. Link to comment
Addlibs Posted March 9, 2015 Share Posted March 9, 2015 Account name or account entity (such as those acquired by getAccount)? Link to comment
roaddog Posted March 10, 2015 Share Posted March 10, 2015 Should work now, if the "owner" is account name. function lockCar(playerSource, command) if not isPedInVehicle(playerSource) then return end local carID = getPedOccupiedVehicle(playerSource) local owner = getElementData(carID, "owner") local username = getAccountName(getPlayerAccount(playerSource)) if owner == username then if (isVehicleLocked(carID)) then local unlocked = setVehicleLocked(carID, false) if (unlocked) then outputChatBox("#7D7D7DCAR MANAGER: #DEDEDEYour " .. getVehicleName(carID) .. " has been successfully unlocked!", playerSource, 255, 255, 255, true) else outputChatBox("#7D7D7DCAR MANAGER: #DEDEDEYour " .. getVehicleName(carID) .. " was not unlocked successfully!", playerSource, 255, 255, 255, true) end else local locked = setVehicleLocked(carID, true) if (locked) then outputChatBox("#7D7D7DCAR MANAGER: #DEDEDEYour " .. getVehicleName(carID) .. " has been successfully locked!", playerSource, 255, 255, 255, true) else outputChatBox("#7D7D7DCAR MANAGER: #DEDEDEYour " .. getVehicleName(carID) .. " was not locked successfully!", playerSource, 255, 255, 255, true) end end else outputChatBox("#7D7D7DCAR MANAGER: #DEDEDEThis is not your vehicle!", playerSource, 255, 255, 255, true) end end addCommandHandler("lock", lockCar) function unlockOnExit(vehicle, seat, jacked) if (seat ~= 0) then return end if (isElement(source)) and (isVehicleLocked(vehicle)) then setVehicleLocked(vehicle, false) outputChatBox("#7D7D7DCAR MANAGER: #DEDEDEYour " .. getVehicleName(vehicle) .. " has been successfully unlocked!", source, 255, 255, 255, true) end end addEventHandler("onPlayerVehicleExit", getRootElement(), unlockOnExit) Link to comment
FastDriver Posted March 10, 2015 Author Share Posted March 10, 2015 Should work now, if the "owner" is account name. function lockCar(playerSource, command) if not isPedInVehicle(playerSource) then return end local carID = getPedOccupiedVehicle(playerSource) local owner = getElementData(carID, "owner") local username = getAccountName(getPlayerAccount(playerSource)) if owner == username then if (isVehicleLocked(carID)) then local unlocked = setVehicleLocked(carID, false) if (unlocked) then outputChatBox("#7D7D7DCAR MANAGER: #DEDEDEYour " .. getVehicleName(carID) .. " has been successfully unlocked!", playerSource, 255, 255, 255, true) else outputChatBox("#7D7D7DCAR MANAGER: #DEDEDEYour " .. getVehicleName(carID) .. " was not unlocked successfully!", playerSource, 255, 255, 255, true) end else local locked = setVehicleLocked(carID, true) if (locked) then outputChatBox("#7D7D7DCAR MANAGER: #DEDEDEYour " .. getVehicleName(carID) .. " has been successfully locked!", playerSource, 255, 255, 255, true) else outputChatBox("#7D7D7DCAR MANAGER: #DEDEDEYour " .. getVehicleName(carID) .. " was not locked successfully!", playerSource, 255, 255, 255, true) end end else outputChatBox("#7D7D7DCAR MANAGER: #DEDEDEThis is not your vehicle!", playerSource, 255, 255, 255, true) end end addCommandHandler("lock", lockCar) function unlockOnExit(vehicle, seat, jacked) if (seat ~= 0) then return end if (isElement(source)) and (isVehicleLocked(vehicle)) then setVehicleLocked(vehicle, false) outputChatBox("#7D7D7DCAR MANAGER: #DEDEDEYour " .. getVehicleName(vehicle) .. " has been successfully unlocked!", source, 255, 255, 255, true) end end addEventHandler("onPlayerVehicleExit", getRootElement(), unlockOnExit) Well uhmm now it only says: "This is not your vehicle!" as i see you added that in the script but it didn't work. the car did not get locked Link to comment
roaddog Posted March 10, 2015 Share Posted March 10, 2015 Well that means the "owner" data is not set to the account. Add this line after the getAccountName line to check whether the owner was accountname outputChatBox(tostring(owner).. " == ".. tostring(username) .." ?") post the result here. the car did not get locked Did it pass the messages in chatbox? I have tested this, and this was actually worked. Link to comment
FastDriver Posted March 11, 2015 Author Share Posted March 11, 2015 This is what it said: Zayd is my username btw Link to comment
roaddog Posted March 11, 2015 Share Posted March 11, 2015 Option 1: Change this line local username = getAccountName(getPlayerAccount(playerSource)) to local username = getPlayerAccount(playerSource) Option 2: or add getAccountName(owner) at the if clause line 7. choose either of them. 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