Untitled
unknown
lua
2 years ago
4.4 kB
23
Indexable
Never
local mod_name = "berkriders anti civilian" local loaded = rawget(_G, mod_name) local c = not loaded and rawset(_G, mod_name, {toggle = true, player_data = {}}) and _G[mod_name] or loaded if not loaded then function c:init() self.ban_player = false self.jail_player = true -- Jail/kick player self.clear_equipment = false -- Clear player equipment on dropin after jail self.max_civilians = 6 -- Amount of civilians to die before punishment self.notify = false -- Announce to others self.host_only = false -- Use when host only self.chat_tag = "BAC" self.low_threat_color = Color("f7f300") -- Yellow self.medium_threat_color = Color("f76f00") -- Orange self.high_threat_color = Color("f80000") -- Red end function c:punish_player() if self.ban_player and not managers.ban_list:banned(self.user_id) then managers.ban_list:ban(self.user_id, self.peer_name) end if Network:is_server() then local peer_id = self.peer:id() if self.jail_player then local unit_health = self.attacker_unit:character_damage() and self.attacker_unit:character_damage():_max_health() self.peer:send("sync_player_movement_state", "dead", 1, peer_id) self.peer:send("spawn_dropin_penalty", true, false, (unit_health or 23), self.clear_equipment, 0, 0) else self.session:send_to_peers("kick_peer", peer_id, 6) self.session:on_peer_kicked(self.peer, peer_id, 6) end end self.player_data[self.user_id].civilians_killed = 0 end function c:register_player(damage_info) self.attacker_unit = type(damage_info) == "table" and damage_info.attacker_unit self.peer = self.attacker_unit:network():peer() self.user_id = self.peer:user_id() self.peer_name = self.peer:name() self.session = BaseNetworkHandler._verify_in_session() if self.session and (not self.host_only or Network:is_server()) and BaseNetworkHandler._verify_character_and_sender(self.attacker_unit, self.peer:rpc()) and self.attacker_unit:key() ~= managers.player:player_unit():key() then self.player_data[self.user_id] = self.player_data[self.user_id] or {} if self.player_data[self.user_id].civilians_killed then self.player_data[self.user_id].civilians_killed = self.player_data[self.user_id].civilians_killed + 1 else self.player_data[self.user_id].civilians_killed = 1 end local civs_killed = self.player_data[self.user_id].civilians_killed local amount = managers.money:get_civilian_deduction() * civs_killed local kills_and_cost = string.format("%s killed (%s / %s) civilian(s) and paid $%s cleaner costs.", self.peer_name, civs_killed, self.max_civilians, amount) if civs_killed == self.max_civilians then self:punish_player() if self.notify then managers.chat:send_message(1, managers.network.account:username(), string.format("%s: %s was punished for reaching max kill count.\n%s", self.chat_tag, self.peer_name, kills_and_cost)) else managers.chat:_receive_message(1, self.chat_tag, string.format("%s was punished for reaching max kill count.\n%s", self.peer_name, kills_and_cost), self.high_threat_color) end else if self.notify then managers.chat:send_message(1, managers.network.account:username(), self.chat_tag..": "..kills_and_cost) else managers.chat:_receive_message(1, self.chat_tag, kills_and_cost, (civs_killed <= (self.max_civilians / 2) and self.low_threat_color or civs_killed > (self.max_civilians / 2) and self.medium_threat_color)) end end end end end c:init() if RequiredScript == "lib/units/enemies/cop/copbrain" and _G["CopBrain"] then local orig_func_CopBrain = CopBrain.clbk_death function CopBrain:clbk_death(my_unit, damage_info, ...) local is_civilian = CopDamage.is_civilian(self._unit:base()._tweak_table) if c.toggle and is_civilian then c:register_player(damage_info) end orig_func_CopBrain(self, my_unit, damage_info, ...) end elseif RequiredScript == "lib/units/enemies/cop/huskcopbrain" and _G["HuskCopBrain"] then local orig_func_HuskCopBrain = HuskCopBrain.clbk_death function HuskCopBrain:clbk_death(my_unit, damage_info, ...) local is_civilian = CopDamage.is_civilian(self._unit:base()._tweak_table) if c.toggle and is_civilian then c:register_player(damage_info) end orig_func_HuskCopBrain(self, my_unit, damage_info, ...) end end