-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.lua
65 lines (56 loc) · 2.52 KB
/
server.lua
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
----Gets ESX-----
ESX = nil
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
RegisterNetEvent('koe_mlobuy:getOwner')
AddEventHandler('koe_mlobuy:getOwner', function(locationid, locationprice, locationkey)
local src = source
local xPlayer = ESX.GetPlayerFromId(src)
local identifier = ESX.GetPlayerFromId(src).identifier
MySQL.Async.fetchAll('SELECT * FROM owned_mlos WHERE location = @location',
{
['@identifier'] = owner,
['@location'] = locationid
},
function(result)
if result[1].identifier == nil then
TriggerClientEvent('koe_mlobuy:buyMenu', src, locationid, locationprice, locationkey)
elseif result[1].identifier == identifier then
TriggerClientEvent('koe_mlobuy:ownerMenu', src, locationid, locationprice, locationkey)
else
TriggerClientEvent('ox_lib:notify', src, {type = 'error', description = "This property is owned."})
end
end)
end)
RegisterNetEvent('koe_mlobuy:purchaseTheProperty')
AddEventHandler('koe_mlobuy:purchaseTheProperty', function(locationid, locationprice, locationkey)
local src = source
local xPlayer = ESX.GetPlayerFromId(src)
local identifier = ESX.GetPlayerFromId(src).identifier
MySQL.Async.fetchAll('SELECT * FROM owned_mlos WHERE location = @location',
{
['@identifier'] = owner,
},
function(result2)
if xPlayer.getMoney() >= locationprice then
MySQL.Async.fetchAll("UPDATE owned_mlos SET identifier = @identifier WHERE location = @location",{['@identifier'] = identifier, ['@location'] = locationid}, function(result)
end)
xPlayer.removeMoney(locationprice)
print(locationkey)
TriggerClientEvent('ox_lib:notify', src, {type = 'success', description = "Purchased "..locationid.. " for $"..locationprice})
xPlayer.addInventoryItem(locationkey, 1)
else
TriggerClientEvent('ox_lib:notify', src, {type = 'error', description = "Not enough money"})
end
end)
end)
RegisterNetEvent('koe_mlobuy:getNewKey')
AddEventHandler('koe_mlobuy:getNewKey', function(locationkey)
local src = source
local xPlayer = ESX.GetPlayerFromId(src)
local identifier = ESX.GetPlayerFromId(src).identifier
if exports.ox_inventory:CanCarryItem(src, locationkey, 1) then
xPlayer.addInventoryItem(locationkey, 1)
else
TriggerClientEvent('ox_lib:notify', source, {type = 'error', description = 'Not enough space', duration = 8000, position = 'top'})
end
end)