117 lines
4.1 KiB
Lua
117 lines
4.1 KiB
Lua
local PLUGIN = PLUGIN
|
||
|
||
local groupToConfig = {
|
||
["sponsor"] = "killRewardSponsor",
|
||
["premium"] = "killRewardPremium",
|
||
["vip_plus"] = "killRewardVIPPlus",
|
||
["vip"] = "killRewardVIP",
|
||
["admin"] = "killRewardAdmin",
|
||
["st.admin"] = "killRewardAdmin",
|
||
["curator"] = "killRewardAdmin",
|
||
["projectteam"] = "killRewardAdmin",
|
||
["teh.admin"] = "killRewardAdmin",
|
||
["superadmin"] = "killRewardAdmin"
|
||
}
|
||
|
||
-- Прямой вывод в консоль при загрузке файла для проверки
|
||
print("[KillRewards] Server-side script loaded successfully!")
|
||
|
||
local function FormatMoney(amount, ply)
|
||
local amountVal = math.floor(math.abs(amount))
|
||
local formatted = tostring(amountVal):reverse():gsub("(%d%d%d)", "%1 "):reverse():gsub("^ ", "")
|
||
|
||
local char = ply:GetCharacter()
|
||
if (!char) then return formatted end
|
||
|
||
local faction = char:GetFaction()
|
||
|
||
-- Логика из F4 меню (cl_plugin.lua:29-38)
|
||
if (faction == _G.FACTION_UKRAINE) then
|
||
return formatted .. " валюты "
|
||
elseif (faction == _G.FACTION_RUSSIAN) then
|
||
return formatted .. " валюты "
|
||
end
|
||
|
||
return formatted
|
||
end
|
||
|
||
-- Используем PLUGIN:PlayerDeath вместо hook.Add для лучшей интеграции с Helix
|
||
function PLUGIN:PlayerDeath(victim, inflictor, attacker)
|
||
if (!IsValid(victim) or !victim:IsPlayer()) then return end
|
||
|
||
local victimChar = victim:GetCharacter()
|
||
if (!victimChar) then return end
|
||
|
||
-- Штраф за смерть (УДАЛЕНО: теперь штраф списывается в плагине death_screen при нажатии Пробела)
|
||
--[[
|
||
local deathPenalty = ix.config.Get("deathPenalty", 3000)
|
||
if (deathPenalty > 0) then
|
||
local money = victimChar:GetMoney()
|
||
local toTake = math.min(money, deathPenalty)
|
||
if (toTake > 0) then
|
||
victimChar:TakeMoney(toTake)
|
||
victim:NotifyLocalized("deathPenaltyMsg", FormatMoney(toTake, victim))
|
||
end
|
||
end
|
||
]]
|
||
|
||
-- Пытаемся найти реального игрока-убийцу
|
||
local killer = attacker
|
||
if (IsValid(killer)) then
|
||
if (killer.GetDriver and IsValid(killer:GetDriver())) then
|
||
killer = killer:GetDriver()
|
||
elseif (killer.lvsGetDriver and IsValid(killer:lvsGetDriver())) then
|
||
killer = killer:lvsGetDriver()
|
||
elseif (killer:IsVehicle() and killer.GetPassenger and IsValid(killer:GetPassenger(0))) then
|
||
killer = killer:GetPassenger(0)
|
||
elseif (IsValid(killer:GetOwner()) and killer:GetOwner():IsPlayer()) then
|
||
killer = killer:GetOwner()
|
||
elseif (killer.GetCreator and IsValid(killer:GetCreator()) and killer:GetCreator():IsPlayer()) then
|
||
killer = killer:GetCreator()
|
||
end
|
||
end
|
||
|
||
-- Если убийца не игрок или убил сам себя - выходим
|
||
if (!IsValid(killer) or !killer:IsPlayer() or killer == victim) then
|
||
return
|
||
end
|
||
|
||
local killerChar = killer:GetCharacter()
|
||
if (!killerChar) then return end
|
||
|
||
-- Отладочная инфа в консоль сервера (безопасное форматирование через tostring)
|
||
MsgC(Color(0, 255, 0), string.format("[KillRewards] %s (F:%s) killed %s (F:%s)\n",
|
||
tostring(killer:Nick()),
|
||
tostring(killerChar:GetFaction()),
|
||
tostring(victim:Nick()),
|
||
tostring(victimChar:GetFaction())
|
||
))
|
||
|
||
-- Сравнение фракций. В Helix GetFaction() может возвращать как число, так и строку (internal name)
|
||
if (tostring(killerChar:GetFaction()) != tostring(victimChar:GetFaction())) then
|
||
-- НАГРАДА
|
||
local group = killer:GetUserGroup()
|
||
local confKey = groupToConfig[group] or "killRewardBase"
|
||
local reward = ix.config.Get(confKey, 300)
|
||
|
||
killerChar:GiveMoney(reward)
|
||
killer:NotifyLocalized("killRewardMsg", FormatMoney(reward, killer))
|
||
|
||
ix.log.Add(killer, "playerKillReward", victim:Nick(), reward)
|
||
else
|
||
-- ШТРАФ (FF)
|
||
local penalty = ix.config.Get("friendlyFirePenalty", 5000)
|
||
if (penalty > 0) then
|
||
local money = killerChar:GetMoney()
|
||
local toTake = math.min(money, penalty)
|
||
|
||
if (toTake > 0) then
|
||
killerChar:TakeMoney(toTake)
|
||
killer:NotifyLocalized("killPenaltyMsg", FormatMoney(toTake, killer))
|
||
|
||
ix.log.Add(killer, "playerKillPenalty", victim:Nick(), toTake)
|
||
end
|
||
end
|
||
end
|
||
end
|