-
Notifications
You must be signed in to change notification settings - Fork 3
/
c_passive.lua
170 lines (135 loc) · 4.14 KB
/
c_passive.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
Citizen.CreateThread(function()
TriggerEvent('chat:addSuggestion','/'.. config.ChatCommand, 'Toggle Passive Mode', {
})
passiveMode = config.PassiveOnLoad
coolDown = false
coolDownTimeRemaining = 0
isInSafeZone = false
end)
if (config.PassiveOnLoad) then
passiveText = "Passive Mode Enabled"
else
passiveText = ""
end
RegisterCommand(config.ChatCommand, function(source,args)
TogglePassive()
end)
function TogglePassive()
if passiveMode then
if not coolDown then
SetCanAttackFriendly(GetPlayerPed(-1), true, false)
NetworkSetFriendlyFireOption(true)
ShowNotification("Passive Mode Disabled - You might get hurt!")
passiveMode = false
passiveText = ""
StartCooldown()
else
ShowNotification("You need to wait at least ".. tostring(coolDownTimeRemaining) .." seconds to enter passive mode")
end
else
if not coolDown then
SetCanAttackFriendly(GetPlayerPed(-1), false, false)
NetworkSetFriendlyFireOption(false)
ShowNotification("Passive Mode Enabled - You are safe!")
passiveMode = true
passiveText = "Passive Mode Enabled"
StartCooldown()
else
ShowNotification("You need to wait at least ".. tostring(coolDownTimeRemaining) .." seconds to exit passive mode.")
end
end
end
function StartCooldown()
coolDown = true
coolDownTimeRemaining = config.CoolDownTimer
Citizen.CreateThread(function()
while (coolDownTimeRemaining ~= 0) do
Wait( 1000 )
coolDownTimeRemaining = coolDownTimeRemaining - 1
end
end)
Citizen.Wait(config.CoolDownTimer * 1000)
coolDown = false
end
exports("passiveModeEnabled",function()
return passiveMode
end)
exports("isInSafeZone",function()
return isInSafeZone
end)
function ShowNotification( text )
SetNotificationTextEntry( "STRING" )
AddTextComponentString( text )
DrawNotification( false, false )
end
Citizen.CreateThread(function()
local _string = "STRING"
local _scale = 0.42
local _font = 4
while true do
SetTextScale(_scale, _scale)
SetTextColour(0,255,127,255)
SetTextFont(_font)
SetTextOutline()
BeginTextCommandDisplayText(_string)
AddTextComponentSubstringPlayerName(passiveText)
EndTextCommandDisplayText(config.textPosX, config.textPosY)
Wait(0)
end
end)
-- SAFE ZONES
if config.useSafeZones then
Citizen.CreateThread(function ()
while true do
Citizen.Wait(5)
local player = GetPlayerPed(-1)
local playerLoc = GetEntityCoords(player)
local posCounts = 0
for _,location in ipairs(safeZones) do
loc = {
x=location[1][1],
y=location[1][2],
z=location[1][3],
heading= 0,
radius = location[2]
}
if CheckPos(playerLoc.x, playerLoc.y, playerLoc.z, loc.x, loc.y, loc.z, loc.radius) then
posCounts += 1
end
end
if posCounts > 0 then
isInSafeZone = true
else
isInSafeZone = false
end
postCounts = 0
if isInSafeZone then
DisablePlayerFiring(player, true)
end
if isInSafeZone and not passiveMode then
SetCanAttackFriendly(GetPlayerPed(-1), false, false)
NetworkSetFriendlyFireOption(false)
passiveText = "Safe Zone"
elseif isInSafeZone and passiveMode then
passiveText = "Safe Zone"
elseif not isInSafeZone and not passiveMode then
SetCanAttackFriendly(GetPlayerPed(-1), true, false)
NetworkSetFriendlyFireOption(true)
passiveText = ""
elseif not isInSafeZone and passiveMode then
SetCanAttackFriendly(GetPlayerPed(-1), false, false)
NetworkSetFriendlyFireOption(false)
passiveText = "Passive Mode Enabled"
end
end
end)
end
function CheckPos(x, y, z, cx, cy, cz, radius)
local t1 = x - cx
local t12 = t1^2
local t2 = y-cy
local t21 = t2^2
local t3 = z - cz
local t31 = t3^2
return (t12 + t21 + t31) <= radius^2
end