-
Notifications
You must be signed in to change notification settings - Fork 1
/
xdopehunting_cl.lua
250 lines (193 loc) · 7.12 KB
/
xdopehunting_cl.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
local Keys = {
["ESC"] = 322, ["F1"] = 288, ["F2"] = 289, ["F3"] = 170, ["F5"] = 166, ["F6"] = 167, ["F7"] = 168, ["F8"] = 169, ["F9"] = 56, ["F10"] = 57,
["~"] = 243, ["1"] = 157, ["2"] = 158, ["3"] = 160, ["4"] = 164, ["5"] = 165, ["6"] = 159, ["7"] = 161, ["8"] = 162, ["9"] = 163, ["-"] = 84, ["="] = 83, ["BACKSPACE"] = 177,
["TAB"] = 37, ["Q"] = 44, ["W"] = 32, ["E"] = 38, ["R"] = 45, ["T"] = 245, ["Y"] = 246, ["U"] = 303, ["P"] = 199, ["["] = 39, ["]"] = 40, ["ENTER"] = 18,
["CAPS"] = 137, ["A"] = 34, ["S"] = 8, ["D"] = 9, ["F"] = 23, ["G"] = 47, ["H"] = 74, ["K"] = 311, ["L"] = 182,
["LEFTSHIFT"] = 21, ["Z"] = 20, ["X"] = 73, ["C"] = 26, ["V"] = 0, ["B"] = 29, ["N"] = 249, ["M"] = 244, [","] = 82, ["."] = 81,
["LEFTCTRL"] = 36, ["LEFTALT"] = 19, ["SPACE"] = 22, ["RIGHTCTRL"] = 70,
["HOME"] = 213, ["PAGEUP"] = 10, ["PAGEDOWN"] = 11, ["DELETE"] = 178,
["LEFT"] = 174, ["RIGHT"] = 175, ["TOP"] = 27, ["DOWN"] = 173,
["NENTER"] = 201, ["N4"] = 108, ["N5"] = 60, ["N6"] = 107, ["N+"] = 96, ["N-"] = 97, ["N7"] = 117, ["N8"] = 61, ["N9"] = 118
}
XD = nil
Citizen.CreateThread(function()
while true do
Citizen.Wait(1)
if XD == nil then
TriggerEvent("XD:GetObject", function(obj) XD = obj end)
Citizen.Wait(200)
ScriptLoaded()
end
end
end)
RegisterNetEvent('XD:Client:OnPlayerLoaded')
AddEventHandler('XD:Client:OnPlayerLoaded', function()
LoadMarkers()
end)
function DrawText3D2(x, y, z, text)
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 ScriptLoaded()
Citizen.Wait(1000)
LoadMarkers()
end
local AnimalPositions = {
{ x = -1505.2, y = 4887.39, z = 78.38 },
{ x = -1164.68, y = 4806.76, z = 223.11 },
{ x = -1410.63, y = 4730.94, z = 44.0369 },
{ x = -1377.29, y = 4864.31, z = 134.162 },
{ x = -1697.63, y = 4652.71, z = 22.2442 },
{ x = -1259.99, y = 5002.75, z = 151.36 },
{ x = -960.91, y = 5001.16, z = 183.0 },
}
local AnimalsInSession = {}
local Positions = {
['StartHunting'] = { ['hint'] = '[E] Start Hunting', ['x'] = -769.23773193359, ['y'] = 5595.6215820313, ['z'] = 33.48571395874 },
['Sell'] = { ['hint'] = '[E] Sell', ['x'] = 969.16375732422, ['y'] = -2107.9033203125, ['z'] = 31.475671768188 },
['SpawnATV'] = { ['x'] = -769.63067626953, ['y'] = 5592.7573242188, ['z'] = 33.48571395874 }
}
local OnGoingHuntSession = false
local HuntCar = nil
Citizen.CreateThread(function()
local StartBlip = AddBlipForCoord(-769.23773193359, 5595.621582031, 33.485713)
SetBlipSprite(StartBlip, 442)
SetBlipColour(StartBlip, 75)
SetBlipScale(StartBlip, 0.9)
SetBlipAsShortRange(StartBlip, true)
BeginTextCommandSetBlipName("STRING")
AddTextComponentString('Hunting Spot')
EndTextCommandSetBlipName(StartBlip)
end)
function LoadMarkers()
LoadModel('blazer')
LoadModel('a_c_deer')
LoadAnimDict('amb@medic@standing@kneel@base')
LoadAnimDict('anim@gangops@facility@servers@bodysearch@')
Citizen.CreateThread(function()
while true do
local sleep = 500
local plyCoords = GetEntityCoords(PlayerPedId())
for index, value in pairs(Positions) do
if value.hint ~= nil then
if OnGoingHuntSession and index == 'StartHunting' then
value.hint = '[E] Stop Hunting'
elseif not OnGoingHuntSession and index == 'StartHunting' then
value.hint = '[E] Start Hunting'
end
local distance = GetDistanceBetweenCoords(plyCoords, value.x, value.y, value.z, true)
if distance < 5.0 then
sleep = 5
DrawM(value.hint, 27, value.x, value.y, value.z - 0.945, 255, 255, 255, 1.5, 15)
if distance < 1.0 then
if IsControlJustReleased(0, Keys['E']) then
if index == 'StartHunting' then
StartHuntingSession()
else
SellItems()
end
end
end
end
end
end
Citizen.Wait(sleep)
end
end)
end
function StartHuntingSession()
if OnGoingHuntSession then
OnGoingHuntSession = false
for index, value in pairs(AnimalsInSession) do
if DoesEntityExist(value.id) then
DeleteEntity(value.id)
end
end
else
OnGoingHuntSession = true
--Animals
Citizen.CreateThread(function()
for index, value in pairs(AnimalPositions) do
local Animal = CreatePed(5, GetHashKey('a_c_deer'), value.x, value.y, value.z, 0.0, true, false)
TaskWanderStandard(Animal, true, true)
SetEntityAsMissionEntity(Animal, true, true)
--Blips
local AnimalBlip = AddBlipForEntity(Animal)
SetBlipSprite(AnimalBlip, 153)
SetBlipColour(AnimalBlip, 1)
BeginTextCommandSetBlipName("STRING")
AddTextComponentString('Deer - Animal')
EndTextCommandSetBlipName(AnimalBlip)
table.insert(AnimalsInSession, {id = Animal, x = value.x, y = value.y, z = value.z, Blipid = AnimalBlip})
end
while OnGoingHuntSession do
local sleep = 500
for index, value in ipairs(AnimalsInSession) do
if DoesEntityExist(value.id) then
local AnimalCoords = GetEntityCoords(value.id)
local PlyCoords = GetEntityCoords(PlayerPedId())
local AnimalHealth = GetEntityHealth(value.id)
local PlyToAnimal = GetDistanceBetweenCoords(PlyCoords, AnimalCoords, true)
if AnimalHealth <= 0 then
SetBlipColour(value.Blipid, 3)
if PlyToAnimal < 2.0 then
sleep = 5
DrawText3D2(AnimalCoords.x, AnimalCoords.y, AnimalCoords.z + 1, '[E] Slaughter Animal')
if IsControlJustReleased(0, Keys['E']) then
if GetSelectedPedWeapon(PlayerPedId()) == GetHashKey('WEAPON_KNIFE') then
if DoesEntityExist(value.id) then
table.remove(AnimalsInSession, index)
SlaughterAnimal(value.id)
end
else
XD.Functions.Notify('You need to use the knife!', "error")
end
end
end
end
end
end
Citizen.Wait(sleep)
end
end)
end
end
function SlaughterAnimal(AnimalId)
TaskPlayAnim(PlayerPedId(), "amb@medic@standing@kneel@base" ,"base" ,8.0, -8.0, -1, 1, 0, false, false, false )
TaskPlayAnim(PlayerPedId(), "anim@gangops@facility@servers@bodysearch@" ,"player_search" ,8.0, -8.0, -1, 48, 0, false, false, false )
Citizen.Wait(5000)
ClearPedTasksImmediately(PlayerPedId())
local AnimalWeight = math.random(10, 160) / 10
print('You slaughtered the animal and recieved' ..AnimalWeight.. 'kg of meat')
TriggerServerEvent('xd:reward', AnimalWeight)
DeleteEntity(AnimalId)
end
function SellItems()
TriggerServerEvent('xd:sell')
end
function LoadAnimDict(dict)
while (not HasAnimDictLoaded(dict)) do
RequestAnimDict(dict)
Citizen.Wait(10)
end
end
function LoadModel(model)
while not HasModelLoaded(model) do
RequestModel(model)
Citizen.Wait(10)
end
end
function DrawM(hint, type, x, y, z)
DrawText3D2(x, y, z + 1.0, hint)
DrawMarker(type, x, y, z, 0.0, 0.0, 0.0, 0, 0.0, 0.0, 1.5, 1.5, 1.5, 255, 255, 255, 100, false, true, 2, false, false, false, false)
end