Jump to content

HELP PLease with fix vehicle command.


DonOmar

Recommended Posts

hi guys today i made a code to fix vehicle for DL3 but i want to disable it in dimension 366 so what shoul i do ?

here is the code.

function fixVeh ( thePlayer ) 
  setTimer (function () 
        if isObjectInACLGroup ( "user.".. getAccountName ( getPlayerAccount ( thePlayer ) ), aclGetGroup ( "DL3" ) ) then 
            for _, vehicle in ipairs ( getElementsByType ( 'vehicle' ) ) do 
                fixVehicle ( vehicle ) 
            end 
        end 
 end,15000, 1) 
end 
addCommandHandler( "fixv", fixVeh )    
  

Link to comment

here is an example, but you realize you are making a loop through all vehicles right...? so basically it will repair all vehicles with players in it.

function fixVeh ( thePlayer ) 
  setTimer (function () 
        if isObjectInACLGroup ( "user.".. getAccountName ( getPlayerAccount ( thePlayer ) ), aclGetGroup ( "DL3" ) ) then 
                local dimension = getElementDimension(thePlayer) 
                for i, vehicle in ipairs(getElementsByType("vehicle")) do 
                if (dimension == 366) then return end 
                fixVehicle ( vehicle ) 
            end 
        end 
 end,15000, 1) 
end 
addCommandHandler( "fixv", fixVeh )  

Edited by Guest
Link to comment

Try this , untested i'm using the phone

function fixVeh (thePlayer,cmd) 
    if thePlayer and isElement(thePlayer) then  
        local account = getPlayerAccount(thePlayer) 
            if account and not isGuestAccount(account) then  
                local accountName = getAccountName (account) 
                if isObjectInACLGroup ( "user."..accountName , aclGetGroup ( "DL3" ) ) then 
                    local dimension = getElementDimension(thePlayer) 
                    if dimension ~= 366 then  
                        if isPedInVehicle(thePlayer) then  
                            local vehicle = getPedOccupiedVehicle (thePlayer) 
                            fixVehicle ( vehicle ) 
                            outputChatBox("Fixed",thePlayer,255,0,0) 
                        else 
                            outputChatBox("You can't use this ("..cmd..") when your not inside a vehicle!",thePlayer,255,0,0) 
                        end  
                    else 
                    outputChatBox("You can't use this command when you are inside 366 dimension",thePlayer,255,0,0) 
                end  
            end 
        end 
    end 
end 
addCommandHandler( "fixv", fixVeh )  

Link to comment

if you want the car to repair in 15 seconds and if you also want the player won't be able to spam it then use this( i edited the fixVehicle and outputChatBox on Walids code):

function fixVeh (thePlayer,cmd) 
    if thePlayer and isElement(thePlayer) then 
        local account = getPlayerAccount(thePlayer) 
            if account and not isGuestAccount(account) then 
                local accountName = getAccountName (account) 
                if isObjectInACLGroup ( "user."..accountName , aclGetGroup ( "DL3" ) ) then 
                    local dimension = getElementDimension(thePlayer) 
                    local data = getElementData(thePlayer, "cooldown") 
                    if dimension ~= 366 then 
                        if isPedInVehicle(thePlayer) then 
                            local vehicle = getPedOccupiedVehicle (thePlayer) 
                            if data == false then 
                            setElementData(thePlayer, "cooldown", true) 
                            setTimer(setElementData, 15000, 1, thePlayer, "cooldown", false) 
                            setTimer(function () fixVehicle(vehicle) end, 15000, 1, true) 
                            setTimer(outputChatBox, 15000, 1, "Fixed", thePlayer, 255, 0, 0) 
                            outputChatBox("Fixing in 15 seconds", thePlayer) 
                            end 
                            if data == true then 
                            outputChatBox("PLEASE WAIT 15 SECONDS TO REPAIR AGAIN", thePlayer, 255,0,0) 
                         end 
                        else 
                            outputChatBox("You can't use this ("..cmd..") when your not inside a vehicle!",thePlayer,255,0,0) 
                        end 
                    else 
                    outputChatBox("You can't use this command when you are inside 366 dimension",thePlayer,255,0,0) 
                end 
            end 
        end 
    end 
end 
addCommandHandler( "fixv", fixVeh ) 

Edited by Guest
Link to comment

@Walid, oh yeah sorry bout that

This could be useful:, it prevents people from spamming the command(which is he can bind it and repair his car all over again.):

function fixVeh (thePlayer,cmd) 
    if thePlayer and isElement(thePlayer) then 
        local account = getPlayerAccount(thePlayer) 
            if account and not isGuestAccount(account) then 
                local accountName = getAccountName (account) 
                if isObjectInACLGroup ( "user."..accountName , aclGetGroup ( "DL3" ) ) then 
                    local dimension = getElementDimension(thePlayer) 
                    local data = getElementData(thePlayer, "cooldown") 
                    if dimension ~= 366 then 
                        if isPedInVehicle(thePlayer) then 
                            local vehicle = getPedOccupiedVehicle (thePlayer) 
                            if data == false then 
                            setElementData(thePlayer, "cooldown", true) 
                            setTimer(function (veh) 
                            fixVehicle(veh) 
                            outputChatBox("Fixed", thePlayer, 255, 0,0) 
                            setElementData(thePlayer, "cooldown", false) 
                            end, 15000, 1, vehicle) 
                            outputChatBox("Fixing in 15 seconds", thePlayer) 
                            elseif data == true then 
                            outputChatBox("Please wait 15 seconds to use this command(fixv) again!", thePlayer, 255,0,0) 
                         end 
                        else 
                            outputChatBox("You can't use this ("..cmd..") when you're not inside a vehicle!",thePlayer,255,0,0) 
                        end 
                    else 
                    outputChatBox("You can't use this command when you are inside 366 dimension",thePlayer,255,0,0) 
                end 
            end 
        end 
    end 
end 
addCommandHandler( "fixv", fixVeh ) 

Link to comment

@Walid

if thePlayer and isElement(thePlayer) then 

Is completely unnecessary with onCommandHandler as it'll always be a player element.

@shaman123

It's not recommended nor necessary to use setElementData (read here). Try a table:

local carsBeingFixed = {} 
  
function fixVeh(thePlayer) 
    if isObjectInACLGroup("user.".. getAccountName(getPlayerAccount(thePlayer)),aclGetGroup("DL3")) then 
        if getElementDimension(thePlayer) == 366 then 
            local vehicle = getPedOccupiedVehicle(thePlayer) 
            if vehicle then 
                if carsBeingFixed[vehicle] then 
                    outputChatBox("Your car is already being fixed.",thePlayer) 
                    return 
                end 
                outputChatBox("Your car is being fixed. Please wait a few moments.",thePlayer) 
                carsBeingFixed[vehicle] = setTimer(function() 
                    fixVehicle(vehicle) 
                    carsBeingFixed[vehicle] = nil 
                    outputChatBox("Your car has been fixed.",thePlayer) 
                end,15000,1) 
            end 
        else 
            outputChatBox("You can only use this command in dimension 366",thePlayer) 
        end 
    end 
end 
addCommandHandler("fixv",fixVeh) 

Cool thing about this is you could also use it in roleplay evironments if you add some small changes (colshape etc..) where you have to leave your car at the repair shop and pick it up later.

Sorry, no disrespect to you guys providing examples! Hope this will help.

@DonOmar This fixes the vehicle of the player that executes the command:

local vehicle = getPedOccupiedVehicle(thePlayer) 

This would fix vehicle in the server when you execute the command:

for _, vehicle in ipairs ( getElementsByType ( 'vehicle' ) ) do 

Link to comment
local carsBeingFixed = {} 
  
function fixVeh(thePlayer) 
    if isObjectInACLGroup("user.".. getAccountName(getPlayerAccount(thePlayer)),aclGetGroup("DL3")) then 
        if getElementDimension(thePlayer) == 366 then 
            local vehicle = getPedOccupiedVehicle(thePlayer) 
            if vehicle then 
                if carsBeingFixed[vehicle] then 
                    outputChatBox("Your car is already being fixed.",thePlayer) 
                    return 
                end 
                outputChatBox("Your car is being fixed. Please wait a few moments.",thePlayer) 
                carsBeingFixed[vehicle] = setTimer(function() 
                    fixVehicle(vehicle) 
                    carsBeingFixed[vehicle] = nil 
                    outputChatBox("Your car has been fixed.",thePlayer) 
                end,15000,1) 
            end 
        else 
            outputChatBox("You can only use this command in dimension 366",thePlayer) 
        end 
    end 
end 
addCommandHandler("fixv",fixVeh) 

Sorry, no disrespect to you guys providing examples! Hope this will help.

that's a great example, and btw he wants the command disabled in Dimension 366 so..:

local carsBeingFixed = {} 
  
function fixVeh(thePlayer) 
    if isObjectInACLGroup("user.".. getAccountName(getPlayerAccount(thePlayer)),aclGetGroup("DL3")) then 
        if getElementDimension(thePlayer) ~= 366 then 
            local vehicle = getPedOccupiedVehicle(thePlayer) 
            if vehicle then 
                if carsBeingFixed[vehicle] then 
                    outputChatBox("Your car is already being fixed.",thePlayer) 
                    return 
                end 
                outputChatBox("Your car is being fixed. Please wait a few moments.",thePlayer) 
                carsBeingFixed[vehicle] = setTimer(function() 
                    fixVehicle(vehicle) 
                    carsBeingFixed[vehicle] = nil 
                    outputChatBox("Your car has been fixed.",thePlayer) 
                end,15000,1) 
            end 
        else 
            outputChatBox("This command(fixv) is disabled in the dimension 366",thePlayer) 
        end 
    end 
end 
addCommandHandler("fixv",fixVeh) 

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