DonOmar Posted July 4, 2016 Share Posted July 4, 2016 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
Bean666 Posted July 4, 2016 Share Posted July 4, 2016 (edited) 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 July 4, 2016 by Guest Link to comment
Walid Posted July 4, 2016 Share Posted July 4, 2016 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
Bean666 Posted July 4, 2016 Share Posted July 4, 2016 (edited) 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 July 4, 2016 by Guest Link to comment
Walid Posted July 4, 2016 Share Posted July 4, 2016 (edited) it can be just like this: without using setTimer x2 setTimer(function (veh) fixVehicle(veh) outputChatBox("Fixed", thePlayer, 255, 0,0) end, 15000, 1, vehicle) Edited July 4, 2016 by Guest Link to comment
Bean666 Posted July 4, 2016 Share Posted July 4, 2016 @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
Tails Posted July 4, 2016 Share Posted July 4, 2016 @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
Bean666 Posted July 4, 2016 Share Posted July 4, 2016 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
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