local CurrentAddictions = {} local isWithdrawalActive = false -- Sync addictions from server RegisterNetEvent('drc_drugs:client:syncAddictions', function(addictions) CurrentAddictions = addictions SendNUIMessage({ action = 'updateAddictions', addictions = addictions }) end) -- Withdrawal Loop CreateThread(function() while true do local wait = 1000 if Config.Addiction.Enabled then local currentTime = GetCloudTimeAsInt() -- Use cloud time for consistency local isAddicted = false local highestAddiction = 0 for drug, data in pairs(CurrentAddictions) do if data.level > 0 then isAddicted = true if data.level > highestAddiction then highestAddiction = data.level end -- Check if withdrawal should start local timeSinceLastDose = GetTimeDifference(currentTime, data.lastDose) if timeSinceLastDose > Config.Addiction.Effects.WithdrawalTime then TriggerWithdrawalEffect(data.level) wait = 10000 -- Run every 10 seconds as requested end end end if not isAddicted then wait = 5000 -- Slower check if not addicted end else wait = 10000 -- Slower check if system disabled end Wait(wait) end end) function TriggerWithdrawalEffect(level) if not Config.Addiction.Enabled then return end -- Professional withdrawal feeling -- 1. Notify lib.notify({ title = 'Yoksunluk Krizi', description = Config.Addiction.WithdrawalWarning, type = 'error' }) -- 2. Screen Blur (Progressive) local blurIn = (level / 100) * Config.Addiction.Effects.BlurIntensity SetTimecycleModifier("spectator5") SetTimecycleModifierStrength(blurIn) -- 3. Blackout (Realism - even while driving) if math.random() < Config.Addiction.Effects.BlackoutProbability then DoScreenFadeOut(500) Wait(1000) DoScreenFadeIn(1000) end -- 4. Shake local shakeIn = (level / 100) * Config.Addiction.Effects.ShakeIntensity ShakeGameplayCam("SMALL_EXPLOSION_SHAKE", shakeIn) -- 5. Audio effort PlaySoundFrontend(-1, "BASE_JUMP_PASSED", "HUD_AWARDS", 1) Wait(3000) -- Cleanup ClearTimecycleModifier() StopGameplayCamShaking(true) end -- Helper for time difference function GetTimeDifference(t2, t1) return os.difftime(t2, t1) end -- Sync on startup AddEventHandler('onResourceStart', function(resourceName) if (GetCurrentResourceName() ~= resourceName) then return end Wait(2000) if Config.Framework == "qbcore" then local QBCore = exports['qb-core']:GetCoreObject() local PlayerData = QBCore.Functions.GetPlayerData() if PlayerData and PlayerData.metadata then CurrentAddictions = PlayerData.metadata['addictions'] or {} SendNUIMessage({ action = 'updateAddictions', addictions = CurrentAddictions }) end end end)