Repository navigation
Expand file tree
/
Copy pathclient.lua
More file actions
89 lines (74 loc) · 3.04 KB
/
Copy pathclient.lua
File metadata and controls
89 lines (74 loc) · 3.04 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
79
80
81
82
83
84
85
86
87
88
89
local ESX = nil
local isMounted = false
local mountedPlayer = nil
local mountCooldown = false
Citizen.CreateThread(function()
while ESX == nil do
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
Citizen.Wait(0)
end
end)
function loadAnimDict(dict)
while not HasAnimDictLoaded(dict) do
RequestAnimDict(dict)
Citizen.Wait(5)
end
end
RegisterNetEvent('BackMountSystem:MountPlayer')
AddEventHandler('BackMountSystem:MountPlayer', function(target)
if not mountCooldown then
local playerPed = PlayerPedId()
local targetPed = GetPlayerPed(GetPlayerFromServerId(target))
if DoesEntityExist(targetPed) and not IsPedInAnyVehicle(playerPed) and not IsPedInAnyVehicle(targetPed) then
local playerCoords = GetEntityCoords(playerPed)
local targetCoords = GetEntityCoords(targetPed)
if #(playerCoords - targetCoords) < Config.MountDistance then
loadAnimDict(Config.MountAnimDict)
loadAnimDict(Config.MountedAnimDict)
AttachEntityToEntity(playerPed, targetPed, 0, 0.0, -0.7, 0.4, 0.0, 0.0, 0.0, false, false, false, false, 2, true)
TaskPlayAnim(playerPed, Config.MountAnimDict, Config.MountAnimName, 8.0, -8.0, -1, 1, 0, false, false, false)
TaskPlayAnim(targetPed, Config.MountedAnimDict, Config.MountedAnimName, 8.0, -8.0, -1, 1, 0, false, false, false)
isMounted = true
mountedPlayer = target
mountCooldown = true
Citizen.SetTimeout(Config.MountCooldown, function()
mountCooldown = false
end)
else
ESX.ShowNotification('You are too far away from the player.')
end
else
ESX.ShowNotification('You cannot mount this player.')
end
else
ESX.ShowNotification('You are on cooldown. Please wait.')
end
end)
RegisterNetEvent('BackMountSystem:DismountPlayer')
AddEventHandler('BackMountSystem:DismountPlayer', function()
if isMounted then
local playerPed = PlayerPedId()
DetachEntity(playerPed, true, false)
ClearPedTasks(playerPed)
isMounted = false
mountedPlayer = nil
end
end)
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
if isMounted then
local playerPed = PlayerPedId()
local targetPed = GetPlayerPed(GetPlayerFromServerId(mountedPlayer))
if DoesEntityExist(targetPed) then
local playerCoords = GetEntityCoords(playerPed)
local targetCoords = GetEntityCoords(targetPed)
if #(playerCoords - targetCoords) > Config.MountDistance then
TriggerEvent('BackMountSystem:DismountPlayer')
end
else
TriggerEvent('BackMountSystem:DismountPlayer')
end
end
end
end)