├── README.md ├── client └── cl_main.lua ├── config └── sh_config.lua ├── fxmanifest.lua └── server └── sv_main.lua /README.md: -------------------------------------------------------------------------------- 1 | # This Repository is going to Archive 2 | Pls Use 3 | https://github.com/Disabled-Coding/dc-shiftlog 4 | this is fixed and the best . Tnx For Chatty 5 | 6 | # QBCore Job Shift Log 7 | 8 | ![Police Job](https://cdn.discordapp.com/attachments/911895850148560917/912792069939032144/unknown.png) 9 | ![EMS Job](https://cdn.discordapp.com/attachments/911895850148560917/912791998631649310/unknown.png) 10 | ![Mechanic Job](https://cdn.discordapp.com/attachments/911895850148560917/912792069939032144/unknown.png) 11 | 12 | # Idea From https://github.com/utkuali/Shift-Log-to-Discord 13 | -------------------------------------------------------------------------------- /client/cl_main.lua: -------------------------------------------------------------------------------- 1 | local QBCore = exports['qb-core']:GetCoreObject() -- We've ALWAYS got to grab our core object 2 | 3 | local currentjob = {} 4 | 5 | RegisterNetEvent("QBCore:Client:OnPlayerLoaded") 6 | AddEventHandler("QBCore:Client:OnPlayerLoaded", function() 7 | local Player=QBCore.Functions.GetPlayerData() 8 | local job = Player.job 9 | print(json.encode(Player.job)) 10 | currentjob = job 11 | if job == "police" or job == "ambulance" or job == "mechanic" then -- job's name here 12 | TriggerServerEvent("qb-shiftlog:userjoined", job) 13 | end 14 | end) 15 | 16 | RegisterNetEvent('QBCore:Client:OnJobUpdate') 17 | AddEventHandler('QBCore:Client:OnJobUpdate', function(job) 18 | Wait(100) 19 | 20 | if job.name == "police" or job.name == "ambulance" or job.name == "mechanic" then -- job's name here 21 | if job.onduty == false then 22 | TriggerEvent("qb-shiftlog:jobchanged", job, job, 1, src) 23 | end 24 | 25 | end 26 | currentjob = job 27 | end) 28 | 29 | 30 | -------------------------------------------------------------------------------- /config/sh_config.lua: -------------------------------------------------------------------------------- 1 | -- Wowow an epic shared file 2 | Config = {} -- We must initialise the config table to be able to do config.anything 3 | 4 | Config.policeWebhook="" 5 | Config.ambulanceWebhook="" 6 | Config.mechanicWebhook="" 7 | 8 | -------------------------------------------------------------------------------- /fxmanifest.lua: -------------------------------------------------------------------------------- 1 | fx_version 'cerulean' 2 | game 'gta5' 3 | 4 | description 'qb-shiftlog' 5 | version '1.0.0' 6 | author 'hAMID' 7 | 8 | shared_scripts { 9 | 'config/sh_config.lua' 10 | } 11 | 12 | client_scripts { 13 | 'client/*.lua' 14 | } 15 | 16 | server_scripts { 17 | 'server/*.lua' 18 | } -------------------------------------------------------------------------------- /server/sv_main.lua: -------------------------------------------------------------------------------- 1 | local QBCore = exports['qb-core']:GetCoreObject() -- Grabs our core object 2 | 3 | local timers = { -- if you want more job shifts add table entry here same as the examples below 4 | ambulance = { 5 | }, 6 | police = { 7 | }, 8 | mechanic = { 9 | }, 10 | -- fbi = {} 11 | } 12 | 13 | local currentjob = {} 14 | 15 | 16 | local dcname = "Shift Logger" -- bot's name 17 | local http = Config.policeWebhook -- webhook for police 18 | local httpAmbulance = Config.ambulanceWebhook -- webhook for ems (you can add as many as you want) 19 | local httpMechanic = Config.mechanicWebhook 20 | local avatar = "" -- bot's avatar 21 | 22 | function DiscordLog(name, message, color, job) 23 | local connect = { 24 | { 25 | ["color"] = color, 26 | ["title"] = "**".. name .."**", 27 | ["description"] = message, 28 | ["footer"] = { 29 | ["text"] = "qb-shiftlog", 30 | }, 31 | } 32 | } 33 | if job == "police" then 34 | PerformHttpRequest(http, function(err, text, headers) end, 'POST', json.encode({username = dcname, embeds = connect, avatar_url = avatar}), { ['Content-Type'] = 'application/json' }) 35 | elseif job == "ambulance" then 36 | PerformHttpRequest(httpAmbulance, function(err, text, headers) end, 'POST', json.encode({username = dcname, embeds = connect, avatar_url = avatar}), { ['Content-Type'] = 'application/json' }) 37 | elseif job == "mechanic" then 38 | PerformHttpRequest(httpMechanic, function(err, text, headers) end, 'POST', json.encode({username = dcname, embeds = connect, avatar_url = avatar}), { ['Content-Type'] = 'application/json' }) 39 | end 40 | end 41 | 42 | RegisterServerEvent("qb-shiftlog:userjoined") 43 | AddEventHandler("qb-shiftlog:userjoined", function(job) 44 | local id = source 45 | local xPlayer = QBCore.Functions.GetPlayer(id) 46 | 47 | if job.onduty == true then 48 | table.insert(timers[job.name], {id = id, citizenid = xPlayer.citizenid, name = xPlayer.charinfo.firstname.." "..xPlayer.charinfo.lastname, time = os.time(), date = os.date("%d/%m/%Y %X")}) 49 | end 50 | end) 51 | RegisterServerEvent("qb-shiftlog:jobchanged") 52 | AddEventHandler("qb-shiftlog:jobchanged", function(old, new, method,src) 53 | if src == nil then 54 | src = source 55 | end 56 | local xPlayer = QBCore.Functions.GetPlayer(src) 57 | xPlayer=xPlayer.PlayerData 58 | local header = nil 59 | local color = nil 60 | if old.name == "police" then 61 | header = "Police Shift" -- Header 62 | color = 3447003 -- Color 63 | elseif old.name == "ambulance" then 64 | header = "EMS Shift" 65 | color = 15158332 66 | elseif old.name == "mechanic" then 67 | header = "Mechanic Shift" 68 | color = 13400320 69 | --elseif job == "fbi" then 70 | --header = "FBI Shift" 71 | --color = 3447003 72 | end 73 | if method == 1 then 74 | for i,v in ipairs(timers[old.name]) do 75 | if v.citizenid == xPlayer.citizenid then 76 | local duration = os.time() - v.time 77 | local date = v.date 78 | local timetext = nil 79 | 80 | if duration > 0 and duration < 60 then 81 | timetext = tostring(math.floor(duration)).." seconds" 82 | elseif duration >= 60 and duration < 3600 then 83 | timetext = tostring(math.floor(duration / 60)).." minutes" 84 | elseif duration >= 3600 then 85 | timetext = tostring(math.floor(duration / 3600).." hours, "..tostring(math.floor(math.fmod(duration, 3600)) / 60)).." minutes" 86 | end 87 | DiscordLog(header , "Name: **"..v.name.."**\ncitizenid: **"..v.citizenid.."**\n Shift duration: **__"..timetext.."__**\n Start date: **"..date.."**\n End date: **"..os.date("%d/%m/%Y %X").."**", color, old.name) 88 | table.remove(timers[old.name], i) 89 | break 90 | end 91 | end 92 | end 93 | if not (timers[new.name] == nil) then 94 | for t, l in pairs(timers[new.name]) do 95 | if l.citizenid == xPlayer.citizenid then 96 | table.remove(timers[new.name], t) 97 | end 98 | end 99 | end 100 | if new.name == "police" or new.name == "ambulance" or new.name =="mechanic" then 101 | table.insert(timers[new.name], {citizenid = xPlayer.citizenid, name = xPlayer.charinfo.firstname.." "..xPlayer.charinfo.lastname, time = os.time(), date = os.date("%d/%m/%Y %X")}) 102 | end 103 | end) 104 | 105 | 106 | 107 | RegisterNetEvent('QBCore:ToggleDuty', function() 108 | local src = source 109 | local Player = QBCore.Functions.GetPlayer(src) 110 | Player=Player.PlayerData 111 | local job = Player.job 112 | if job.name == "police" or job.name == "ambulance" or job.name == "mechanic" then -- job's name here 113 | if job.onduty == false then 114 | TriggerEvent("qb-shiftlog:jobchanged", currentjob, job, 1, src) 115 | else 116 | TriggerEvent("qb-shiftlog:jobchanged", currentjob, job, 0, src) 117 | end 118 | 119 | end 120 | currentjob = job 121 | end) 122 | 123 | 124 | AddEventHandler("playerDropped", function(reason) 125 | local id = source 126 | local header = nil 127 | local color = nil 128 | 129 | for k, v in pairs(timers) do 130 | for n = 1, #timers[k], 1 do 131 | if timers[k][n].id == id then 132 | local duration = os.time() - timers[k][n].time 133 | local date = timers[k][n].date 134 | local timetext = nil 135 | 136 | if k == "police" then 137 | header = "Police Shift" 138 | color = 3447003 139 | elseif k == "ambulance" then 140 | header = "EMS Shift" 141 | color = 15158332 142 | elseif old.name == "mechanic" then 143 | header = "Mechanic Shift" 144 | color = 13400320 145 | --elseif job == "fbi" then 146 | --header = "FBI Shift" 147 | --color = 3447003 148 | end 149 | if duration > 0 and duration < 60 then 150 | timetext = tostring(math.floor(duration)).." seconds" 151 | elseif duration >= 60 and duration < 3600 then 152 | timetext = tostring(math.floor(duration / 60)).." minutes" 153 | elseif duration >= 3600 then 154 | timetext = tostring(math.floor(duration / 3600).." hours, "..tostring(math.floor(math.fmod(duration, 3600)) / 60)).." minutes" 155 | end 156 | DiscordLog(header, "Name: **"..timers[k][n].name.."**\ncitizenid: **"..timers[k][n].identifier.."**\n Shift duration: **__"..timetext.."__**\n Start date: **"..date.."**\n End date: **"..os.date("%d/%m/%Y %X").."**", color, k) 157 | table.remove(timers[k], n) 158 | return 159 | end 160 | end 161 | end 162 | end) 163 | 164 | DiscordLog("[qb-shiftlog]", "Shift logger started!", 3447003, "police") --------------------------------------------------------------------------------