Jump to content

Freezing a vehicle


greenops011

Recommended Posts

Hi again guys. Got another question for you.

 

I want to make a “vehicle booting” system where if someone in the specified towing faction or PD faction wants to boot a vehicle, the vehicle would not be able to move, yet would still be able to turn on.

 

From what I read on the wiki, there is a function that would sort of allow this:

 

function toggleFreezeStatus ( thePlayer )
	-- get the vehicle element
	local playerVehicle = getPlayerOccupiedVehicle ( thePlayer )

	if playerVehicle then
		-- get the current freeze status
		local currentFreezeStatus = isElementFrozen ( playerVehicle )
		-- get the new freeze status (the opposite of the previous)
		local newFreezeStatus = not currentFreezeStatus
		-- set the new freeze status
		setElementFrozen ( playerVehicle, newFreezeStatus )
	end
end

However from what I’m seeing, that only works if a player is in the vehicle. What I’m hoping for is that the towing faction, or even an admin for that matter could type something like:

/bootveh <VIN or plate>

And it would check the vehlib database for either that VIN or plate, and then do the toggleFreezeStatus to the vehicle.

 

Then if they typed:

/unbootveh <VIN or plate>

It would set the frozen status to false. Any suggestions on how I would be able to accomplish this? 

 

Sorry for creating the multiple topics, I’m a complete noob to scripting, and want to be able to help the community I’m in to be able to develop scripts

Link to comment
addCommandHandler("bootveh", bootVehicle)
function bootVehicle(player, command, vinOrPlate)
  -- retrieve the VIN or plate of the vehicle from the command arguments
  local vinOrPlate = vinOrPlate
  -- retrieve the element of the vehicle using the VIN or plate
  local vehicle = getVehicleFromVinOrPlate(vinOrPlate)
  -- check if the vehicle was found
  if not vehicle then
    outputChatBox("Invalid VIN or plate.", player)
    return
  end
  -- freeze the vehicle
  setElementFrozen(vehicle, true)
  outputChatBox("Vehicle frozen.", player)
end
function getVehicleFromVinOrPlate(vinOrPlate)
  -- query the database for the VIN or plate
  local result = dbQuery(...)
  -- check if the result is valid
  if not result then return end
  -- retrieve the first row from the result
  local row = dbPoll(result, -1)[1]
  -- check if a row was found
  if not row then return end
  -- return the element of the vehicle
  return row.vehicle
end
addCommandHandler("unbootveh", unbootVehicle)
function unbootVehicle(player, command, vinOrPlate)
  -- retrieve the VIN or plate of the vehicle from the command arguments
  local vinOrPlate = vinOrPlate
  -- retrieve the element of the vehicle using the VIN or plate
  local vehicle = getVehicleFromVinOrPlate(vinOrPlate)
  -- check if the vehicle was found
  if not vehicle then
    outputChatBox("Invalid VIN or plate.", player)
    return
  end
  -- unfreeze the vehicle
  setElementFrozen(vehicle, false)
  outputChatBox("Vehicle unfrozen.", player)
end
  1.  
  2.  
  3.  
  4.  

 

You will need to create a function to retrieve the element of the vehicle from the VIN or plate. You can do this by querying the database for the VIN or plate and returning the element of the vehicle.

 

You can create a similar command and function for /unbootveh to unfreeze the vehicle.

 

  • Thanks 1
Link to comment
addCommandHandler("bootveh",function(player,_,plate)
    if not plate then return end

    local vehicle = getVehicleFromPlate(plate)

    if vehicle then
        local state = isElementFrozen(vehicle)
        setElementFrozen(vehicle, not state)
        if state then
            outputChatBox("Unfrozen",player,255,255,255,true)
        else
            outputChatBox("Frozen",player,255,255,255,true)
        end
    else
        outputChatBox("Vehicle not found",player,255,255,255,true)
    end
end)

function getVehicleFromPlate(plate)
    if not tostring(plate) then return end

    for _, vehicle in ipairs(getElementsByType("vehicle")) do
        if (getVehiclePlateText(vehicle) == plate) then
            return vehicle
        end
    end
    return false
end

 

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