Jump to content

[HELP] Carlocker won't work.


Recommended Posts

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
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
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
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

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
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 xD 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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...