Jump to content

[HELP] How to make the command enable/disable the same function


lilwayn

Recommended Posts

local theVehicles = {}
local spamTick = 0

function findVehsToRob(player)
    local vehicle = getNearestElement(player, "vehicle", 100)
    if (getTickCount() - spamTick < 100000) then
        outputChatBox("You are robbing a vehicle already", player, 255, 0, 0)
        return false
    end
    spamTick = getTickCount()
    if (vehicle) then
        local x, y, z = getElementPosition(vehicle)
        local rx, ry, rz = getElementRotation(vehicle)
        local model = getElementModel(vehicle)
        robVeh = createVehicle(model, x, y, z)
        destroyElement(vehicle)
        setElementRotation(robVeh, rx, ry, rz)
        setVehicleLocked(robVeh, true)
        theVehicles[#theVehicles + 1] = robVeh
        outputChatBox("You're attempting to steal this vehicle, complete your tasks !", player, 0, 128, 0)
        triggerClientEvent(player, "sendTableToClient", player, theVehicles)
        addEventHandler("onVehicleStartEnter", robVeh, startRobbery)
        addEventHandler("onVehicleEnter", robVeh, taskOnEnter)
    else
        outputChatBox("There is no nearby vehicle to steal", player, 255, 255, 255)
    end
end
addCommandHandler("robvehicle", findVehsToRob)

How to edit this code so when the player types the command once again, he stops robbing the vehicle?

idk what is the check that checks if the player has typed the command once again.

Link to comment
On 25/10/2023 at 00:00, lilwayn said:
local theVehicles = {}
local spamTick = 0

function findVehsToRob(player)
    local vehicle = getNearestElement(player, "vehicle", 100)
    if (getTickCount() - spamTick < 100000) then
        outputChatBox("You are robbing a vehicle already", player, 255, 0, 0)
        return false
    end
    spamTick = getTickCount()
    if (vehicle) then
        local x, y, z = getElementPosition(vehicle)
        local rx, ry, rz = getElementRotation(vehicle)
        local model = getElementModel(vehicle)
        robVeh = createVehicle(model, x, y, z)
        destroyElement(vehicle)
        setElementRotation(robVeh, rx, ry, rz)
        setVehicleLocked(robVeh, true)
        theVehicles[#theVehicles + 1] = robVeh
        outputChatBox("You're attempting to steal this vehicle, complete your tasks !", player, 0, 128, 0)
        triggerClientEvent(player, "sendTableToClient", player, theVehicles)
        addEventHandler("onVehicleStartEnter", robVeh, startRobbery)
        addEventHandler("onVehicleEnter", robVeh, taskOnEnter)
    else
        outputChatBox("There is no nearby vehicle to steal", player, 255, 255, 255)
    end
end
addCommandHandler("robvehicle", findVehsToRob)

How to edit this code so when the player types the command once again, he stops robbing the vehicle?

idk what is the check that checks if the player has typed the command once again.


 

local theVehicles = {}
local spamTick = 0
local isRobbed = false

function findVehsToRob(player)
    local vehicle = getNearestElement(player, "vehicle", 100)
    if (getTickCount() - spamTick < 100000) then
        outputChatBox("You are robbing a vehicle already", player, 255, 0, 0)
        return false
    end
    if isRobbed then
       return
    end
    spamTick = getTickCount()
    if (vehicle) then
        local x, y, z = getElementPosition(vehicle)
        local rx, ry, rz = getElementRotation(vehicle)
        local model = getElementModel(vehicle)
        robVeh = createVehicle(model, x, y, z)
        destroyElement(vehicle)
        setElementRotation(robVeh, rx, ry, rz)
        setVehicleLocked(robVeh, true)
        theVehicles[#theVehicles + 1] = robVeh
        outputChatBox("You're attempting to steal this vehicle, complete your tasks !", player, 0, 128, 0)
        triggerClientEvent(player, "sendTableToClient", player, theVehicles)
        addEventHandler("onVehicleStartEnter", robVeh, startRobbery)
        addEventHandler("onVehicleEnter", robVeh, taskOnEnter)
        isRobbed = true
    else
        outputChatBox("There is no nearby vehicle to steal", player, 255, 255, 255)
    end
end
addCommandHandler("robvehicle", findVehsToRob)

 

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