Repository navigation
Expand file tree
/
Copy pathserver.lua
More file actions
38 lines (33 loc) · 1.47 KB
/
Copy pathserver.lua
File metadata and controls
38 lines (33 loc) · 1.47 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
local ESX = nil
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
ESX.RegisterServerCallback('AnimalMapSystem:getAnimals', function(source, cb)
local xPlayer = ESX.GetPlayerFromId(source)
local identifier = xPlayer.identifier
MySQL.Async.fetchAll('SELECT * FROM animals WHERE owner_id = @owner_id', {
['@owner_id'] = identifier
}, function(result)
cb(result)
end)
end)
RegisterServerEvent('AnimalMapSystem:captureAnimal')
AddEventHandler('AnimalMapSystem:captureAnimal', function(animalPed)
local xPlayer = ESX.GetPlayerFromId(source)
local identifier = xPlayer.identifier
local animalCoords = GetEntityCoords(animalPed)
for _, animal in ipairs(Config.Animals) do
if GetEntityModel(animalPed) == GetHashKey(animal.model) then
MySQL.Async.execute('INSERT INTO animals (owner_id, animal_name, model, x, y, z) VALUES (@owner_id, @animal_name, @model, @x, @y, @z)', {
['@owner_id'] = identifier,
['@animal_name'] = animal.name,
['@model'] = animal.model,
['@x'] = animalCoords.x,
['@y'] = animalCoords.y,
['@z'] = animalCoords.z
}, function(rowsChanged)
xPlayer.addMoney(animal.captureReward)
TriggerClientEvent('esx:showNotification', source, 'You captured a ' .. animal.name .. ' and earned $' .. animal.captureReward)
end)
break
end
end
end)