util.AddNetworkString("hitman_msg") util.AddNetworkString("hitman_new") util.AddNetworkString("hitman_menu") local HIT_NOHITMEN = 1 local HIT_NOPLAYER = 2 local HIT_NILMONEY = 3 local HIT_ALREADY = 4 local HIT_CREATED = 5 local HIT_SUCCESS = 6 local function MatchName(ply, str) str = str or "" if (string.match( str, "STEAM_[0-5]:[0-9]:[0-9]+" )) then return ply:SteamID() == str elseif (string.Left(str, 1) == "'" and string.Right(str, 1) == "'") then --chat.AddText(color_white, string.sub(str, 2, #str - 1)) return (string.lower(ply:Nick()) == string.lower(string.sub(str, 2, #str - 1))) else return (string.lower(ply:Nick()) == string.lower(str) or string.find(string.lower(ply:Nick()), string.lower(str), nil, true)) end end local function FindPlayers(ply, name) local matches = {} for k, v in pairs(player.GetAll()) do if (MatchName(v, name)) then table.insert(matches, v) end end return matches end local function FindPlayer(ply, name) local matches = FindPlayers(ply, name) if(#matches > 1) then return false, true elseif(#matches == 1) then return matches[1] else return false, false end end AddChatCommand("/hit", function(ply, argstr) if(IsValid(ply)) then if(not argstr or #argstr <= 1 and (ply:Team() == TEAM_HITMAN or ply:Team() == TEAM_HITMANPLUS)) then net.Start("hitman_menu") net.Send(ply) else if(#team.GetPlayers(TEAM_HITMAN) <= 0 and #team.GetPlayers(TEAM_HITMANPLUS) <= 0) then net.Start("hitman_msg") net.WriteUInt(HIT_NOHITMEN, 3) net.Send(ply) return "" end local args = {} local arr = string.Explode(" ", argstr) if(not arr[2]) then arr[2] = 0 end args[2] = arr[#arr] table.remove(arr, #arr) args[1] = string.Implode(" ", arr) local target = FindPlayer(ply, args[1] or "") if(not IsValid(target) or ply == target or target:Team() == (TEAM_HITMAN or TEAM_HITMANPLUS)) then net.Start("hitman_msg") net.WriteUInt(HIT_NOPLAYER, 3) net.Send(ply) return "" end local amount = math.abs(tonumber(args[2]) or 0) if(amount < 250 or not ply:CanAfford(amount)) then net.Start("hitman_msg") net.WriteUInt(HIT_NILMONEY, 3) net.Send(ply) return "" end if(IsValid(target:GetNWEntity("HitOwner"))) then net.Start("hitman_msg") net.WriteUInt(HIT_ALREADY, 3) net.Send(ply) return "" end ply:AddMoney(-amount) target:SetNWInt("HitCost", amount) target:SetNWEntity("HitOwner", ply) net.Start("hitman_msg") net.WriteUInt(HIT_CREATED, 3) net.Send(ply) local hitcount = 0 for k, v in pairs(player.GetAll()) do if(IsValid(v:GetNWEntity("HitOwner"))) then hitcount = hitcount + 1 end end SetGlobalInt("HitCount", hitcount) timer.Simple(4, function() net.Start("hitman_new") net.Send(team.GetPlayers(TEAM_HITMAN)) net.Send(team.GetPlayers(TEAM_HITMANPLUS)) end) end end return "" end) hook.Add("EntityRemoved", "HITSYSTEM_PlayerLeave", function(ply) if(IsValid(ply) and ply:IsPlayer()) then for k, v in pairs(player.GetAll()) do if(IsValid(v:GetNWEntity("HitOwner")) and v:GetNWEntity("HitOwner") == ply) then v:SetNWEntity("HitOwner", NULL) ply:AddMoney(v:GetNWInt("HitCost")) end end if(IsValid(ply:GetNWEntity("HitOwner"))) then ply:GetNWEntity("HitOwner"):AddMoney(ply:GetNWEntity("HitCost")) ply:SetNWEntity("HitOwner", NULL) end local hitcount = 0 local old = GetGlobalInt("HitCount") for k, v in pairs(player.GetAll()) do if(IsValid(v:GetNWEntity("HitOwner"))) then hitcount = hitcount + 1 end end SetGlobalInt("HitCount", hitcount) if(old ~= hitcount) then timer.Simple(4, function() net.Start("hitman_new") net.Send(team.GetPlayers(TEAM_HITMAN and TEAM_HITMANPLUS)) end) end end end) hook.Add("PlayerDeath", "HITSYSTEM_PlayerDeath", function(ply, inf, kill) if(IsValid(ply) and IsValid(ply:GetNWEntity("HitOwner")) and kill:Team() == TEAM_HITMAN and TEAM_HITMANPLUS and ply:GetNWEntity("HitOwner") ~= kill) then kill:AddMoney(ply:GetNWInt("HitCost")) PrintMessage( HUD_PRINTTALK, "Hit Complete!" ) GAMEMODE:Notify(kill, 1, 4, "You have earned money for completing a hit!") net.Start("hitman_msg") net.WriteUInt(HIT_SUCCESS, 3) net.Send(ply:GetNWEntity("HitOwner")) else if(IsValid(ply:GetNWEntity("HitOwner"))) then ply:GetNWEntity("HitOwner"):AddMoney(ply:GetNWInt("HitCost")) net.Start("hitman_msg") net.WriteUInt(HIT_SUCCESS, 3) net.Send(ply:GetNWEntity("HitOwner")) end end ply:SetNWEntity("HitOwner", NULL) local hitcount = 0 local old = GetGlobalInt("HitCount") for k, v in pairs(player.GetAll()) do if(IsValid(v:GetNWEntity("HitOwner"))) then hitcount = hitcount + 1 end end SetGlobalInt("HitCount", hitcount) if(old ~= hitcount) then timer.Simple(4, function() net.Start("hitman_new") net.Send(team.GetPlayers(TEAM_HITMAN and TEAM_HITMANPLUS)) end) end end) hook.Add("OnPlayerChangeTeam", "HITMAN_TeamChange", function(ply, old, new) if(new == TEAM_HITMAN and TEAM_HITMANPLUS) then for k, v in pairs(player.GetAll()) do if(IsValid(v:GetNWEntity("HitOwner")) and v:GetNWEntity("HitOwner") == ply) then v:SetNWEntity("HitOwner", NULL) end end local hitcount = 0 local old = GetGlobalInt("HitCount") for k, v in pairs(player.GetAll()) do if(IsValid(v:GetNWEntity("HitOwner"))) then hitcount = hitcount + 1 end end SetGlobalInt("HitCount", hitcount) if(old ~= hitcount) then timer.Simple(4, function() net.Start("hitman_new") net.Send(team.GetPlayers(TEAM_HITMAN and TEAM_HITMANPLUS)) end) end end end)