1
+ GetEntities = function (isPlayerEntity )
2
+ local entities = {}
3
+
4
+ if isPlayerEntity then
5
+ for _ , player in ipairs (GetActivePlayers ()) do
6
+ local ped = GetPlayerPed (player )
7
+
8
+ if DoesEntityExist (ped ) and ped ~= PlayerPedId () then
9
+ entities [player ] = ped
10
+ end
11
+ end
12
+ else
13
+ entities = GetGamePool (' CVehicle' )
14
+ end
15
+
16
+ return entities
17
+ end
18
+
19
+ GetClosestEntity = function (isPlayerEntity , coords )
20
+ local closestEntity , closestDistance = - 1 , - 1
21
+ local entites = GetEntities (isPlayerEntity )
22
+
23
+ if coords then
24
+ coords = vector3 (coords .x , coords .y , coords .z )
25
+ else
26
+ coords = GetEntityCoords (PlayerPedId ())
27
+ end
28
+
29
+ for k , entity in pairs (entites ) do
30
+ local distance = # (coords - GetEntityCoords (entity ))
31
+
32
+ if closestDistance == - 1 or distance <= closestDistance then
33
+ closestEntity , closestDistance = isPlayerEntity and k or entity , distance
34
+ end
35
+ end
36
+
37
+ return closestEntity , closestDistance
38
+ end
39
+
40
+ GetClosestEntities = function (isPlayerEntity , coords , distance )
41
+ local entites = GetEntities (isPlayerEntity )
42
+ local closestEntities = {}
43
+
44
+ if coords then
45
+ coords = vector3 (coords .x , coords .y , coords .z )
46
+ else
47
+ coords = GetEntityCoords (PlayerPedId ())
48
+ end
49
+
50
+ for k , entity in pairs (entites ) do
51
+ local dist = # (coords - GetEntityCoords (entity ))
52
+
53
+ if dist <= distance then
54
+ closestEntities [# closestEntities + 1 ] = isPlayerEntity and k or entity
55
+ end
56
+ end
57
+
58
+ return closestEntities
59
+ end
60
+
61
+ PlayerDied = function (deathCause , killer , killerServerId )
62
+ local playerPed = PlayerPedId ()
63
+ local playerCoords = GetEntityCoords (playerPed )
64
+
65
+ local data = {
66
+ killedByPlayer = false ,
67
+ victim = playerPed ,
68
+ victimCoords = playerCoords ,
69
+ victimServerId = GetPlayerServerId (PlayerId ())
70
+ }
71
+
72
+ if killer and killerServerId then
73
+ local killerPed = GetPlayerPed (killer )
74
+ local killerCoords = GetEntityCoords (killerPed )
75
+ local dist = # (playerCoords - killerCoords )
76
+
77
+ data .killedByPlayer = true
78
+ data .killer = killerPed
79
+ data .killerCoords = killerCoords
80
+ data .killerServerId = killerServerId
81
+ data .distance = MSK .Math .Round (dist , 2 )
82
+ end
83
+
84
+ TriggerEvent (' msk_core:onPlayerDeath' , data )
85
+ TriggerServerEvent (' msk_core:onPlayerDeath' , data )
86
+ end
87
+
88
+ AddEventHandler (' gameEventTriggered' , function (event , data )
89
+ if event == ' CEventNetworkEntityDamage' then
90
+ local entity , model = data [1 ], data [7 ]
91
+
92
+ if IsEntityAPed (entity ) and IsPedAPlayer (entity ) then
93
+ local playerPed = entity
94
+ local playerDied = data [4 ]
95
+
96
+ if playerDied and NetworkGetPlayerIndexFromPed (playerPed ) == PlayerId () and (IsPedDeadOrDying (playerPed , true ) or IsPedFatallyInjured (playerPed )) then
97
+ local deathCause , killerEntity = GetPedCauseOfDeath (playerPed ), GetPedSourceOfDeath (playerPed )
98
+ local killer = NetworkGetPlayerIndexFromPed (killerEntity )
99
+
100
+ if killerEntity ~= playerPed and killer and NetworkIsPlayerActive (killer ) then
101
+ PlayerDied (deathCause , killer , GetPlayerServerId (killer ))
102
+ else
103
+ PlayerDied (deathCause )
104
+ end
105
+ end
106
+ elseif IsEntityAVehicle (entity ) then
107
+ local vehicle = entity
108
+
109
+ -- Do something with the vehicle...
110
+ end
111
+ end
112
+ end )
0 commit comments