Pacheco465 Posted August 2, 2020 Share Posted August 2, 2020 (edited) Como eu poderia adicionar delay ao comando neste script? function repararveiculo ( source ) local accName = getAccountName ( getPlayerAccount ( source ) ) if isObjectInACLGroup("user." .. accName, aclGetGroup("Staff")) then if isPedInVehicle ( source ) then return end local x, y, z = getElementPosition(source) local colcarros = createColSphere ( x, y, z, 2) local vehicle = getElementsWithinColShape ( colcarros, "vehicle" ) destroyElement(colcarros) setPedAnimation( source, "CAR", "Fixn_Car_Loop", 4500, true, false, false, false) for theKey, veh in ipairs(vehicle) do setTimer ( function() fixVehicle(veh) end, 4500, 1 ) end end end addCommandHandler ( "fix", repararveiculo ) function displayVehicleLoss(loss) if getElementHealth(source) <= 255 then setElementHealth(source, 255.5) setVehicleEngineState(source, false) setVehicleDamageProof(source, true) else if isVehicleDamageProof(source) then setVehicleDamageProof(source, false) end end end addEventHandler("onVehicleDamage", getRootElement(), displayVehicleLoss) function displayVehicleLoss2() if getElementHealth(source) <= 255 then setVehicleEngineState(source, false) else if isVehicleDamageProof(source) then setVehicleDamageProof(source, false) end end end addEventHandler("onVehicleEnter", getRootElement(), displayVehicleLoss2) function DestroyVeiculo () destroyElement (veh[source]) end addEventHandler ("onPlayerLogout", root, DestroyVeiculo) addEventHandler ("onPlayerQuit", root, DestroyVeiculo) Tentei usar o setTimer mas não consegui muito bem, alguém poderia colocar este script com o delay já ou poderia dar um exemplo por favor? Edited August 2, 2020 by Pacheco465 Link to comment
DNL291 Posted August 2, 2020 Share Posted August 2, 2020 local tPlayers = {} -- tabela global, esta irá armazenar os jogadores com o tempo que usou o comando local tempo = 5000 -- 5 segundos em milissegundos function repararveiculo ( source ) local accName = getAccountName ( getPlayerAccount ( source ) ) if isObjectInACLGroup("user." .. accName, aclGetGroup("Staff")) then if isPedInVehicle ( source ) then return end -- verificar se existe o tempo vinculado ao jogador; verificar quanto tempo passou desde que usou da última vez if tPlayers[source] and (getTickCount(source) - tPlayers[source]) < tempo then -- parar a execução aqui return outputChatBox( "Aguarde um tempo para usar este comando novamente", source, 230,0,0 ) end tPlayers[source] = getTickCount(source) -- armazenar o tempo em que o jogador usou o comando local x, y, z = getElementPosition(source) local colcarros = createColSphere ( x, y, z, 2) local vehicle = getElementsWithinColShape ( colcarros, "vehicle" ) destroyElement(colcarros) setPedAnimation( source, "CAR", "Fixn_Car_Loop", 4500, true, false, false, false) for theKey, veh in ipairs(vehicle) do setTimer ( function() fixVehicle(veh) end, 4500, 1 ) end end end addCommandHandler ( "fix", repararveiculo ) -- otimização addEventHandler("onPlayerQuit", root, function() -- remover da tabela global ao sair do servidor if tPlayers[source] then tPlayers[source] = nil end end) Leia os comentários do código. 1 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