-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmod.lua
More file actions
105 lines (96 loc) · 3.19 KB
/
mod.lua
File metadata and controls
105 lines (96 loc) · 3.19 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
if not HopLib then
return
end
if not JokerInfo then
JokerInfo = {}
JokerInfo.modded_host = false
JokerInfo.messages = {}
local file = io.open(ModPath .. "messages.json", "r")
if file then
JokerInfo.messages = json.decode(file:read("*all")) or JokerInfo.messages
file:close()
end
function JokerInfo:create_text(data, index)
local text_table = data.type == 0 and self.messages.death or self.messages.survive
if not index then
for i, v in ipairs(text_table) do
if data.kills <= v.threshold or i == #text_table then
index = i
break
end
end
end
local fixed_rnd = ((data.rnd - 1) % #text_table[index].texts) + 1
return text_table[index].texts[fixed_rnd]:gsub("<N>", data.name):gsub("<K>", tostring(data.kills)):gsub("<A>", data.attacker or "an unknown force")
end
Hooks:Add("HopLibOnUnitDied", "HopLibOnUnitDiedJokerInfo", function (unit, damage_info)
if JokerInfo.modded_host then
return
end
local info = HopLib:unit_info_manager():get_info(unit)
if info and info:type() == "joker" then
local attacker_info = HopLib:unit_info_manager():get_info(damage_info.attacker_unit)
if not attacker_info then
return
end
for i, v in ipairs(JokerInfo.messages.death) do
if info:kills() <= v.threshold or i == #JokerInfo.messages.death then
local data = {
type = 0,
rnd = math.random(#v.texts),
name = info:nickname(),
kills = info:kills(),
attacker = attacker_info and attacker_info:nickname()
}
managers.chat:_receive_message(1, "Joker Info", JokerInfo:create_text(data, i), tweak_data.system_chat_color)
LuaNetworking:SendToPeers("joker_info", json.encode(data))
break
end
end
end
end)
Hooks:Add("BaseNetworkSessionOnLoadComplete", "BaseNetworkSessionOnLoadCompleteJokerInfo", function(local_peer, id)
if id ~= 1 then
LuaNetworking:SendToPeer(1, "has_joker_info", "")
end
end)
Hooks:Add("NetworkReceivedData", "NetworkReceivedDataJokerInfo", function(sender, id, data)
if id == "joker_info" then
managers.chat:_receive_message(1, "Joker Info", JokerInfo:create_text(json.decode(data)), tweak_data.system_chat_color)
elseif id == "has_joker_info" then
if sender == 1 then
JokerInfo.modded_host = true
else
LuaNetworking:SendToPeer(sender, "has_joker_info", "")
end
end
end)
end
if RequiredScript == "lib/states/missionendstate" then
local at_enter_original = MissionEndState.at_enter
function MissionEndState:at_enter(...)
DelayedCalls:Add("Joker Info", 1, function()
if JokerInfo.modded_host then
return
end
for _, info in pairs(HopLib:unit_info_manager():all_infos()) do
if info:type() == "joker" then
for i, v in ipairs(JokerInfo.messages.survive) do
if info:kills() <= v.threshold or i == #JokerInfo.messages.survive then
local data = {
type = 1,
rnd = math.random(#v.texts),
name = info:nickname(),
kills = info:kills()
}
managers.chat:_receive_message(1, "Joker Info", JokerInfo:create_text(data, i), tweak_data.system_chat_color)
LuaNetworking:SendToPeers("joker_info", json.encode(data))
break
end
end
end
end
end)
return at_enter_original(self, ...)
end
end