forked from Blauerdrache87/ikipm_bus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.lua
156 lines (133 loc) · 4.31 KB
/
client.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
ESX = nil
showtext = true
point = ""
onRoute = false
destinationSelected = ""
local options ={}
-- Load ESX
Citizen.CreateThread(function()
while ESX == nil do
TriggerEvent(Config.ESXShared, function(obj) ESX = obj end)
Citizen.Wait(100)
end
end)
-- Add stations to options variable
Citizen.CreateThread(function()
for index, value in pairs(Config.Locations) do
table.insert(options, {label = value.Name, value = index})
end
end)
-- Create Schedules
Citizen.CreateThread(function()
while true do
Wait(10)
if showtext then
for index, value in pairs(Config.Locations) do
if #(value.Schedule - GetEntityCoords(PlayerPedId())) <= 3 then
DrawText3D(value.Schedule.x, value.Schedule.y, value.Schedule.z, _U("schedule"))
if IsControlJustReleased(0, 38) then
point = value
showtext = false
openStationMenu()
end
end
end
end
end
end)
-- Create blips
Citizen.CreateThread(function()
for index, value in pairs(Config.Locations) do
local blip = AddBlipForCoord(value.Schedule)
SetBlipSprite (blip, Config.BlipSprite)
SetBlipDisplay(blip, 2)
SetBlipScale (blip, Config.BlipScale)
SetBlipColour (blip, Config.BlipColour)
SetBlipAsShortRange(blip, true)
BeginTextCommandSetBlipName("STRING")
AddTextComponentSubstringPlayerName(_U("blip"))
EndTextCommandSetBlipName(blip)
end
end)
---------------
-- Functions --
---------------
function openStationMenu()
ESX.UI.Menu.Open( "default", GetCurrentResourceName(), "bus", {
title = _U("menu_title"),
align = "bottom-right",
elements = options
}, function(data, menu) -- Options and functions
menu.close()
destinationSelected = data.current.value
createRoute(point.Departure, point.DepHead, Config.Locations[destinationSelected].Arrival, Config.Locations[destinationSelected].Price)
showtext = true
end, function(data, menu) -- Close the menu
menu.close()
showtext = true
end)
end
function createRoute(departure, point, destination, money)
onRoute = true
player = PlayerPedId()
ESX.Game.SpawnVehicle(Config.Vehicle, departure, point, function(vehicle)
TaskWarpPedIntoVehicle(player, vehicle, 0)
SetVehicleDoorsLockedForAllPlayers(vehicle, true)
-- Create NPC
npc = CreatePed(vehicle, -1, Config.NPC)
SetEntityInvincible(npc, true)
SetDriverAbility(npc, 1.0)
SetDriverAggressiveness(npc, 0.0)
-- Drive to coords
TaskVehicleDriveToCoordLongrange(npc, vehicle, destination.x, destination.y, destination.z, Config.Speed, 786603, 10.0)
Citizen.CreateThread(function()
while onRoute do
Wait(5000)
if #(destination - GetEntityCoords(player)) <= 15 and onRoute then
FinRoute(vehicle, npc, money)
ESX.ShowNotification(_U("success", money))
elseif not IsPedInVehicle(player, vehicle, true) and onRoute then
FinRoute(vehicle, npc, money)
ESX.ShowNotification(_U("error", money))
end
end
end)
end)
end
function DrawText3D(x, y, z, text)
coords = vector3(x, y, z)
SetTextScale(0.35, 0.35)
SetTextFont(4)
SetTextProportional(1)
SetTextColour(255, 255, 255, 215)
SetTextEntry("STRING")
SetTextCentre(true)
AddTextComponentString(text)
SetDrawOrigin(x,y,z, 0)
DrawText(0.0, 0.0)
local factor = (string.len(text)) / 370
DrawRect(0.0, 0.0+0.0125, 0.017+ factor, 0.03, 0, 0, 0, 75)
ClearDrawOrigin()
end
function CreatePed(vehicle, pos, model)
local model = GetHashKey(model)
if DoesEntityExist(vehicle) then
if IsModelValid(model) then
RequestModel(model)
while not HasModelLoaded(model) do
Wait(100)
end
local ped = CreatePedInsideVehicle(vehicle, 26, model, pos, true, false)
SetBlockingOfNonTemporaryEvents(ped, true)
SetEntityAsMissionEntity(ped, true, true)
SetModelAsNoLongerNeeded(model)
return ped
end
end
end
function FinRoute(vehicle, npc, money)
onRoute = false
DeletePed(npc)
ESX.Game.DeleteVehicle(vehicle)
TriggerServerEvent('ikipm_bus:getMoney', money)
end