-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathclient.lua
More file actions
76 lines (64 loc) · 2.59 KB
/
client.lua
File metadata and controls
76 lines (64 loc) · 2.59 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
local stunnedCache = {}
local stunnedStack = 0
local function DoTaserEffect(effectLength)
stunnedStack = stunnedStack + 1
SetTimecycleModifierStrength(Config.TimecycleStrength)
SetTimecycleModifier("dont_tazeme_bro")
if Config.CameraShake then
ShakeGameplayCam(Config.CameraShakeName, Config.CameraShakeIntensity)
end
Wait(effectLength)
stunnedStack = stunnedStack - 1
if stunnedStack == 0 then
SetTransitionTimecycleModifier('default', Config.TimecycleTransitionDuration)
if Config.CameraShake then
StopGameplayCamShaking(false)
end
end
end
local function OnLocalPlayerStunned(playerPed, attacker)
-- This usually won't effect the player ped the first time the get stunned.
local groundTime = Config.MinGroundTime == Config.MaxGroundTime and Config.MinGroundTime or math.random(Config.MinGroundTime, Config.MaxGroundTime)
SetPedMinGroundTimeForStungun(playerPed, groundTime)
-- Needed as weaponHash does not guarantee that we actually were stunned, and IsPedBeingStunned doesn't return true before a frame after beeing stunned
SetTimeout(50, function()
local gameTimer = GetGameTimer()
-- If the player was stunned by the same source less them 2.8 seconds ago then ignore, this is to not spam the event when taking fall damage while beeing stunned
if stunnedCache[attacker] and stunnedCache[attacker] + 2800 > gameTimer then
return
end
if IsPedBeingStunned(playerPed, 0) then
stunnedCache[attacker] = gameTimer
DoTaserEffect(groundTime)
end
end)
end
local function OnNPCStunned(args)
local ped = args[1]
if Config.DisableNPCWrithe then
SetPedConfigFlag(ped, 281, true) -- Disable Writhe
end
if Config.NPCDropWeapon then
Wait(400)
local visible, _currentWeapon = GetCurrentPedWeapon(ped, true)
if visible then
SetPedDropsWeapon(ped)
end
end
end
-- Use game events to avoid unnecessary threads/loops
AddEventHandler('gameEventTriggered', function(event, args)
if event == "CEventNetworkEntityDamage" then
local weaponHash = args[7]
if not Config.ValidWeapons[weaponHash] then
return
end
local playerPed = PlayerPedId()
local attacker = args[2]
if playerPed == args[1] and attacker ~= -1 then
OnLocalPlayerStunned(playerPed, attacker)
elseif IsEntityAPed(args[1]) and not IsPedAPlayer(args[1]) and NetworkHasControlOfEntity(args[1]) then
OnNPCStunned(args)
end
end
end)