SHARE
TWEET

Sapp Phantom Shot Detection

it300 Apr 3rd, 2015 (edited) 274 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Phantom Shot Detection for Sapp
  2. -- By: Skylace
  3.  
  4. -- Message the server will send when a player has phantomed .
  5. player_phantomed_msg_enabled = true -- Should the message be enabled
  6. player_phantomed = " has phantom shot!"
  7.  
  8. -- Message sent if a killer kills a victim with a phantom shot.
  9. phantom_kill_msg = "%s killed %s with a phantom shot!"
  10.  
  11. -- Times a player phantoms to get a warn message
  12. max_phantoms = 2
  13.  
  14. -- Times a player needs to get kills with phantoms to have an action taken.
  15. max_phantom_kills = 2
  16.  
  17. -- Action taken if max_phantoms is reached. Valid options = kick, ban, ipban, warn, and none.
  18. phantom_action = "warn" -- Only if they are phantom shooting.
  19. phantom_kill_action = "kick" -- If they get kills with phantom shooting.
  20.  
  21. -- Message if phantom_action is "warn"
  22. warn_msg = "Please stop phantom shooting!"
  23.  
  24. -- Do not touch anything below this unless you know what your doing
  25. api_version = "1.4.0.0"
  26. phantom = {}
  27. phantomcount = {}
  28. isphantomshooting = {}
  29. phantomkills = {}
  30.  
  31. function OnScriptLoad()
  32.         for i = 0,15 do
  33.                 phantom[i] = 0
  34.         end
  35.         register_callback(cb["EVENT_TICK"], "OnServerTick")
  36.         register_callback(cb['EVENT_DIE'], "OnPlayerDeath")
  37. end
  38.  
  39. function OnScriptUnload()
  40. end
  41.  
  42. function OnPlayerDeath(PlayerIndex, KillerIndex)
  43.         if KillerIndex ~= "-1" then
  44.                 local name = get_var(PlayerIndex, "$name")
  45.                 local kname = get_var(KillerIndex, "$name")
  46.                 if isphantomshooting[kname] then
  47.                         local msg = string.format(phantom_kill_msg, kname, name)
  48.                         say_all(msg)
  49.                         if phantomkills[kname] then
  50.                                 phantomkills[kname] = tonumber(phantomkills[kname]) + 1
  51.                                 if phantomkills[kname] >= max_phantom_kills then
  52.                                         takeaction(KillerIndex, phantom_kill_action, 1)
  53.                                 end
  54.                         else
  55.                                 phantomkills[kname] = 0
  56.                         end
  57.                 end
  58.         end
  59. end
  60.  
  61. function OnServerTick()
  62.         for i = 0,15 do
  63.                 local PlayerIndex = to_player_index(i)
  64.                 if player_alive(PlayerIndex) then
  65.                         local m_object = get_dynamic_player(PlayerIndex)
  66.                         if phantom[i] == 0 then
  67.                                 local melee_key = read_byte(m_object + 0x208)
  68.                                 if melee_key >= 0x80 then
  69.                                         local scoped = read_byte(m_object + 0x320)
  70.                                         if scoped ~= 255 then
  71.                                                 phantom[i] = 1
  72.                                                 local name = get_var(PlayerIndex, "$name")
  73.                                                 if not isphantomshooting[name] then
  74.                                                         isphantomshooting[name] = true
  75.                                                         timer(1500, "removeactivephantom", name) -- Time it takes for melee animation to end and time players have to phantom shoot.
  76.                                                 end
  77.                                         end
  78.                                 end
  79.                         elseif phantom[i] < 60 then
  80.                                 phantom[i] = phantom[i] + 1
  81.                                 local is_shooting = bit.band(read_byte(m_object + 0x209), 0x08)
  82.                                 if is_shooting ~= 0 then
  83.                                         local name = get_var(PlayerIndex, "$name")
  84.                                         if player_phantomed_msg_enabled then
  85.                                                 say_all_exempt(PlayerIndex, name .. player_phantomed)
  86.                                         end
  87.                                         if phantomcount[name] then
  88.                                                 phantomcount[name] = phantomcount[name] + 1
  89.                                                 if phantomcount[name] >= max_phantoms then
  90.                                                         takeaction(PlayerIndex, phantom_action, 0)
  91.                                                 end
  92.                                         else
  93.                                                 phantomcount[name] = 1
  94.                                         end
  95.                                         phantom[i] = 0
  96.                                 end
  97.                         else
  98.                                 phantom[i] = 0
  99.                         end
  100.                 end
  101.         end
  102. end
  103.  
  104. function say_all_exempt(ExemptPlayer, Message) -- Dont send this message to the ExemptPlayer
  105.         for i = 0,15 do
  106.                 local PlayerIndex = to_player_index(i)
  107.                 if player_present(PlayerIndex) then
  108.                         if PlayerIndex ~= ExemptPlayer then
  109.                                 say(PlayerIndex, Message)
  110.                         end
  111.                 end
  112.         end
  113. end
  114.  
  115. function takeaction(PlayerIndex, Action, Mode)
  116.         local name = get_var(PlayerIndex, "$name")
  117.         if Action == "kick" then
  118.                 execute_command("k " .. PlayerIndex ..  " 'Phantom Shooting'")
  119.         elseif Action == "ban" then
  120.                 execute_command("b " .. PlayerIndex ..  " 'Phantom Shooting'")
  121.         elseif Action == "ipban" then
  122.                 execute_command("ipban " .. PlayerIndex ..  " 'Phantom Shooting'")
  123.         elseif Action == "warn" then
  124.                 say(PlayerIndex, warn_msg)
  125.         end
  126.         phantomcount[name] = 0
  127.         if Mode == 1 then
  128.                 phantom[to_real_index(PlayerIndex)] = 0
  129.                 phantomkills[name] = 0
  130.         end
  131. end
  132.  
  133. function removeactivephantom(name)
  134.         if isphantomshooting[name] then
  135.                 isphantomshooting[name] = false
  136.         else
  137.                 isphantomshooting[name] = false
  138.         end
  139. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top