This repository was archived by the owner on Aug 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbleeding.lua
More file actions
134 lines (114 loc) · 3.82 KB
/
bleeding.lua
File metadata and controls
134 lines (114 loc) · 3.82 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
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
local PLUGIN = PLUGIN
PLUGIN.name = "Bleeding"
PLUGIN.author = "sky"
PLUGIN.desc = "Adds the possibility for players to bleed"
nut.config.add("bleed", true, "Whether bleeding is on.", nil, {
category = "server"
})
function PLUGIN:GetBleed(char)
return char:getData("bleed", 0)
end
if(SERVER) then
function PLUGIN:RemoveBleed(char, death)
if(char:getData("bleed")) then
if(death) then char:setData("bleed", nil, nil, nil, player.GetAll()) end
if(timer.Exists("bleedtime"..char:getID())) then
timer.Remove("bleedtime"..char:getID())
end
end
end
--[[
freq = delay
do quicker freqs for faster bleeds (constant 1 dmg)
]]
function PLUGIN:CreateBleed(char, freq)
local ply = char:getPlayer()
local id = "bleedtime"..ply:getChar():getID()
if(timer.Exists(id)) then
timer.Remove(id)
end
local targ = ply --justincaseidk
local tiks = 0
local max = freq*10
local typtik = 0
ply:getChar():setData("bleed", freq, nil, nil, player.GetAll())
timer.Create(id, freq, 0, function()
if(!IsValid(targ) or targ:getNetVar("neardeath") or !targ:Alive()) then
timer.Remove(id)
return
end
--this could be changed to always but idk id prefer no
--this will slow bleeding for players so they can type, it ticks at 1/4th of the normal time
--increased it to 1/16
if(ply:getNetVar("typing") and !ply:getNutData("typeImm") and typtik < 16) then
typtik = typtik + 1
return
elseif(ply:getNetVar("typing") and !ply:getNutData("typeImm") and typtik == 16) then
typtik = 0
end
tiks = tiks+1
if(tiks > freq*6) then
tiks = 0
hook.Run("ReduceBleed", char, 1.5)
--self:CreateBleed(char, freq*1.5)
return
end
targ:TakeDamage(1, game.GetWorld(), game.GetWorld())
end)
end
hook.Add("ReduceBleed", "function", function(char, amt)
local bleed = char:getData("bleed", 0)
local mult = nut.traits.getMod(char:getPlayer(), "bleed", bleed, amt)
if(bleed == 0) then
return
end
if(((bleed*amt)*mult) >= 3) then
PLUGIN:RemoveBleed(char, true)
else
PLUGIN:CreateBleed(char, ((bleed*amt)*mult))
end
end)
hook.Add("EntityTakeDamage", "zzbleed", function(target, dmg)
if(!(dmg:IsDamageType(DMG_BULLET) --whitelisting to only these dmg types
or dmg:IsDamageType(DMG_CRUSH)
or dmg:IsDamageType(DMG_SLASH)
or dmg:IsDamageType(DMG_FALL)
or dmg:IsDamageType(DMG_BLAST))) then
return
end
if(target:IsPlayer()) then
if(target:HasGodMode()) then return end --ye
local min, chance, chance2 = nut.traits.getMod(target, "minbleed")
if(IsValid(dmg:GetAttacker()) and dmg:GetAttacker():IsPlayer() and math.random(20) <= 5) then return end --25% chance for no bleed at all vs player
if((dmg:GetDamage() >= (min or 19)) and math.random(1,chance or 100) > (chance2 or 75)) then
print("bleeding!")
local bleed = target:getChar():getData("bleed") and -0.25 or 2.75 --todo better way?
PLUGIN:CreateBleed(target:getChar(), math.Clamp(target:getChar():getData("bleed", 0)+(1*bleed), 0.01, 2.999)) --need to do some kind of thing to determine freq based on dmg?
end
end
end)
hook.Add("PlayerLoadedChar", "bleedswitch", function(ply, char, lastChar)
if(lastChar) then
PLUGIN:RemoveBleed(lastChar)
end
local bleed = ply:getChar():getData("bleed")
if(bleed) then
PLUGIN:CreateBleed(char, bleed)
end
end)
function PLUGIN:PlayerDeath(client, inflictor, attacker)
self:RemoveBleed(client:getChar(), true)
end
hook.Add("OnDown", "stopbleeding", function(ply, dmg)
PLUGIN:RemoveBleed(ply:getChar(), true)
end)
else--client
nut.bar.add(function()
if(LocalPlayer():getChar()) then --just to be safe
local bleed = PLUGIN:GetBleed(LocalPlayer():getChar())
return math.min(((bleed == 0 and 3) or bleed / 3), 1)
else
return 0
end
end, Color(255, 45, 126), nil, "bleed")
end