-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathcl_savezones.lua
More file actions
89 lines (68 loc) · 2.71 KB
/
Copy pathcl_savezones.lua
File metadata and controls
89 lines (68 loc) · 2.71 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 GUARD_MODEL = GetHashKey("u_m_y_juggernaut_01")
local GUARDSPAWN_ID_DECOR = "_GUARD_SPAWNID"
DecorRegister(GUARDSPAWN_ID_DECOR, 3)
AddTextEntry("SAFEZONE_BLIP_NAME", "Safezone")
local function SpawnGuard(guardSpawn)
local guard = Utils.CreatePed(GUARD_MODEL, 25, vector3(guardSpawn[1], guardSpawn[2], guardSpawn[3]), guardSpawn[4])
SetPedRelationshipGroupHash(guard, SAFEZONE_GUARD_GROUP)
SetEntityInvincible(guard, true)
SetPedSeeingRange(guard, 75.0)
SetPedHearingRange(guard, 75.0)
GiveWeaponToPed(guard, GetHashKey(Config.Spawning.Safezones.GUARD_WEAPONS[math.random(1, #Config.Spawning.Safezones.GUARD_WEAPONS)]),
9999, true, true)
SetPedAccuracy(guard, 100)
SetPedFiringPattern(guard, GetHashKey("FIRING_PATTERN_FULL_AUTO"))
SetPedCombatAttributes(guard, 0, false)
SetPedCanRagdoll(guard, false)
SetPedAlertness(guard, 3)
SetPedSphereDefensiveArea(guard, guardSpawn[1], guardSpawn[2], guardSpawn[3], 25.0)
SetPedDesiredHeading(guard, guardSpawn[4])
SetPedToInformRespectedFriends(guard, 20.0, 1)
DecorSetInt(guard, GUARDSPAWN_ID_DECOR, guardSpawn.Id)
end
local function HandleGuardSpawning()
local untilPause = 10
local spawnedIds = {}
for ped, pedData in pairs(g_peds) do
if pedData.IsGuard then
local guardCoords = GetEntityCoords(ped)
if not Utils.IsPosNearAPlayer(guardCoords, Config.Spawning.Safezones.SPAWN_DIST) then
SetPedAsNoLongerNeeded(ped)
else
spawnedIds[DecorGetInt(ped, GUARDSPAWN_ID_DECOR)] = true
end
untilPause = untilPause - 1
if untilPause == 0 then
untilPause = 10
Wait(0)
end
end
end
for _, safezone in ipairs(Config.Spawning.Safezones.SAFEZONES) do
for _, guardSpawn in ipairs(safezone.GuardSpawns) do
if guardSpawn.Id and not spawnedIds[guardSpawn.Id] then
SpawnGuard(guardSpawn)
end
end
end
end
RegisterNetEvent("GuardSpawn")
AddEventHandler("GuardSpawn", function()
HandleGuardSpawning()
end)
Citizen.CreateThread(function()
local id = 0
for _, safezone in ipairs(Config.Spawning.Safezones.SAFEZONES) do
local blipCoords = safezone.Core
local blip = AddBlipForCoord(blipCoords[1], blipCoords[2], blipCoords[3])
SetBlipSprite(blip, 487)
SetBlipAsShortRange(blip, true)
SetBlipScale(blip, 0.9)
EndTextCommandSetBlipName(blip)
SetBlipNameFromTextFile(blip, "SAFEZONE_BLIP_NAME")
for _, guardSpawn in ipairs(safezone.GuardSpawns) do
guardSpawn.Id = id
id = id + 1
end
end
end)