Skip to content

Commit 398653c

Browse files
authored
Add Fivemerr Integration (#27)
1 parent f81b228 commit 398653c

File tree

4 files changed

+84
-36
lines changed

4 files changed

+84
-36
lines changed

client/cl_main.lua

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ local photoprop = nil
1414

1515
local Functions = exports[GetCurrentResourceName()]
1616

17-
local function grabWebhook()
17+
local function grabUploadDetails()
1818
local newEvent = nil
1919
local p = promise.new()
2020
local Key = Functions.Key()
@@ -24,7 +24,12 @@ local function grabWebhook()
2424
newEvent = RemoveEventHandler(newEvent)
2525
p:resolve(hook)
2626
end)
27-
TriggerServerEvent("ps-camera:requestWebhook", Key)
27+
28+
if Config.UseFivemerr == false then
29+
TriggerServerEvent("ps-camera:requestWebhook", Key)
30+
else
31+
TriggerServerEvent("ps-camera:requestFivemerrToken", Key)
32+
end
2833
return Citizen.Await(p)
2934
end
3035

@@ -177,7 +182,7 @@ function CameraLoop()
177182
CreateThread(function()
178183
local lPed = PlayerPedId()
179184
local vehicle = GetVehiclePedIsIn(lPed)
180-
local hook = grabWebhook()
185+
local uploadHookOrSecret = grabUploadDetails()
181186
Wait(500)
182187

183188
SetTimecycleModifier("default")
@@ -208,15 +213,34 @@ function CameraLoop()
208213
Wait(100)
209214
end
210215
PlaySoundFrontend(-1, "Camera_Shoot", "Phone_Soundset_Franklin", false)
211-
exports['screenshot-basic']:requestScreenshotUpload(tostring(hook), "files[]", function(data)
212-
local image = json.decode(data)
213-
camera = false
214-
if cameraprop then DeleteEntity(cameraprop) end
215-
ClearPedTasks(lPed)
216-
TriggerServerEvent("ps-camera:CreatePhoto", json.encode(image.attachments[1].proxy_url))
217-
SendNUIMessage({action = "SavePic", pic = json.encode(image.attachments[1].proxy_url)})
218-
SendNUIMessage({action = "hideOverlay"})
219-
end)
216+
217+
if Config.UseFivemerr == false then
218+
exports['screenshot-basic']:requestScreenshotUpload(tostring(uploadHookOrSecret), "files[]", function(data)
219+
local image = json.decode(data)
220+
camera = false
221+
if cameraprop then DeleteEntity(cameraprop) end
222+
ClearPedTasks(lPed)
223+
TriggerServerEvent("ps-camera:CreatePhoto", json.encode(image.attachments[1].proxy_url))
224+
SendNUIMessage({action = "SavePic", pic = json.encode(image.attachments[1].proxy_url)})
225+
SendNUIMessage({action = "hideOverlay"})
226+
end)
227+
else
228+
exports['screenshot-basic']:requestScreenshotUpload("https://api.fivemerr.com/v1/media/images", "file", {
229+
headers = {
230+
Authorization = tostring(uploadHookOrSecret)
231+
},
232+
encoding = 'png'
233+
}, function(data)
234+
local image = json.decode(data)
235+
camera = false
236+
if cameraprop then DeleteEntity(cameraprop) end
237+
ClearPedTasks(lPed)
238+
local link = (image and image.url) or 'invalid_url'
239+
TriggerServerEvent("ps-camera:CreatePhoto", json.encode(link))
240+
SendNUIMessage({action = "SavePic", pic = json.encode(link)})
241+
SendNUIMessage({action = "hideOverlay"})
242+
end)
243+
end
220244
Wait(100) -- You can adjust the timing if needed
221245
ClearTimecycleModifier()
222246
end
@@ -298,4 +322,3 @@ RegisterNetEvent('ps-camera:useCamera', function()
298322
SendNUIMessage({action = "hideOverlay"})
299323
end
300324
end)
301-

config.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
Config = Config or {}
22

3+
Config.UseFivemerr = true

fxmanifest.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ author 'Project Sloth Team'
66

77
description 'Camera script'
88

9-
version '1.0.6'
9+
version '1.1.0'
1010

1111
lua54 'yes'
1212

server/sv_main.lua

Lines changed: 46 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
local QBCore = exports['qb-core']:GetCoreObject()
2-
Config = {
2+
3+
SvConfig = {
34
Inv = "qb", -- qb(=lj) or ox [Inventory system]
45
webhook = "", -- Add Discord webhook
6+
FivemerrApiToken = '',
57
}
68
local function ConfigInvInvalid()
7-
print('^1[Error] Your Config.Inv isnt set.. you probably had a typo\nYou have it set as= Config.Inv = "'.. Config.Inv .. '"')
9+
print('^1[Error] Your SvConfig.Inv isnt set.. you probably had a typo\nYou have it set as= SvConfig.Inv = "'.. SvConfig.Inv .. '"')
810
end
911

1012
RegisterNetEvent("ps-camera:cheatDetect", function()
@@ -14,13 +16,29 @@ end)
1416
RegisterNetEvent("ps-camera:requestWebhook", function(Key)
1517
local source = source
1618
local event = ("ps-camera:grabbed%s"):format(Key)
17-
if Config.webhook == '' then
18-
print("^1[Error] A webhook is missing in: Config.webhook")
19+
20+
if SvConfig.webhook == '' then
21+
print("^1[Error] A webhook is missing in: SvConfig.webhook")
1922
else
20-
TriggerClientEvent(event, source, Config.webhook)
23+
TriggerClientEvent(event, source, SvConfig.webhook)
2124
end
2225
end)
2326

27+
RegisterNetEvent('ps-camera:requestFivemerrToken', function(Key)
28+
local source = source
29+
local event = ("ps-camera:grabbed%s"):format(Key)
30+
31+
if Config.UseFivemerr == false then
32+
return print("^1[Error] Requesting Fivemerr token but Config.UseFivemerr set to false.")
33+
end
34+
35+
if SvConfig.FivemerrApiToken == '' then
36+
return print("^1[Error] Your Fivemerr API Token is missing in: Config.FivemerrApiToken")
37+
end
38+
39+
TriggerClientEvent(event, source, SvConfig.FivemerrApiToken)
40+
end)
41+
2442
RegisterNetEvent("ps-camera:CreatePhoto", function(url)
2543
local source = source
2644
local player = QBCore.Functions.GetPlayer(source)
@@ -43,15 +61,15 @@ RegisterNetEvent("ps-camera:savePhoto", function(url, streetName)
4361
ps_image = url,
4462
location = location
4563
}
46-
if not (Config.Inv == "qb" or Config.Inv == "ox") then
64+
if not (SvConfig.Inv == "qb" or SvConfig.Inv == "ox") then
4765
ConfigInvInvalid()
4866
return;
4967
end
5068

51-
if Config.Inv == "qb" then
69+
if SvConfig.Inv == "qb" then
5270
player.Functions.AddItem("photo", 1, nil, info)
5371
TriggerClientEvent('inventory:client:ItemBox', source, QBCore.Shared.Items['photo'], "add")
54-
elseif Config.Inv == "ox" then
72+
elseif SvConfig.Inv == "ox" then
5573
local ox_inventory = exports.ox_inventory
5674

5775
if not ox_inventory:CanCarryItem(source, 'photo', 1) then
@@ -67,21 +85,27 @@ end)
6785
QBCore.Functions.CreateUseableItem("camera", function(source, item)
6886
local source = source
6987
local Player = QBCore.Functions.GetPlayer(source)
70-
if not (Config.Inv == "qb" or Config.Inv == "ox") then
88+
if not (SvConfig.Inv == "qb" or SvConfig.Inv == "ox") then
7189
ConfigInvInvalid()
7290
return;
7391
end
7492

75-
if not Config.webhook or Config.webhook == nil or Config.webhook == "" then
76-
print("^1[Error] A webhook is missing in: Config.webhook")
77-
return;
93+
if Config.UseFivemerr == false then
94+
if not SvConfig.webhook or SvConfig.webhook == nil or SvConfig.webhook == "" then
95+
print("^1[Error] A webhook is missing in: SvConfig.webhook")
96+
return;
97+
end
98+
else
99+
if not SvConfig.FivemerrApiToken or SvConfig.FivemerrApiToken == '' then
100+
return print("^1[Error] A webhook is missing in: SvConfig.FivemerrApiToken")
101+
end
78102
end
79103

80-
if Config.Inv == "qb" then
104+
if SvConfig.Inv == "qb" then
81105
if Player.Functions.GetItemByName(item.name) then
82106
TriggerClientEvent("ps-camera:useCamera", source)
83107
end
84-
elseif Config.Inv == "ox" then
108+
elseif SvConfig.Inv == "ox" then
85109
local ox_inventory = exports.ox_inventory
86110
if ox_inventory:GetItem(source, item.name, nil, true) > 0 then
87111
TriggerClientEvent("ps-camera:useCamera", source)
@@ -93,16 +117,16 @@ end)
93117
QBCore.Functions.CreateUseableItem("photo", function(source, item)
94118
local source = source
95119
local Player = QBCore.Functions.GetPlayer(source)
96-
if not (Config.Inv == "qb" or Config.Inv == "ox") then
120+
if not (SvConfig.Inv == "qb" or SvConfig.Inv == "ox") then
97121
ConfigInvInvalid()
98122
return;
99123
end
100124

101-
if Config.Inv == "qb" then
125+
if SvConfig.Inv == "qb" then
102126
if Player.Functions.GetItemByName(item.name) then
103127
TriggerClientEvent("ps-camera:usePhoto", source, item.info.ps_image, item.info.location)
104128
end
105-
elseif Config.Inv == "ox" then
129+
elseif SvConfig.Inv == "ox" then
106130
local ox_inventory = exports.ox_inventory
107131
if ox_inventory:GetItem(source, item.name, nil, true) > 0 then
108132
TriggerClientEvent("ps-camera:usePhoto", source, item.metadata.ps_image, item.metadata.location)
@@ -113,23 +137,23 @@ end)
113137
function UseCam(source)
114138
local source = source
115139
local Player = QBCore.Functions.GetPlayer(source)
116-
if not (Config.Inv == "qb" or Config.Inv == "ox") then
140+
if not (SvConfig.Inv == "qb" or SvConfig.Inv == "ox") then
117141
ConfigInvInvalid()
118142
return;
119143
end
120144

121-
if not Config.webhook or Config.webhook == nil or Config.webhook == "" then
122-
print("^1[Error] A webhook is missing in: Config.webhook")
145+
if not SvConfig.webhook or SvConfig.webhook == nil or SvConfig.webhook == "" then
146+
print("^1[Error] A webhook is missing in: SvConfig.webhook")
123147
return;
124148
end
125149

126-
if Config.Inv == "qb" then
150+
if SvConfig.Inv == "qb" then
127151
if Player.Functions.GetItemByName('dslrcamera') then
128152
TriggerClientEvent("ps-camera:useCamera", source)
129153
else
130154
TriggerClientEvent('QBCore:Notify', source, "U don\'t have a camera", "error")
131155
end
132-
elseif Config.Inv == "ox" then
156+
elseif SvConfig.Inv == "ox" then
133157
local ox_inventory = exports.ox_inventory
134158
if ox_inventory:GetItem(source, 'dslrcamera', nil, true) > 0 then
135159
TriggerClientEvent("ps-camera:useCamera", source)

0 commit comments

Comments
 (0)