-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.lua
More file actions
78 lines (65 loc) · 3.43 KB
/
Copy pathserver.lua
File metadata and controls
78 lines (65 loc) · 3.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
local ESX = exports['es_extended']:getSharedObject()
local function GetRelationshipStatus(player1, player2)
local result = MySQL.Sync.fetchScalar('SELECT status FROM relationships WHERE (player1 = @player1 AND player2 = @player2) OR (player1 = @player2 AND player2 = @player1)', {
['@player1'] = player1,
['@player2'] = player2
})
return result or 0
end
local function UpdateRelationshipStatus(player1, player2, status)
MySQL.Async.execute('INSERT INTO relationships (player1, player2, status) VALUES (@player1, @player2, @status) ON DUPLICATE KEY UPDATE status = @status', {
['@player1'] = player1,
['@player2'] = player2,
['@status'] = status
})
end
local function SendDiscordWebhook(message)
PerformHttpRequest(Config.DiscordWebhook.Url, function(err, text, headers) end, 'POST', json.encode({content = message}), { ['Content-Type'] = 'application/json' })
end
RegisterNetEvent('passions_relationship:checkRelationship')
AddEventHandler('passions_relationship:checkRelationship', function(targetId)
local xPlayer = ESX.GetPlayerFromId(source)
local xTarget = ESX.GetPlayerFromId(targetId)
if xPlayer and xTarget then
local status = GetRelationshipStatus(xPlayer.source, xTarget.source)
TriggerClientEvent('passions_relationship:openUI', xPlayer.source, status)
end
end)
RegisterNetEvent('passions_relationship:uploadPhoto')
AddEventHandler('passions_relationship:uploadPhoto', function(photoUrl)
local xPlayer = ESX.GetPlayerFromId(source)
local xTarget = ESX.GetPlayerFromId(targetId)
if xPlayer and xTarget then
local relationshipId = MySQL.Sync.fetchScalar('SELECT id FROM relationships WHERE (player1 = @player1 AND player2 = @player2) OR (player1 = @player2 AND player2 = @player1)', {
['@player1'] = xPlayer.source,
['@player2'] = xTarget.source
})
if relationshipId then
MySQL.Async.execute('INSERT INTO relationship_photos (relationship_id, photo_url, uploaded_by) VALUES (@relationship_id, @photo_url, @uploaded_by)', {
['@relationship_id'] = relationshipId,
['@photo_url'] = photoUrl,
['@uploaded_by'] = xPlayer.source
})
SendDiscordWebhook('New photo uploaded by ' .. xPlayer.getName() .. ' for relationship with ' .. xTarget.getName())
end
end
end)
RegisterNetEvent('passions_relationship:sendGift')
AddEventHandler('passions_relationship:sendGift', function(giftName)
local xPlayer = ESX.GetPlayerFromId(source)
local xTarget = ESX.GetPlayerFromId(targetId)
if xPlayer and xTarget then
local relationshipId = MySQL.Sync.fetchScalar('SELECT id FROM relationships WHERE (player1 = @player1 AND player2 = @player2) OR (player1 = @player2 AND player2 = @player1)', {
['@player1'] = xPlayer.source,
['@player2'] = xTarget.source
})
if relationshipId then
MySQL.Async.execute('INSERT INTO relationship_gifts (relationship_id, gift_name, gifted_by) VALUES (@relationship_id, @gift_name, @gifted_by)', {
['@relationship_id'] = relationshipId,
['@gift_name'] = giftName,
['@gifted_by'] = xPlayer.source
})
SendDiscordWebhook('New gift sent by ' .. xPlayer.getName() .. ' for relationship with ' .. xTarget.getName())
end
end
end)