/
client.lua
964 lines (821 loc) · 26.5 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
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
cam = nil
hided = false
spawnedCamera = nil
choosePed = {}
pedSelected = nil
sex = nil
zoom = 4.0
offset = 0.2
DeleteeEntity = true
local InterP = true
local adding = true
local showroomHorse_entity
local showroomHorse_model
local MyHorse_entity
local IdMyHorse
cameraUsing = {
{
name = "Horse",
x = 0.2,
y = 0.0,
z = 1.8
},
{
name = "Olhos",
x = 0.0,
y = -0.4,
z = 0.65
}
}
local saddlecloths = {}
local acshorn = {}
local bags = {}
local horsetails = {}
local manes = {}
local saddles = {}
local stirrups = {}
local acsluggage = {}
Citizen.CreateThread(
function()
while adding do
Citizen.Wait(0)
for i, v in ipairs(HorseComp) do
if v.category == "Saddlecloths" then
table.insert(saddlecloths, v.Hash)
elseif v.category == "AcsHorn" then
table.insert(acshorn, v.Hash)
elseif v.category == "Bags" then
table.insert(bags, v.Hash)
elseif v.category == "HorseTails" then
table.insert(horsetails, v.Hash)
elseif v.category == "Manes" then
table.insert(manes, v.Hash)
elseif v.category == "Saddles" then
table.insert(saddles, v.Hash)
elseif v.category == "Stirrups" then
table.insert(stirrups, v.Hash)
elseif v.category == "AcsLuggage" then
table.insert(acsluggage, v.Hash)
end
end
adding = false
end
end
)
RegisterCommand(
"estabulo",
function()
OpenStable()
end
)
function OpenStable()
inCustomization = true
horsesp = true
local playerHorse = MyHorse_entity
SetEntityHeading(playerHorse, 334)
DeleteeEntity = true
SetNuiFocus(true, true)
InterP = true
local hashm = GetEntityModel(playerHorse)
if hashm ~= nil and IsPedOnMount(PlayerPedId()) then
createCamera(PlayerPedId())
else
createCamera(PlayerPedId())
end
-- SetEntityVisible(PlayerPedId(), false)
if not alreadySentShopData then
SendNUIMessage(
{
action = "show",
shopData = getShopData()
}
)
else
SendNUIMessage(
{
action = "show"
}
)
end
TriggerServerEvent("VP:STABLE:AskForMyHorses")
end
local promptGroup
local varStringCasa = CreateVarString(10, "LITERAL_STRING", "Estabulo")
local blip
local prompts = {}
local SpawnPoint = {}
local StablePoint = {}
local HeadingPoint
local CamPos = {}
Citizen.CreateThread(
function()
while true do
Wait(1)
local coords = GetEntityCoords(PlayerPedId())
for _, prompt in pairs(prompts) do
if PromptIsJustPressed(prompt) then
for k, v in pairs(Config.Stables) do
if GetDistanceBetweenCoords(coords, v.Pos.x, v.Pos.y, v.Pos.z, true) < 7 then
HeadingPoint = v.Heading
StablePoint = {v.Pos.x, v.Pos.y, v.Pos.z}
CamPos = {v.SpawnPoint.CamPos.x, v.SpawnPoint.CamPos.y}
SpawnPoint = {x = v.SpawnPoint.Pos.x, y = v.SpawnPoint.Pos.y, z = v.SpawnPoint.Pos.z, h = v.SpawnPoint.Heading}
Wait(300)
end
end
OpenStable()
end
end
end
end
)
Citizen.CreateThread(
function()
for _, v in pairs(Config.Stables) do
-- blip = N_0x554d9d53f696d002(1664425300, v.Pos.x, v.Pos.y, v.Pos.z)
SetBlipSprite(blip, -145868367, 1)
Citizen.InvokeNative(0x9CB1A1623062F402, blip, "Stable")
local prompt = PromptRegisterBegin()
PromptSetActiveGroupThisFrame(promptGroup, varStringCasa)
PromptSetControlAction(prompt, 0xE8342FF2)
PromptSetText(prompt, CreateVarString(10, "LITERAL_STRING", "Open Stable"))
PromptSetStandardMode(prompt, true)
PromptSetEnabled(prompt, 1)
PromptSetVisible(prompt, 1)
PromptSetHoldMode(prompt, 1)
PromptSetPosition(prompt, v.Pos.x, v.Pos.y, v.Pos.z)
N_0x0c718001b77ca468(prompt, 3.0)
PromptSetGroup(prompt, promptGroup)
PromptRegisterEnd(prompt)
table.insert(prompts, prompt)
end
end
)
AddEventHandler(
"onResourceStop",
function(resourceName)
if resourceName == GetCurrentResourceName() then
for _, prompt in pairs(prompts) do
PromptDelete(prompt)
RemoveBlip(blip)
end
end
end
)
-- function deletePrompt()
-- if prompt ~= nil then
-- PromptSetVisible(prompt, false)
-- PromptSetEnabled(prompt, false)
-- PromptDelete(prompt)
-- prompt = nil
-- promptGroup = nil
-- end
-- end
function rotation(dir)
local playerHorse = MyHorse_entity
local pedRot = GetEntityHeading(playerHorse) + dir
SetEntityHeading(playerHorse, pedRot % 360)
end
RegisterNUICallback(
"rotate",
function(data, cb)
if (data["key"] == "left") then
rotation(20)
else
rotation(-20)
end
cb("ok")
end
)
-- AddEventHandler(
-- 'onResourceStop',
-- function(resourceName)
-- if resourceName == GetCurrentResourceName() then
-- for _, prompt in pairs(prompts) do
-- PromptDelete(prompt)
-- end
-- end
-- end
-- )
AddEventHandler(
"onResourceStop",
function(resourceName)
if (GetCurrentResourceName() ~= resourceName) then
return
end
SetNuiFocus(false, false)
SendNUIMessage(
{
action = "hide"
}
)
end
)
function createCam(creatorType)
for k, v in pairs(cams) do
if cams[k].type == creatorType then
cam = CreateCamWithParams("DEFAULT_SCRIPTED_CAMERA", cams[k].x, cams[k].y, cams[k].z, cams[k].rx, cams[k].ry, cams[k].rz, cams[k].fov, false, 0) -- CAMERA COORDS
SetCamActive(cam, true)
RenderScriptCams(true, false, 3000, true, false)
createPeds()
end
end
end
RegisterNUICallback(
"Saddles",
function(data)
zoom = 4.0
offset = 0.2
if tonumber(data.id) == 0 then
num = 0
SaddlesUsing = num
local playerHorse = MyHorse_entity
Citizen.InvokeNative(0xD710A5007C2AC539, playerHorse, 0xBAA7E618, 0) -- HAT REMOVE
Citizen.InvokeNative(0xCC8CA3E88256E58F, playerHorse, 0, 1, 1, 1, 0) -- Actually remove the component
else
local num = tonumber(data.id)
hash = ("0x" .. saddles[num])
setcloth(hash)
SaddlesUsing = ("0x" .. saddles[num])
end
end
)
RegisterNUICallback(
"Saddlecloths",
function(data)
zoom = 4.0
offset = 0.2
if tonumber(data.id) == 0 then
num = 0
SaddleclothsUsing = num
local playerHorse = MyHorse_entity
Citizen.InvokeNative(0xD710A5007C2AC539, playerHorse, 0x17CEB41A, 0) -- HAT REMOVE
Citizen.InvokeNative(0xCC8CA3E88256E58F, playerHorse, 0, 1, 1, 1, 0) -- Actually remove the component
else
local num = tonumber(data.id)
hash = ("0x" .. saddlecloths[num])
setcloth(hash)
SaddleclothsUsing = ("0x" .. saddlecloths[num])
end
end
)
RegisterNUICallback(
"Stirrups",
function(data)
zoom = 4.0
offset = 0.2
if tonumber(data.id) == 0 then
num = 0
StirrupsUsing = num
local playerHorse = MyHorse_entity
Citizen.InvokeNative(0xD710A5007C2AC539, playerHorse, 0xDA6DADCA, 0) -- HAT REMOVE
Citizen.InvokeNative(0xCC8CA3E88256E58F, playerHorse, 0, 1, 1, 1, 0) -- Actually remove the component
else
local num = tonumber(data.id)
hash = ("0x" .. stirrups[num])
setcloth(hash)
StirrupsUsing = ("0x" .. stirrups[num])
end
end
)
RegisterNUICallback(
"Bags",
function(data)
zoom = 4.0
offset = 0.2
if tonumber(data.id) == 0 then
num = 0
BagsUsing = num
local playerHorse = MyHorse_entity
Citizen.InvokeNative(0xD710A5007C2AC539, playerHorse, 0x80451C25, 0) -- HAT REMOVE
Citizen.InvokeNative(0xCC8CA3E88256E58F, playerHorse, 0, 1, 1, 1, 0) -- Actually remove the component
else
local num = tonumber(data.id)
hash = ("0x" .. bags[num])
setcloth(hash)
BagsUsing = ("0x" .. bags[num])
end
end
)
RegisterNUICallback(
"Manes",
function(data)
zoom = 4.0
offset = 0.2
if tonumber(data.id) == 0 then
num = 0
ManesUsing = num
local playerHorse = MyHorse_entity
Citizen.InvokeNative(0xD710A5007C2AC539, playerHorse, 0xAA0217AB, 0) -- HAT REMOVE
Citizen.InvokeNative(0xCC8CA3E88256E58F, playerHorse, 0, 1, 1, 1, 0) -- Actually remove the component
else
local num = tonumber(data.id)
hash = ("0x" .. manes[num])
setcloth(hash)
ManesUsing = ("0x" .. manes[num])
end
end
)
RegisterNUICallback(
"HorseTails",
function(data)
zoom = 4.0
offset = 0.2
if tonumber(data.id) == 0 then
num = 0
HorseTailsUsing = num
local playerHorse = MyHorse_entity
Citizen.InvokeNative(0xD710A5007C2AC539, playerHorse, 0x17CEB41A, 0) -- HAT REMOVE
Citizen.InvokeNative(0xCC8CA3E88256E58F, playerHorse, 0, 1, 1, 1, 0) -- Actually remove the component
else
local num = tonumber(data.id)
hash = ("0x" .. horsetails[num])
setcloth(hash)
HorseTailsUsing = ("0x" .. horsetails[num])
end
end
)
RegisterNUICallback(
"AcsHorn",
function(data)
zoom = 4.0
offset = 0.2
if tonumber(data.id) == 0 then
num = 0
AcsHornUsing = num
local playerHorse = MyHorse_entity
Citizen.InvokeNative(0xD710A5007C2AC539, playerHorse, 0x5447332, 0) -- HAT REMOVE
Citizen.InvokeNative(0xCC8CA3E88256E58F, playerHorse, 0, 1, 1, 1, 0) -- Actually remove the component
else
local num = tonumber(data.id)
hash = ("0x" .. acshorn[num])
setcloth(hash)
AcsHornUsing = ("0x" .. acshorn[num])
end
end
)
RegisterNUICallback(
"AcsLuggage",
function(data)
zoom = 4.0
offset = 0.2
if tonumber(data.id) == 0 then
num = 0
AcsLuggageUsing = num
local playerHorse = MyHorse_entity
Citizen.InvokeNative(0xD710A5007C2AC539, playerHorse, 0xEFB31921, 0) -- HAT REMOVE
Citizen.InvokeNative(0xCC8CA3E88256E58F, playerHorse, 0, 1, 1, 1, 0) -- Actually remove the component
else
local num = tonumber(data.id)
hash = ("0x" .. acsluggage[num])
setcloth(hash)
AcsLuggageUsing = ("0x" .. acsluggage[num])
end
end
)
myHorses = {}
function setcloth(hash)
local model2 = GetHashKey(tonumber(hash))
if not HasModelLoaded(model2) then
Citizen.InvokeNative(0xFA28FE3A6246FC30, model2)
end
Citizen.InvokeNative(0xD3A7B003ED343FD9, MyHorse_entity, tonumber(hash), true, true, true)
end
RegisterNUICallback(
"selectHorse",
function(data)
TriggerServerEvent("VP:STABLE:SelectHorseWithId", tonumber(data.horseID))
end
)
RegisterNUICallback(
"sellHorse",
function(data)
DeleteEntity(showroomHorse_entity)
TriggerServerEvent("VP:STABLE:SellHorseWithId", tonumber(data.horseID))
TriggerServerEvent("VP:STABLE:AskForMyHorses")
alreadySentShopData = false
Wait(300)
SendNUIMessage(
{
action = "show",
shopData = getShopData()
}
)
TriggerServerEvent("VP:STABLE:AskForMyHorses")
end
)
RegisterNetEvent("VP:STABLE:ReceiveHorsesData")
AddEventHandler(
"VP:STABLE:ReceiveHorsesData",
function(dataHorses)
SendNUIMessage(
{
myHorsesData = dataHorses
}
)
end
)
SaddlesUsing = nil
SaddleclothsUsing = nil
StirrupsUsing = nil
BagsUsing = nil
ManesUsing = nil
HorseTailsUsing = nil
AcsHornUsing = nil
AcsLuggageUsing = nil
--- /// ARRASTAR CAVALO
local alreadySentShopData = false
function getShopData()
alreadySentShopData = true
local ret = Config.Horses
return ret
end
RegisterNUICallback(
"loadHorse",
function(data)
local horseModel = data.horseModel
if showroomHorse_model == horseModel then
return
end
if MyHorse_entity ~= nil then
DeleteEntity(MyHorse_entity)
MyHorse_entity = nil
end
local modelHash = GetHashKey(horseModel)
if IsModelValid(modelHash) then
if not HasModelLoaded(modelHash) then
RequestModel(modelHash)
while not HasModelLoaded(modelHash) do
Citizen.Wait(10)
end
end
end
if showroomHorse_entity ~= nil then
DeleteEntity(showroomHorse_entity)
showroomHorse_entity = nil
end
showroomHorse_model = horseModel
showroomHorse_entity = CreatePed(modelHash, SpawnPoint.x, SpawnPoint.y, SpawnPoint.z - 0.98, SpawnPoint.h, false, 0)
Citizen.InvokeNative(0x283978A15512B2FE, showroomHorse_entity, true)
Citizen.InvokeNative(0x58A850EAEE20FAA3, showroomHorse_entity)
NetworkSetEntityInvisibleToNetwork(showroomHorse_entity, true)
SetVehicleHasBeenOwnedByPlayer(showroomHorse_entity, true)
-- SetModelAsNoLongerNeeded(modelHash)
interpCamera("Horse", showroomHorse_entity)
end
)
RegisterNUICallback(
"loadMyHorse",
function(data)
local horseModel = data.horseModel
IdMyHorse = data.IdHorse
if showroomHorse_model == horseModel then
return
end
if showroomHorse_entity ~= nil then
DeleteEntity(showroomHorse_entity)
showroomHorse_entity = nil
end
if MyHorse_entity ~= nil then
DeleteEntity(MyHorse_entity)
MyHorse_entity = nil
end
showroomHorse_model = horseModel
local modelHash = GetHashKey(showroomHorse_model)
if not HasModelLoaded(modelHash) then
RequestModel(modelHash)
while not HasModelLoaded(modelHash) do
Citizen.Wait(10)
end
end
MyHorse_entity = CreatePed(modelHash, SpawnPoint.x, SpawnPoint.y, SpawnPoint.z - 0.98, SpawnPoint.h, false, 0)
Citizen.InvokeNative(0x283978A15512B2FE, MyHorse_entity, true)
Citizen.InvokeNative(0x58A850EAEE20FAA3, MyHorse_entity)
NetworkSetEntityInvisibleToNetwork(MyHorse_entity, true)
SetVehicleHasBeenOwnedByPlayer(MyHorse_entity, true)
local componentsHorse = json.decode(data.HorseComp)
if componentsHorse ~= '[]' then
for _, Key in pairs(componentsHorse) do
local model2 = GetHashKey(tonumber(Key))
if not HasModelLoaded(model2) then
Citizen.InvokeNative(0xFA28FE3A6246FC30, model2)
end
Citizen.InvokeNative(0xD3A7B003ED343FD9, MyHorse_entity, tonumber(Key), true, true, true)
end
end
-- SetModelAsNoLongerNeeded(modelHash)
interpCamera("Horse", MyHorse_entity)
end
)
RegisterNetEvent('VP:STABLE:UpdadeHorseComponents')
AddEventHandler('VP:STABLE:UpdadeHorseComponents', function(horseEntity, components)
for _, value in pairs(components) do
NativeSetPedComponentEnabled(horseEntity, value)
end
end)
RegisterNUICallback(
"BuyHorse",
function(data)
SetHorseName(data)
end
)
function SetHorseName(data)
SetNuiFocus(false, false)
SendNUIMessage(
{
action = "hide"
}
)
Wait(200)
local HorseName = ""
Citizen.CreateThread(function()
AddTextEntry('FMMC_MPM_NA', "Name your horse:")
DisplayOnscreenKeyboard(1, "FMMC_MPM_NA", "", "", "", "", "", 30)
while (UpdateOnscreenKeyboard() == 0) do
DisableAllControlActions(0);
Citizen.Wait(0);
end
if (GetOnscreenKeyboardResult()) then
HorseName = GetOnscreenKeyboardResult()
TriggerServerEvent('VP:STABLE:BuyHorse', data, HorseName)
SetNuiFocus(true, true)
SendNUIMessage(
{
action = "show",
shopData = getShopData()
}
)
Wait(1000)
TriggerServerEvent("VP:STABLE:AskForMyHorses")
end
end)
end
RegisterNUICallback(
"CloseStable",
function()
SetNuiFocus(false, false)
SendNUIMessage(
{
action = "hide"
}
)
SetEntityVisible(PlayerPedId(), true)
showroomHorse_model = nil
if showroomHorse_entity ~= nil then
DeleteEntity(showroomHorse_entity)
end
if MyHorse_entity ~= nil then
DeleteEntity(MyHorse_entity)
end
DestroyAllCams(true)
showroomHorse_entity = nil
CloseStable()
end
)
function CloseStable()
local dados = {
-- ['saddles'] = SaddlesUsing,
-- ['saddlescloths'] = SaddleclothsUsing,
-- ['stirrups'] = StirrupsUsing,
-- ['bags'] = BagsUsing,
-- ['manes'] = ManesUsing,
-- ['horsetails'] = HorseTailsUsing,
-- ['acshorn'] = AcsHornUsing,
-- ['ascluggage'] = AcsLuggageUsing
SaddlesUsing,
SaddleclothsUsing,
StirrupsUsing,
BagsUsing,
ManesUsing,
HorseTailsUsing,
AcsHornUsing,
AcsLuggageUsing
}
local DadosEncoded = json.encode(dados)
if DadosEncoded ~= "[]" then
TriggerServerEvent("VP:STABLE:UpdateHorseComponents", dados, IdMyHorse, MyHorse_entity )
end
end
Citizen.CreateThread(
function()
while true do
Citizen.Wait(100)
if MyHorse_entity ~= nil then
SendNUIMessage(
{
EnableCustom = "true"
}
)
else
SendNUIMessage(
{
EnableCustom = "false"
}
)
end
end
end
)
local SpawnplayerHorse = 0
local horseModel
local horseName
local horseComponents = {}
local initializing = false
function SetHorseInfo(horse_model, horse_name, horse_components)
horseModel = horse_model
horseName = horse_name
horseComponents = horse_components
end
function NativeSetPedComponentEnabled(ped, component)
Citizen.InvokeNative(0xD3A7B003ED343FD9, ped, component, true, true, true)
end
RegisterNetEvent("VP:HORSE:SetHorseInfo")
AddEventHandler("VP:HORSE:SetHorseInfo", SetHorseInfo)
function InitiateHorse(atCoords)
if initializing then
return
end
initializing = true
if horseModel == nil and horseName == nil then
TriggerServerEvent("VP:HORSE:RequestMyHorseInfo")
local timeoutatgametimer = GetGameTimer() + (3 * 1000)
while horseModel == nil and timeoutatgametimer > GetGameTimer() do
Citizen.Wait(0)
end
if horseModel == nil and horseName == nil then
horseModel = "A_C_Horse_MP_Mangy_Backup"
horseName = "Pangaré"
horseComponents = nil
end
end
if SpawnplayerHorse ~= 0 then
DeleteEntity(SpawnplayerHorse)
SpawnplayerHorse = 0
end
local ped = PlayerPedId()
local pCoords = GetEntityCoords(ped)
local modelHash = GetHashKey(horseModel)
if not HasModelLoaded(modelHash) then
RequestModel(modelHash)
while not HasModelLoaded(modelHash) do
Citizen.Wait(10)
end
end
local spawnPosition
if atCoords == nil then
local x, y, z = table.unpack(pCoords)
local bool, nodePosition = GetClosestVehicleNode(x, y, z, 1, 3.0, 0.0)
local index = 0
while index <= 25 do
local _bool, _nodePosition = GetNthClosestVehicleNode(x, y, z, index, 1, 3.0, 2.5)
if _bool == true or _bool == 1 then
bool = _bool
nodePosition = _nodePosition
index = index + 3
else
break
end
end
spawnPosition = nodePosition
else
spawnPosition = atCoords
end
if spawnPosition == nil then
initializing = false
return
end
local entity = CreatePed(modelHash, spawnPosition, GetEntityHeading(ped), true, true)
SetModelAsNoLongerNeeded(modelHash)
Citizen.InvokeNative(0x9587913B9E772D29, entity, 0)
Citizen.InvokeNative(0x4DB9D03AC4E1FA84, entity, -1, -1, 0)
Citizen.InvokeNative(0x23f74c2fda6e7c61, -1230993421, entity)
Citizen.InvokeNative(0xBCC76708E5677E1D9, entity, 0)
Citizen.InvokeNative(0xB8B6430EAD2D2437, entity, GetHashKey("PLAYER_HORSE"))
Citizen.InvokeNative(0xFD6943B6DF77E449, entity, false)
SetPedConfigFlag(entity, 324, true)
SetPedConfigFlag(entity, 211, true)
SetPedConfigFlag(entity, 208, true)
SetPedConfigFlag(entity, 209, true)
SetPedConfigFlag(entity, 400, true)
SetPedConfigFlag(entity, 297, true)
SetPedConfigFlag(entity, 136, false)
SetPedConfigFlag(entity, 312, false)
SetPedConfigFlag(entity, 113, false)
SetPedConfigFlag(entity, 301, false)
SetPedConfigFlag(entity, 277, true)
SetPedConfigFlag(entity, 319, true)
SetPedConfigFlag(entity, 6, true)
SetAnimalTuningBoolParam(entity, 25, false)
SetAnimalTuningBoolParam(entity, 24, false)
TaskAnimalUnalerted(entity, -1, false, 0, 0)
Citizen.InvokeNative(0x283978A15512B2FE, entity, true)
SpawnplayerHorse = entity
Citizen.InvokeNative(0x283978A15512B2FE, entity, true)
-- SetVehicleHasBeenOwnedByPlayer(playerHorse, true)
SetPedNameDebug(entity, horseName)
SetPedPromptName(entity, horseName)
--CreatePrompts(PromptGetGroupIdForTargetEntity(entity))
if horseComponents ~= nil and horseComponents ~= "0" then
for _, componentHash in pairs(json.decode(horseComponents)) do
NativeSetPedComponentEnabled(entity, tonumber(componentHash))
end
end
if horseModel == "A_C_Horse_MP_Mangy_Backup" then
NativeSetPedComponentEnabled(entity, 0x106961A8) --sela
NativeSetPedComponentEnabled(entity, 0x508B80B9) --blanket
end
TaskGoToEntity(entity, ped, -1, 7.2, 2.0, 0, 0)
SetPedConfigFlag(entity, 297, true) -- Enable_Horse_Leadin
initializing = false
end
function WhistleHorse()
if SpawnplayerHorse ~= 0 then
if GetScriptTaskStatus(SpawnplayerHorse, 0x4924437D, 0) ~= 0 then
local pcoords = GetEntityCoords(PlayerPedId())
local hcoords = GetEntityCoords(SpawnplayerHorse)
local caldist = Vdist(pcoords.x, pcoords.y, pcoords.z, hcoords.x, hcoords.y, hcoords.z)
if caldist >= 100 then
DeleteEntity(SpawnplayerHorse)
Wait(1000)
SpawnplayerHorse = 0
else
TaskGoToEntity(SpawnplayerHorse, PlayerPedId(), -1, 7.2, 2.0, 0, 0)
end
end
else
TriggerServerEvent('VP:STABLE:CheckSelectedHorse')
Wait(100)
InitiateHorse()
end
end
function fleeHorse(playerHorse)
TaskAnimalFlee(SpawnplayerHorse, PlayerPedId(), -1)
Wait(5000)
DeleteEntity(SpawnplayerHorse)
Wait(1000)
SpawnplayerHorse = 0
end
Citizen.CreateThread(function()
while true do
local getHorseMood = Citizen.InvokeNative(0x42688E94E96FD9B4, SpawnplayerHorse, 3, 0, Citizen.ResultAsFloat())
if getHorseMood >= 0.60 then
Citizen.InvokeNative(0x06D26A96CA1BCA75, SpawnplayerHorse, 3, PlayerPedId())
Citizen.InvokeNative(0xA1EB5D029E0191D3, SpawnplayerHorse, 3, 0.99)
end
Citizen.Wait(30000)
end
end)
Citizen.CreateThread(function()
while true do
Citizen.Wait(1)
if Citizen.InvokeNative(0x91AEF906BCA88877, 0, 0x24978A28) then -- Control = H
WhistleHorse()
Citizen.Wait(10000) --Flood Protection? i think yes zoot
end
if Citizen.InvokeNative(0x91AEF906BCA88877, 0, 0x4216AF06) then -- Control = Horse Flee
-- local horseCheck = Citizen.InvokeNative(0x7912F7FC4F6264B6, PlayerPedId(), myHorse[4])
if SpawnplayerHorse ~= 0 then
fleeHorse(SpawnplayerHorse)
end
end
end
end)
function interpCamera(cameraName, entity)
for k, v in pairs(cameraUsing) do
if cameraUsing[k].name == cameraName then
tempCam = CreateCam("DEFAULT_SCRIPTED_CAMERA")
AttachCamToEntity(tempCam, entity, cameraUsing[k].x + CamPos[1], cameraUsing[k].y + CamPos[2], cameraUsing[k].z)
SetCamActive(tempCam, true)
SetCamRot(tempCam, -30.0, 0, HeadingPoint + 50.0)
if InterP then
SetCamActiveWithInterp(tempCam, fixedCam, 1200, true, true)
InterP = false
end
end
end
end
function createCamera(entity)
groundCam = CreateCam("DEFAULT_SCRIPTED_CAMERA")
SetCamCoord(groundCam, StablePoint[1] + 0.5, StablePoint[2] - 3.6, StablePoint[3] )
SetCamRot(groundCam, -20.0, 0.0, HeadingPoint + 20)
SetCamActive(groundCam, true)
RenderScriptCams(true, false, 1, true, true)
--Wait(3000)
-- last camera, create interpolate
fixedCam = CreateCam("DEFAULT_SCRIPTED_CAMERA")
SetCamCoord(fixedCam, StablePoint[1] + 0.5, StablePoint[2] - 3.6, StablePoint[3] +1.8)
SetCamRot(fixedCam, -20.0, 0, HeadingPoint + 50.0)
SetCamActive(fixedCam, true)
SetCamActiveWithInterp(fixedCam, groundCam, 3900, true, true)
Wait(3900)
DestroyCam(groundCam)
end
AddEventHandler(
"onResourceStop",
function(resourceName)
if GetCurrentResourceName() == resourceName then
DeleteEntity(SpawnplayerHorse)
SpawnplayerHorse = 0
end
end
)