Skip to content

Commit

Permalink
Add Fivemerr Integration (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
DeeRock94 authored Jul 26, 2024
1 parent f81b228 commit 398653c
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 36 deletions.
49 changes: 36 additions & 13 deletions client/cl_main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ local photoprop = nil

local Functions = exports[GetCurrentResourceName()]

local function grabWebhook()
local function grabUploadDetails()
local newEvent = nil
local p = promise.new()
local Key = Functions.Key()
Expand All @@ -24,7 +24,12 @@ local function grabWebhook()
newEvent = RemoveEventHandler(newEvent)
p:resolve(hook)
end)
TriggerServerEvent("ps-camera:requestWebhook", Key)

if Config.UseFivemerr == false then
TriggerServerEvent("ps-camera:requestWebhook", Key)
else
TriggerServerEvent("ps-camera:requestFivemerrToken", Key)
end
return Citizen.Await(p)
end

Expand Down Expand Up @@ -177,7 +182,7 @@ function CameraLoop()
CreateThread(function()
local lPed = PlayerPedId()
local vehicle = GetVehiclePedIsIn(lPed)
local hook = grabWebhook()
local uploadHookOrSecret = grabUploadDetails()
Wait(500)

SetTimecycleModifier("default")
Expand Down Expand Up @@ -208,15 +213,34 @@ function CameraLoop()
Wait(100)
end
PlaySoundFrontend(-1, "Camera_Shoot", "Phone_Soundset_Franklin", false)
exports['screenshot-basic']:requestScreenshotUpload(tostring(hook), "files[]", function(data)
local image = json.decode(data)
camera = false
if cameraprop then DeleteEntity(cameraprop) end
ClearPedTasks(lPed)
TriggerServerEvent("ps-camera:CreatePhoto", json.encode(image.attachments[1].proxy_url))
SendNUIMessage({action = "SavePic", pic = json.encode(image.attachments[1].proxy_url)})
SendNUIMessage({action = "hideOverlay"})
end)

if Config.UseFivemerr == false then
exports['screenshot-basic']:requestScreenshotUpload(tostring(uploadHookOrSecret), "files[]", function(data)
local image = json.decode(data)
camera = false
if cameraprop then DeleteEntity(cameraprop) end
ClearPedTasks(lPed)
TriggerServerEvent("ps-camera:CreatePhoto", json.encode(image.attachments[1].proxy_url))
SendNUIMessage({action = "SavePic", pic = json.encode(image.attachments[1].proxy_url)})
SendNUIMessage({action = "hideOverlay"})
end)
else
exports['screenshot-basic']:requestScreenshotUpload("https://api.fivemerr.com/v1/media/images", "file", {
headers = {
Authorization = tostring(uploadHookOrSecret)
},
encoding = 'png'
}, function(data)
local image = json.decode(data)
camera = false
if cameraprop then DeleteEntity(cameraprop) end
ClearPedTasks(lPed)
local link = (image and image.url) or 'invalid_url'
TriggerServerEvent("ps-camera:CreatePhoto", json.encode(link))
SendNUIMessage({action = "SavePic", pic = json.encode(link)})
SendNUIMessage({action = "hideOverlay"})
end)
end
Wait(100) -- You can adjust the timing if needed
ClearTimecycleModifier()
end
Expand Down Expand Up @@ -298,4 +322,3 @@ RegisterNetEvent('ps-camera:useCamera', function()
SendNUIMessage({action = "hideOverlay"})
end
end)

1 change: 1 addition & 0 deletions config.lua
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Config = Config or {}

Config.UseFivemerr = true
2 changes: 1 addition & 1 deletion fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ author 'Project Sloth Team'

description 'Camera script'

version '1.0.6'
version '1.1.0'

lua54 'yes'

Expand Down
68 changes: 46 additions & 22 deletions server/sv_main.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
local QBCore = exports['qb-core']:GetCoreObject()
Config = {

SvConfig = {
Inv = "qb", -- qb(=lj) or ox [Inventory system]
webhook = "", -- Add Discord webhook
FivemerrApiToken = '',
}
local function ConfigInvInvalid()
print('^1[Error] Your Config.Inv isnt set.. you probably had a typo\nYou have it set as= Config.Inv = "'.. Config.Inv .. '"')
print('^1[Error] Your SvConfig.Inv isnt set.. you probably had a typo\nYou have it set as= SvConfig.Inv = "'.. SvConfig.Inv .. '"')
end

RegisterNetEvent("ps-camera:cheatDetect", function()
Expand All @@ -14,13 +16,29 @@ end)
RegisterNetEvent("ps-camera:requestWebhook", function(Key)
local source = source
local event = ("ps-camera:grabbed%s"):format(Key)
if Config.webhook == '' then
print("^1[Error] A webhook is missing in: Config.webhook")

if SvConfig.webhook == '' then
print("^1[Error] A webhook is missing in: SvConfig.webhook")
else
TriggerClientEvent(event, source, Config.webhook)
TriggerClientEvent(event, source, SvConfig.webhook)
end
end)

RegisterNetEvent('ps-camera:requestFivemerrToken', function(Key)
local source = source
local event = ("ps-camera:grabbed%s"):format(Key)

if Config.UseFivemerr == false then
return print("^1[Error] Requesting Fivemerr token but Config.UseFivemerr set to false.")
end

if SvConfig.FivemerrApiToken == '' then
return print("^1[Error] Your Fivemerr API Token is missing in: Config.FivemerrApiToken")
end

TriggerClientEvent(event, source, SvConfig.FivemerrApiToken)
end)

RegisterNetEvent("ps-camera:CreatePhoto", function(url)
local source = source
local player = QBCore.Functions.GetPlayer(source)
Expand All @@ -43,15 +61,15 @@ RegisterNetEvent("ps-camera:savePhoto", function(url, streetName)
ps_image = url,
location = location
}
if not (Config.Inv == "qb" or Config.Inv == "ox") then
if not (SvConfig.Inv == "qb" or SvConfig.Inv == "ox") then
ConfigInvInvalid()
return;
end

if Config.Inv == "qb" then
if SvConfig.Inv == "qb" then
player.Functions.AddItem("photo", 1, nil, info)
TriggerClientEvent('inventory:client:ItemBox', source, QBCore.Shared.Items['photo'], "add")
elseif Config.Inv == "ox" then
elseif SvConfig.Inv == "ox" then
local ox_inventory = exports.ox_inventory

if not ox_inventory:CanCarryItem(source, 'photo', 1) then
Expand All @@ -67,21 +85,27 @@ end)
QBCore.Functions.CreateUseableItem("camera", function(source, item)
local source = source
local Player = QBCore.Functions.GetPlayer(source)
if not (Config.Inv == "qb" or Config.Inv == "ox") then
if not (SvConfig.Inv == "qb" or SvConfig.Inv == "ox") then
ConfigInvInvalid()
return;
end

if not Config.webhook or Config.webhook == nil or Config.webhook == "" then
print("^1[Error] A webhook is missing in: Config.webhook")
return;
if Config.UseFivemerr == false then
if not SvConfig.webhook or SvConfig.webhook == nil or SvConfig.webhook == "" then
print("^1[Error] A webhook is missing in: SvConfig.webhook")
return;
end
else
if not SvConfig.FivemerrApiToken or SvConfig.FivemerrApiToken == '' then
return print("^1[Error] A webhook is missing in: SvConfig.FivemerrApiToken")
end
end

if Config.Inv == "qb" then
if SvConfig.Inv == "qb" then
if Player.Functions.GetItemByName(item.name) then
TriggerClientEvent("ps-camera:useCamera", source)
end
elseif Config.Inv == "ox" then
elseif SvConfig.Inv == "ox" then
local ox_inventory = exports.ox_inventory
if ox_inventory:GetItem(source, item.name, nil, true) > 0 then
TriggerClientEvent("ps-camera:useCamera", source)
Expand All @@ -93,16 +117,16 @@ end)
QBCore.Functions.CreateUseableItem("photo", function(source, item)
local source = source
local Player = QBCore.Functions.GetPlayer(source)
if not (Config.Inv == "qb" or Config.Inv == "ox") then
if not (SvConfig.Inv == "qb" or SvConfig.Inv == "ox") then
ConfigInvInvalid()
return;
end

if Config.Inv == "qb" then
if SvConfig.Inv == "qb" then
if Player.Functions.GetItemByName(item.name) then
TriggerClientEvent("ps-camera:usePhoto", source, item.info.ps_image, item.info.location)
end
elseif Config.Inv == "ox" then
elseif SvConfig.Inv == "ox" then
local ox_inventory = exports.ox_inventory
if ox_inventory:GetItem(source, item.name, nil, true) > 0 then
TriggerClientEvent("ps-camera:usePhoto", source, item.metadata.ps_image, item.metadata.location)
Expand All @@ -113,23 +137,23 @@ end)
function UseCam(source)
local source = source
local Player = QBCore.Functions.GetPlayer(source)
if not (Config.Inv == "qb" or Config.Inv == "ox") then
if not (SvConfig.Inv == "qb" or SvConfig.Inv == "ox") then
ConfigInvInvalid()
return;
end

if not Config.webhook or Config.webhook == nil or Config.webhook == "" then
print("^1[Error] A webhook is missing in: Config.webhook")
if not SvConfig.webhook or SvConfig.webhook == nil or SvConfig.webhook == "" then
print("^1[Error] A webhook is missing in: SvConfig.webhook")
return;
end

if Config.Inv == "qb" then
if SvConfig.Inv == "qb" then
if Player.Functions.GetItemByName('dslrcamera') then
TriggerClientEvent("ps-camera:useCamera", source)
else
TriggerClientEvent('QBCore:Notify', source, "U don\'t have a camera", "error")
end
elseif Config.Inv == "ox" then
elseif SvConfig.Inv == "ox" then
local ox_inventory = exports.ox_inventory
if ox_inventory:GetItem(source, 'dslrcamera', nil, true) > 0 then
TriggerClientEvent("ps-camera:useCamera", source)
Expand Down

0 comments on commit 398653c

Please sign in to comment.