forked from ddraigcymraeg/mrp-missions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.lua
1133 lines (875 loc) · 37.4 KB
/
server.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
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
local ActiveMission=false
local MissionName="N/A"
local MissionType = ""
local IsRandomSpawnAnywhereInfo = {x=0,y=0,z=0}
local SafeHouseLocationIndex = 0
local MissionLocationIndex = 0
local MissionDestinationIndex = 0
local servercheckspawns = false
local MissionTriggered = false
--for mission timeouts
local MissionStartTime = 0
local MissionEndTime = 0
local MissionSpaceTime = 0
local MilliSecondsLeft = 0
local MissionNoTimeout = false
--used to see if we are in the time between missions, when one ends, and another starts
local blInSpaceTime = false
--local variable used to keep track of when the server should send another mission based on
--ExtraTimeToWaitToStartNextMission value
local blMadeIt = false
--used with NextMission and NextMissionIfFailed values if set
--if ProgressToNextMissionIfFail
local blFailedMission = false
--This is in minutes. How long to wait, when there are players online
--for the server to find the host and trigger a new mission
local ExtraTimeToWaitToStartNextMission = 2
--Set this to true in case there are mutiple missions being started
--or duplicate NPC peds.
--Experimental.
local blActiveMissionCheck=false
--The time between missions, is where the player who will trigger the next mission
--can disconnect. Enable this value to true if you find the missions
--stopping when this happens. Players or admins can use /mission Mission1 etc... though to start
--if this is turned off and it happens
--Experimental
local blHelpWithDisconnects=false
--Used for Type="HostageRescue" when IsRandom=true
local IsRandomMissionHostageCount = 0
local IsRandomMissionHostageRescued= 0
local IsRandomDoEvent = false
local IsRandomDoEventRadius = 1000.0
local IsRandomDoEventType = 0
--ESX Support
local UseESX=false
if UseESX then
TriggerEvent("esx:getSharedObject", function(obj)
ESX = obj
end)
RegisterServerEvent("paytheplayer")
AddEventHandler("paytheplayer",function(totalmoney)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
--xPlayer.addMoney(totalmoney)
--FIX courtesy of HMB_Frost:
if (totalmoney >= 0) then
xPlayer.addMoney(totalmoney)
else
xPlayer.removeMoney(totalmoney * -1)
end
end)
end
--players share money?
--local sharedmoney = 0
RegisterServerEvent("sharemoney")
AddEventHandler("sharemoney",function(playermissionmoney)
--print("sharemoney called:"..playermissionmoney)
TriggerClientEvent("mt:sharemoney",-1, playermissionmoney)
end)
RegisterServerEvent("sv:repairvehicle")
AddEventHandler("sv:repairvehicle",function()
TriggerClientEvent("mt:doRepairVehicle",-1)
end)
RegisterServerEvent("sv:repairtarget")
AddEventHandler("sv:repairtarget",function(MissionName)
TriggerClientEvent("mt:doRepairTarget",-1,MissionName)
end)
--looks for setting within a mission, else looks at global setting
function getMissionConfigProperty(MissionName, PropName)
--print('MissionName'..MissionName)
--print('PropName'..PropName)
for i, v in pairs(Config.Missions[MissionName]) do
if PropName == i then
return v
end
end
for i, v in pairs(Config) do
if PropName == i then
return v
end
end
end
--used to tell all clients that an indoor spawn location has been used
RegisterServerEvent("sv:spawned")
AddEventHandler("sv:spawned", function(input,i,isVehicle)
--print("Mission spawned called"..i.." isVehicle:"..tostring(isVehicle))
if isVehicle then
Config.Missions[input].Vehicles[i].spawned = true
else
Config.Missions[input].Peds[i].spawned = true
end
TriggerClientEvent("mt:spawned",-1, input,i,isVehicle)
end)
RegisterServerEvent("sv:playvoicesound")
AddEventHandler("sv:playvoicesound", function(decorid,decorval,greetspeech,voicename)
--print(decorid..decorval..greetspeech..voicename)
TriggerClientEvent("mt:playvoicesound",-1, decorid, decorval,greetspeech,voicename)
end)
RegisterServerEvent("sv:setgroundingdecor")
AddEventHandler("sv:setgroundingdecor", function(decorid,decorval)
--print(decorid..decorval..greetspeech..voicename)
TriggerClientEvent("mt:setgroundingdecor",-1, decorid, decorval)
end)
RegisterServerEvent("sv:generateCheckpointsAndEvents")
AddEventHandler("sv:generateCheckpointsAndEvents", function(MissionName,recordedCheckpoints,Events,startCoords)
--print("chk3")
--if Events then
--print(#Events)
--else
--print("no events found!")
--end
TriggerClientEvent("mt:generateCheckpointsAndEvents",-1, MissionName,recordedCheckpoints,Events)
--trigger StreetRaces createrace event
--print(#recordedCheckpoints)
--local startCoords = recordedCheckpoints[1].coords
--print(startCoords.x)
if Config.Missions[MissionName].Type=="Checkpoint" and Config.Missions[MissionName].IsRandom then
--print("made it sv ")
TriggerEvent("mrpStreetRaces:createRace_sv",1, 300000, startCoords, recordedCheckpoints, 360000)
--print("made it sv2 ")
Config.Missions[MissionName].TotalCheckpoints=#recordedCheckpoints
Config.Missions[MissionName].CheckpointsStartPos=startCoords
Config.Missions[MissionName].RecordedCheckpoints=recordedCheckpoints
end
--used for saving which player completed which checkpoint first
Config.Missions[MissionName].Checkpoints={}
--print("chk4")
Config.Missions[MissionName].Events=Events
--print("GENERATEVENTS: "..#Config.Missions[MissionName].Events)
end)
--make global
local checkpointdata
RegisterServerEvent("sv:updatePlayerCheckpoints")
AddEventHandler("sv:updatePlayerCheckpoints", function(MissionName,checkpointnum,PlayerServerId)
--print("chk"..checkpointnum)
--dont care about start of race
if checkpointnum == 0 then
--print("chkreturn"..checkpointnum)
return
end
local claimedcheckpoint = {checkpointnum=checkpointnum,PlayerServerId=PlayerServerId}
checkpointdata = Config.Missions[MissionName].Checkpoints
local checkpointclaimed = false
for i = 1,#checkpointdata do
if ( checkpointdata[i] and checkpointdata[i].checkpointnum and checkpointdata[i].checkpointnum ==checkpointnum) then
checkpointclaimed = true
break; --checkpoint already claimed by a player.
end
end
if checkpointclaimed == false then
--print("checkpoint claimed")
table.insert(checkpointdata,claimedcheckpoint)
local messagestr = "~h~~r~"..GetPlayerName(source).."~y~ has claimed checkpoint "..checkpointnum.. " and earned ~g~$"..getMissionConfigProperty(MissionName, "CheckPointClaimdReward")
TriggerClientEvent("mt:missiontext2",-1,messagestr,5000)
TriggerClientEvent("mt:rewardPassengers",-1,PlayerServerId)
end
Config.Missions[MissionName].Checkpoints=checkpointdata
end)
RegisterServerEvent("sv:one")
AddEventHandler("sv:one", function(input,input2, timet,rMissionLocationIndex,rMissionType,rIsRandomSpawnAnywhereInfo,rSafeHouseLocationIndex,rMissionDestinationIndex)
print("sv:one called to start new mission")
if blActiveMissionCheck then
if(not ActiveMission) then
TriggerClientEvent('chatMessage', -1, "^1[MISSIONS]: ^2'".. input2 .."'^0 has been launched.")
--TriggerClientEvent("mt:missiontext", -1, input, timet)
TriggerClientEvent('missionBlips', -1, input,rMissionLocationIndex,rMissionType,rIsRandomSpawnAnywhereInfo,rSafeHouseLocationIndex,true,rMissionDestinationIndex)
TriggerClientEvent("SpawnPedBlips",-1, input)
ActiveMission=true
MissionName=input
MissionType = rMissionType
MissionLocationIndex = rMissionLocationIndex
MissionDestinationIndex = rMissionDestinationIndex
IsRandomSpawnAnywhereInfo = rIsRandomSpawnAnywhereInfo
SafeHouseLocationIndex = rSafeHouseLocationIndex
blInSpaceTime = false
MissionStartTime = GetGameTimer()
MissionEndTime = MissionStartTime + getMissionConfigProperty(MissionName, "MissionLengthMinutes")*60*1000
MissionSpaceTime = getMissionConfigProperty(MissionName, "MissionSpaceTime")
MilliSecondsLeft = MissionEndTime - MissionStartTime
MissionNoTimeout = getMissionConfigProperty(MissionName, "MissionNoTimeout")
blMadeIt = false
blFailedMission=false
foundhost=false --EXPERIMENTAL ONESYNC SUPPORT
end
else
--print("rMissionType:"..rMissionType)
--print("rMissionLocationIndex:"..rMissionLocationIndex)
TriggerClientEvent('chatMessage', -1, "^1[MISSIONS]: ^2'".. input2 .."'^0 has been launched.")
TriggerClientEvent("mt:missiontext", -1, input, timet)
--print("sv:one rSafeHouseLocationIndex"..rSafeHouseLocationIndex)
--if(rSafeHouseLocationIndex) then
-- print("sv:one rSafeHouseLocationIndex found:"..rSafeHouseLocationIndex)
--else
-- print("sv:one rSafeHouseLocationIndex not found:")
--end
--print("sv:one rIsRandomSpawnAnywhereInfo.x found:".. rIsRandomSpawnAnywhereInfo.x)
--print("hey:"..timet)
TriggerClientEvent('missionBlips', -1, input,rMissionLocationIndex,rMissionType,rIsRandomSpawnAnywhereInfo,rSafeHouseLocationIndex,true,rMissionDestinationIndex)
TriggerClientEvent("SpawnPedBlips",-1, input)
ActiveMission=true
MissionName=input
MissionType = rMissionType
MissionLocationIndex = rMissionLocationIndex
MissionDestinationIndex = rMissionDestinationIndex
IsRandomSpawnAnywhereInfo = rIsRandomSpawnAnywhereInfo
SafeHouseLocationIndex = rSafeHouseLocationIndex
blInSpaceTime = false
MissionStartTime = GetGameTimer()
MissionEndTime = MissionStartTime + getMissionConfigProperty(MissionName, "MissionLengthMinutes")*60*1000
MissionSpaceTime = getMissionConfigProperty(MissionName, "MissionSpaceTime")
MilliSecondsLeft = MissionEndTime - MissionStartTime
MissionNoTimeout = getMissionConfigProperty(MissionName, "MissionNoTimeout")
blMadeIt = false
blFailedMission=false
--used for saving which player completed which checkpoint first
Config.Missions[MissionName].Checkpoints={}
foundhost=false --EXPERIMENTAL ONESYNC SUPPORT
end
end)
--move this to bottom of file:
function doPlayersExist()
local players = GetNumPlayerIndices()
local foundplayer = false
for i = 0, players - 1 do
if type(GetPlayerFromIndex(i)) ~= "nil" then
foundplayer = true
end
end
--print("found player:"..tostring(foundplayer))
--[[
if not foundplayer then
ActiveMission=false
--MissionName="N/A" --< **Leave the mission as is, so the missions will rotate**
servercheckspawns = false
blInSpaceTime = false
IsRandomMissionHostageCount = 0
IsRandomMissionHostageRescued = 0
IsRandomDoEvent = false
IsRandomDoEventRadius = 1000.0
IsRandomDoEventType = 0
if MissionName~="N/A" then
ResetIndoorSpawns (MissionName)
end
end
]]--
return foundplayer
end
--used to determine what missions are left to use
--to stop repetition:
local randomMissionBucket={}
function getIndex(tab, val)
local index = nil
for i, v in ipairs (tab) do
if (v == val) then
index = i
end
end
return index
end
function getNextMission(MissionName,InitRandom)
local missioncount = 0
local nextmission = ""
if #randomMissionBucket ==0 then
for i, v in pairs(Config.Missions) do
table.insert(randomMissionBucket, i)
end
--print("randomMissionBucke[1]:"..randomMissionBucket[1])
end
if MissionName ~= "N/A" then
for i, v in pairs(Config.Missions) do
missioncount = missioncount + 1
end
if Config.RandomMissions then
-- math.randomseed(GetGameTimer())
-- local randomNum = math.random(1,missioncount)
--nextmission = "Mission"..tostring(randomNum)
--get nextmission from bucket and then
--remove the old mission from it, only if we are
--passed initializing: not InitRandom=true
local rndMissionIndex = math.random(1,#randomMissionBucket)
local rndMission = randomMissionBucket[rndMissionIndex]
local OldMissionIndex = getIndex(randomMissionBucket, MissionName)
nextmission = rndMission
--print("rndMission:"..tostring(rndMission))
--print("OldMissionIndex:"..tostring(OldMissionIndex))
if OldMissionIndex and not InitRandom then
table.remove(randomMissionBucket, OldMissionIndex)
--print("randomMissionBucket len:"..#randomMissionBucket)
end
else
local oldMissionNumber, _ = MissionName:gsub("%D+", "")
if (tonumber(oldMissionNumber) + 1 > missioncount) then
nextmission = "Mission1"
else
nextmission = "Mission" .. tostring(math.floor((tonumber(oldMissionNumber))) + 1)
end
end
--dont let old random mission re-spawn
if missioncount > 1 then
while( nextmission == MissionName )
do
nextmission = "Mission"..tostring( math.random(1,missioncount))
end
else
nextmission = oldmission
end
--override if MissionName mission has a NextMission attribute:
--to allow joined missions
if getMissionConfigProperty(MissionName, "NextMission") then
if getMissionConfigProperty(MissionName, "ProgressToNextMissionIfFail") then
nextmission = getMissionConfigProperty(MissionName, "NextMission")
elseif not blFailedMission then
nextmission = getMissionConfigProperty(MissionName, "NextMission")
end
end
if getMissionConfigProperty(MissionName, "NextMissionIfFailed") and blFailedMission then
if not (getMissionConfigProperty(MissionName, "NextMission") and
getMissionConfigProperty(MissionName, "ProgressToNextMissionIfFail")) then
nextmission = getMissionConfigProperty(MissionName, "NextMissionIfFailed")
end
end
else
if Config.RandomMissions then
nextmission = getNextMission("Mission1",true) --"Mission1"
else
nextmission = "Mission1"
end
end
--print("nextmission:"..nextmission)
return nextmission
end
Citizen.CreateThread(function()
local starttick = GetGameTimer()
local lastActiveMissionTime = starttick
local TimeLeft = GetGameTimer()
while true do
--Citizen.Wait(60000) -- check minute
Citizen.Wait(1000)
local tick = GetGameTimer()
--MissionTime = -1, turn off timed mission checks
if ActiveMission then
lastActiveMissionTime = tick
MilliSecondsLeft = MissionEndTime - lastActiveMissionTime
if tick > MissionEndTime and (not MissionNoTimeout) then
--send client event to fail the current mission
--TriggerClientEvent('DONE', -1, input,false,true,"Mission Timeout")
--print('MISSION TIMEOUT')
TriggerClientEvent('mt:setmissionTimeout', -1,true)
else
--send minutes left to clients
--print("MissionStartTime:"..MissionStartTime)
--local currmissionminutesleft = math.floor((MilliSecondsLeft)/60000) % 60
--local currmissionsecondsleft = math.floor((MilliSecondsLeft)/1000) % 60
--local extraseconds = currmissionsecondsleft - currmissionminutesleft*60
local currmissionminutesleft = string.format("%02d", tostring(math.floor((MilliSecondsLeft)/60000) % 60))
local currmissionsecondsleft = string.format("%02d", tostring(math.floor((MilliSecondsLeft)/1000) % 60))
--print ("currmissionMilliSecondsLeft:"..MilliSecondsLeft)
--print("currmissionminutesleft:"..currmissionminutesleft)
--print("currmissionsecondsleft:"..currmissionsecondsleft)
--TriggerClientEvent('mt:setmissiontimeleft', -1, MilliSecondsLeft)
end
end
--check if we are not in space between missions or an active mission,
--and there are active players, and the extra time waited beyond the end of the last mission + spacetime has occured.
--this code is for when the mission system first starts up:
--if (MissionEndTime == 0 and MissionSpaceTime == 0) then
--MissionEndTime = tick
--end
if (not ActiveMission and not blInSpaceTime and not blMadeIt) then
if (((MissionEndTime + MissionSpaceTime) + ExtraTimeToWaitToStartNextMission*60*1000))- tick > ExtraTimeToWaitToStartNextMission*60*1000 then
TimeLeft = tick + ExtraTimeToWaitToStartNextMission*60*1000
blMadeIt = true
--print("h1")
end
elseif not blMadeIt then
TimeLeft = ((MissionEndTime + MissionSpaceTime) + ExtraTimeToWaitToStartNextMission*60*1000)
blMadeIt = true
--print("h2")
end
--print("SERVER:Next time to send a mission:"..(TimeLeft - tick))
if (not ActiveMission and not blInSpaceTime and ((tick) >= TimeLeft)) and doPlayersExist() then
Wait(10000)
if not ActiveMission then
print("Server Start Mission")
TriggerClientEvent("mt:checkIfIAmHost", -1)
end
end
-- if you want days then use this:
-- local uptimeDay = math.floor((tick-starttick)/86400000)
-- if you use day then change the hour to this:
-- local uptimeHour = math.floor((tick-starttick)/3600000) % 24
--local uptimeHour = math.floor((tick-starttick)/3600000)
--if you want seconds then use this:
--local uptimeMinute = math.floor((tick-starttick)/60000) % 60
--local uptimeSecond = math.floor((tick-starttick)/1000) % 60
--ExecuteCommand(string.format("sets Uptime \"%02dh %02dm\"", uptimeHour, uptimeMinute))
end
end)
--used for joining client for IsRandom HostageRescue mission
RegisterServerEvent("sv:UpdateisHostageRescueCount")
AddEventHandler("sv:UpdateisHostageRescueCount", function()
--print("remaininHostageRescued"..(IsRandomMissionHostageCount - IsRandomMissionHostageRescued))
TriggerClientEvent('mt:UpdateisHostageRescueCount', source, (IsRandomMissionHostageCount - IsRandomMissionHostageRescued))
end)
--setting decor values on NPCs on non-host clients do not seem to propogate
--like when on the host, so when non-host changes a value on an
--NPC make sure everyone does it, most importantly the host as well
--ALSO USED FOR OBJECTIVE RESCUE MISSIONS:
RegisterServerEvent("sv:rescuehostage")
AddEventHandler("sv:rescuehostage", function(hostageid,decorval)
--print("sv:rescuehostage:"..hostageid)
TriggerClientEvent('mt:rescuehostage', -1, hostageid,decorval)
if(Config.Missions[MissionName].Type=="HostageRescue" and not Config.Missions[MissionName].IsRandom and decorval=="mrppedfriend") then
Config.Missions[MissionName].Peds[hostageid].rescued=true
local isHostageRescueCount = 0
for i, v in pairs(Config.Missions[MissionName].Peds) do
if Config.Missions[MissionName].Peds[i].friendly and not Config.Missions[MissionName].Peds[i].dead and not Config.Missions[MissionName].Peds[i].rescued then
isHostageRescueCount = isHostageRescueCount + 1
end
end
TriggerClientEvent('mt:UpdateisHostageRescueCount', -1, isHostageRescueCount)
end
if(Config.Missions[MissionName].Type=="ObjectiveRescue" and not Config.Missions[MissionName].IsRandom and decorval=="mrpproprescue") then
Config.Missions[MissionName].Props[hostageid].rescued=true
--now count up remaining isObective props left to rescue
local isObjectiveRescueCount = 0
for i, v in pairs(Config.Missions[MissionName].Props) do
if Config.Missions[MissionName].Props[i].isObjective and not Config.Missions[MissionName].Props[i].rescued then
isObjectiveRescueCount = isObjectiveRescueCount + 1
end
end
TriggerClientEvent('mt:UpdateisObectiveRescueCount', -1, isObjectiveRescueCount)
end
if MissionType=="HostageRescue" and Config.Missions[MissionName].IsRandom then
IsRandomMissionHostageRescued = IsRandomMissionHostageRescued + 1
--print((IsRandomMissionHostageCount - IsRandomMissionHostageRescued))
TriggerClientEvent('mt:UpdateisHostageRescueCount', -1, (IsRandomMissionHostageCount - IsRandomMissionHostageRescued))
if IsRandomMissionHostageRescued == IsRandomMissionHostageCount then
TriggerClientEvent('mt:IsRandomMissionAllHostagesRescued', -1, true)
end
end
end)
RegisterServerEvent("sv:two")
AddEventHandler("sv:two", function(message)
TriggerClientEvent('chatMessage', -1, message)
end)
RegisterServerEvent("sv:message")
AddEventHandler("sv:message", function(message)
TriggerClientEvent("mt:missiontext2", -1, message, 10000)
end)
RegisterServerEvent("sv:messagetosource")
AddEventHandler("sv:messagetosource", function(message)
TriggerClientEvent("mt:missiontext2", source, message, 10000)
end)
--called by the/a client at mission end when completed
--for server to find the NetworkIsHost() to start the next mission
RegisterServerEvent("sv:getHostForNextMission")
AddEventHandler("sv:getHostForNextMission", function(input)
print('sv:getHostForNextMission called')
TriggerClientEvent("mt:checkIfIAmHost", -1)
end)
--capture replies from mt:checkIfIAmHost in order to find the host
--to spawn the NPCs and vehicles on, who will start the mission
local foundhost=false --EXPERIMANTAL ONESYNC SUPPORT
RegisterServerEvent("sv:getClientWhoIsHostAndStartNextMission")
AddEventHandler("sv:getClientWhoIsHostAndStartNextMission", function(isHost,newMission)
--print("made it")
local nextmission = getNextMission(MissionName)
if newMission then
--TEST
--print("newMission" ..newMission)
nextmission = newMission
end
--isHost=true
print("sv:getClientWhoIsHostAndStartNextMission called")
if(isHost) and not foundhost then
foundhost=true
print("found Host:"..source)
print("next mission:"..nextmission)
--triggerclient event to start next mission
TriggerClientEvent("mt:startnextmission", source,nextmission)
end
end)
--called by a client, to set Events as done on clients so they do not have to do them
--for Type="HostageRescue" missions
RegisterServerEvent("sv:UpdateEvents")
AddEventHandler("sv:UpdateEvents", function(k,PlayerServerId)
--print("event called"..k)
--print("length:"..#Config.Missions[MissionName].Events)
Config.Missions[MissionName].Events[k].done=true
TriggerClientEvent('mt:UpdateEvents',-1,k,PlayerServerId,MissionName)
end)
--called by a client, to set Events as done on clients so they do not have to do them
--for Type="HostageRescue" missions
RegisterServerEvent("sv:IsRandomDoEvent")
AddEventHandler("sv:IsRandomDoEvent", function(clIsRandomDoEvent,clIsRandomDoEventRadius,clIsRandomDoEventType)
--print("IsRandomDoEvent called:"..clIsRandomDoEventType)
IsRandomDoEvent = clIsRandomDoEvent
IsRandomDoEventRadius = clIsRandomDoEventRadius
IsRandomDoEventType = clIsRandomDoEventType
TriggerClientEvent('mt:IsRandomDoEvent',-1,IsRandomDoEvent,IsRandomDoEventRadius,IsRandomDoEventType)
end)
--called by host, to set IsRandomMissionHostageCount
--for Type="HostageRescue" missions
RegisterServerEvent("sv:IsRandomMissionHostageCount")
AddEventHandler("sv:IsRandomMissionHostageCount", function(clIsRandomMissionHostageCount)
-- TriggerClientEvent("mt:IsRandomMissionHostageCount", -1, IsRandomMissionHostageCount)
IsRandomMissionHostageCount = clIsRandomMissionHostageCount
TriggerClientEvent('mt:UpdateisHostageRescueCount',-1,IsRandomMissionHostageCount)
--print("IsRandomMissionHostageCount:"..IsRandomMissionHostageCount)
end)
--called by host, to have other clients readjust suspicious spawns
RegisterServerEvent("sv:checkspawns")
AddEventHandler("sv:checkspawns", function(checkspawns)
servercheckspawns = checkspawns
TriggerClientEvent("mt:checkspawns", -1, checkspawns)
end)
--called by connecting client, to see if they have to readjust suspicious spawns
--RegisterServerEvent("sv:getcheckspawns")
--AddEventHandler("sv:getcheckspawns", function()
-- TriggerClientEvent("mt:checkspawns", source, servercheckspawns)
--end)
--ALSO resets rescued flags for Type="HostageRescue"
--& "ObjectiveRescue"
function ResetIndoorSpawns (input)
--RESET INDOOR MISSION SPAWNS
if Config.Missions[input].IndoorsMission then
if Config.Missions[input].Peds then
for i, v in pairs(Config.Missions[input].Peds) do
Config.Missions[input].Peds[i].spawned=false
end
end
--print(input)
if Config.Missions[input].Vehicles then
for i, v in pairs(Config.Missions[input].Vehicles) do
Config.Missions[input].Vehicles[i].spawned = false
end
end
end
if Config.Missions[input].Type=="HostageRescue" then
if Config.Missions[input].Peds then
for i, v in pairs(Config.Missions[input].Peds) do
Config.Missions[input].Peds[i].rescued=false
end
end
end
if Config.Missions[input].Type=="ObjectiveRescue" then
if Config.Missions[input].Props then
for i, v in pairs(Config.Missions[input].Props) do
Config.Missions[input].Props[i].rescued=false
end
end
end
if Config.Missions[input].Events then
for i, v in pairs(Config.Missions[input].Events) do
--print("Event done:"..i)
Config.Missions[input].Events[i].done=false
end
end
end
RegisterServerEvent("sv:CheckMissionHost")
AddEventHandler("sv:CheckMissionHost", function()
TriggerClientEvent('mt:CheckMissionHost', -1)
end)
RegisterServerEvent("sv:CheckHostFlag")
AddEventHandler("sv:CheckHostFlag", function(BLHOSTFLAG)
--found the mission host, trigger the mission
if(BLHOSTFLAG) then
MissionTriggered=true
TriggerClientEvent('mt:TriggerMission', -1,MissionName)
end
end)
--HACK for now
RegisterServerEvent("sv:KillTargetPed")
AddEventHandler("sv:KillTargetPed", function()
TriggerClientEvent('mt:KillTargetPed', -1)
end)
RegisterServerEvent("sv:done")
AddEventHandler("sv:done", function(input,isstop,isfail,reasontext,blGoalReached)
--make sure not multiple done messages
foundhost=false --EXPERIMENTAL ONESYNC SUPPORT
if ActiveMission and MissionName~="N/A" then
if Config.Missions[MissionName].Type=="Checkpoint" then
--print("cance race")
TriggerEvent("mrpStreetRaces:cancelRace_sv")
end
--remove any random events
local REvents = Config.Missions[MissionName].Events
local rem_key = {}
--print("REvents"..#REvents)
if REvents then
for index, irevent in pairs(REvents) do
--print(index)
if irevent.revent or irevent.checkpoint then
-- Matches existing checkpoint, remove blip and checkpoint from table
--print("r"..index)
--table.remove(REvents, index)
-- print("t"..index)
table.insert(rem_key, index)
end
end
for i = #rem_key, 1, -1 do
value = rem_key[i]
table.remove(REvents, value)
end
Config.Missions[MissionName].Events = REvents
end
--used for mrpStreetRaces:
local MName = input
if MName == '' then
MName = MissionName
end
ActiveMission=false
--MissionName="N/A" --< **Leave the mission as is, so the missions will rotate**
servercheckspawns = false
blInSpaceTime = false
IsRandomMissionHostageCount = 0
IsRandomMissionHostageRescued = 0
IsRandomDoEvent = false
IsRandomDoEventRadius = 1000.0
IsRandomDoEventType = 0
MissionTriggered = false
ResetIndoorSpawns (MName)
TriggerClientEvent('DONE', -1, MName,isstop,isfail,reasontext,blGoalReached,checkpointdata) --GHK
blMadeIt = false
if not isstop and isfail then
blFailedMission = true
end
end
end)
RegisterServerEvent("sv:checkhostandremovepickups")
AddEventHandler("sv:checkhostandremovepickups", function(oldmission,nextmission,timetowait)
local sourceplayer = source
blInSpaceTime = true
Citizen.Wait(timetowait)
blInSpaceTime = false
TriggerClientEvent('mt:removepickups', -1, oldmission)
--check if player index is still online
local foundplayer = false
local players = GetNumPlayerIndices()
for i = 0, players - 1 do
if tonumber(GetPlayerFromIndex(i)) == tonumber(sourceplayer) then
foundplayer = true
end
end
--can probaaly remove this code now:
if not foundplayer and blHelpWithDisconnects then
--'host' player disconnected
local newplayers = GetNumPlayerIndices()
local foundnewplayer = false
local newindex = 0
for i = 0, newplayers - 1 do
if type(GetPlayerFromIndex(i)) ~= "nil" then
foundnewplayer = true
newindex = i
end
if(foundnewplayer) then
--find another player to start the nextmission with
--and 'hack' the client call for now, which is used for the first player on server
--blHelpWithDisconnects
--***DOUBLE CHECK THIS LOGIC ON CLIENT SIDE***
--NEW MISSION...
MilliSecondsLeft = getMissionConfigProperty(MissionName, "MissionLengthMinutes")*60*1000
TriggerClientEvent('mt:setactive', GetPlayerFromIndex(newindex), 1,nextmission,1,false,MilliSecondsLeft)
--be consistent and send host the mission triggered flag if it is true
--for some reason, should never be though in this case.
if MissionTriggered then
TriggerClientEvent('mt:TriggerMission', -1,MissionName)
end
end
end
end
end)
RegisterServerEvent("sv:getmillisecondsleft")
AddEventHandler("sv:getmillisecondsleft", function()
local timeLeft = MilliSecondsLeft
TriggerClientEvent('mrpStreetRaces:getmillisecondsleft', source,timeLeft)
end)
--called when a player joins
--if mission is currently running on server (ActiveMission=true), and they are only player
--enable mission for them and spawn peds, set mission blip, and NPC blips
--if mission is running on server (ActiveMission=true) and there are other players
--enable mission for them, dont spawn peds, but set mission blip and NPC blips
--if mission is not running on server (ActiveMission=false), and they are the only player
--set Mission to 'Mission1' and enable mission for them and spawn peds, set mission blips, and NPC blips
RegisterServerEvent("sv:checkmission")
AddEventHandler("sv:checkmission", function(blfirstplayer)
print('sv:checkmission')
local onlinePlayers = GetNumPlayerIndices()
if onlinePlayers > 0 then
if ActiveMission then
print('mt:setactive activemission')
--print("sv:one rSafeHouseLocationIndex"..SafeHouseLocationIndex)
--if(SafeHouseLocationIndex) then
--print("sv:one rSafeHouseLocationIndex found:"..SafeHouseLocationIndex)
--else
--print("sv:one rSafeHouseLocationIndex not found:")
--end
--print("sv:one IsRandomSpawnAnywhereInfo.x found:".. IsRandomSpawnAnywhereInfo.x)
TriggerClientEvent('mt:setactive', source, 1,MissionName,onlinePlayers,servercheckspawns,MilliSecondsLeft,ActiveMission,MissionType,MissionLocationIndex,IsRandomSpawnAnywhereInfo,SafeHouseLocationIndex,Config.Missions[MissionName].Peds,Config.Missions[MissionName].Vehicles,Config.Missions[MissionName].Props,Config.Missions[MissionName].Events,IsRandomDoEvent,IsRandomDoEventRadius,IsRandomDoEventType,MissionDestinationIndex)
blInSpaceTime = false
--do checkpoint mission stuff
if Config.Missions[MissionName].Type=="Checkpoint" then
--this just generates Events
--TriggerClientEvent("mt:generateCheckpointsAndEvents",-1, MissionName,Config.Missions[MissionName].RecordedCheckpoints,Config.Missions[MissionName].Events)
TriggerClientEvent("mrpStreetRaces:createRace_cl", source, 1, 1, 300000, Config.Missions[MissionName].CheckpointsStartPos, Config.Missions[MissionName].RecordedCheckpoints)
end
--send host the mission triggered flag if it is true
if MissionTriggered then
TriggerClientEvent('mt:TriggerMission', -1,MissionName)
end
else
if onlinePlayers == 1 and Config.StartMissionsOnSpawn then
if MissionName == "N/A" then
if Config.RandomMissions then
MissionName = getNextMission("Mission1",true) --"Mission1"
else
MissionName = "Mission1"
end
end
print('mt:setactive newmission')
ActiveMission=true
servercheckspawns = false
blInSpaceTime = false
--NEW MISSION...
MissionStartTime = GetGameTimer()
MissionEndTime = MissionStartTime + getMissionConfigProperty(MissionName, "MissionLengthMinutes")*60*1000
MissionSpaceTime = getMissionConfigProperty(MissionName, "MissionSpaceTime")
--both lines below are the same:
--MilliSecondsLeft = MissionEndTime - MissionStartTime
MilliSecondsLeft = getMissionConfigProperty(MissionName, "MissionLengthMinutes")*60*1000
MissionNoTimeout = getMissionConfigProperty(MissionName, "MissionNoTimeout")
TriggerClientEvent('mt:setactive', source, 1,MissionName,onlinePlayers,servercheckspawns,MilliSecondsLeft,ActiveMission,MissionType,MissionLocationIndex,IsRandomSpawnAnywhereInfo,SafeHouseLocationIndex,Config.Missions[MissionName].Peds,Config.Missions[MissionName].Vehicles,Config.Missions[MissionName].Props,Config.Missions[MissionName].Events,IsRandomDoEvent,IsRandomDoEventRadius,IsRandomDoEventType,MissionDestinationIndex)
--be consistent and send host the mission triggered flag if it is true
--for some reason, should never be though in this case.
if MissionTriggered then
TriggerClientEvent('mt:TriggerMission', -1,MissionName)
end
end
end
end
end)
--all credit below to FAXES for his Vote-To-Kick resource: https://forum.fivem.net/t/release-vote-to-kick-vote-players-out-fax-vote2kick-1-0/191676
-----------------------------------
--- BASED ON: Vote to Kick, Made by FAXES ---
-----------------------------------
local voteCount = 0
local canStartVote = true
local voteActive = false
local tPlayer = nil
local svrSeconds = 0
local svrMinutes = 0
minVoteAmt = 1 -- Amount of 'yes' votes needed to cancel the mission