Advertisement
Combreal

AntiCamp.lua

Feb 8th, 2014
613
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.50 KB | None | 0 0
  1. --[[ Name : Anti-Camping
  2.          Version : 1.01
  3.          Created by : Idea by «§H»Kennan{Leader}, mostly wrote by Aelite Prime (Thanks both of them)
  4.                       Short modifications by combre
  5. ]]--
  6.  
  7. players = {}
  8. players.haveflag = nil
  9.  
  10. weapons = {}
  11.  
  12. coords = {}
  13. coords_to_move = 8 -- How many coords do they have to move in 30 seconds to be considered camping.
  14.                         -- If you walk in a stright line for 30 seconds, you can move around 30-40 coords.
  15.                         -- Also the radius of the circle they must get out of in 30 seconds before they are considered camping.
  16.                         -- Would want to make this smaller as the map gets small.
  17.  
  18. punishment = "move" -- What do you want to do to the "campers", methods :
  19.                      -- "kill"  : Kill them
  20.                      -- "hurt"  : Hurt them (20% of their health, on the 5th time, it will kill them)
  21.                      -- "moove" : Moove them back to teir spawn position
  22.  
  23.  
  24. -- Don't touch below this line --
  25. coords = {}
  26. countercamp = 0
  27.  
  28. function GetRequiredVersion()
  29.     return 200
  30. end
  31.  
  32. function OnScriptLoad(processId, game, persistent)
  33.     timer = registertimer(60000, "CoordCheck") -- 30000 or 30 sec, time between each coords checks
  34. end
  35.  
  36. function OnGameEnd(stage)
  37.     if stage == 1 then
  38.         removetimer(timer)
  39.     end
  40. end
  41.  
  42. function OnPlayerJoin(player)
  43.     coords[gethash(player)] = readfloat(getplayer(player) + 0xF8)
  44. end
  45.  
  46. function CoordCheck(id, count)
  47.     for player = 0,15 do
  48.         if getplayer(player) then
  49.             local hash = gethash(player)
  50.             local m_objectId = getplayerobjectid(player)
  51.             local x_diff = (coords[hash] + coords_to_move)
  52.             coords[hash] = readfloat(getplayer(player) + 0xF8)
  53.             if not isinvehicle(player) then
  54.                 if m_objectId and coords[hash] ~= nil and coords[hash] <= x_diff then
  55.                     if countercamp == 0 then
  56.                     countercamp = countercamp + 1
  57.                     privatesay(player, "You cannot stand here.")
  58.                     elseif countercamp == 1 then
  59.                         countercamp = countercamp + 1
  60.                         privatesay(player, "Last warning.")
  61.                     elseif countercamp == 2 and players[hash].haveflag == false then
  62.                             if punishment == "kill" then
  63.                                 countercamp = 0
  64.                                 kill(player)
  65.                                 privatesay(player, "You were killed for camping!")
  66.                             elseif punishment == "hurt" then
  67.                                 local m_object = getobject(m_objectId)
  68.                                 local health = readfloat(m_object + 0xE0)
  69.                                 if health <= 0.21 then
  70.                                     countercamp = 0
  71.                                     kill(player)
  72.                                     privatesay(player, "20% of your Health was damaged for camping, thus resulting in your death!")
  73.                                 else
  74.                                     countercamp = 0
  75.                                     writefloat(m_object + 0xE0, health - 0.20)
  76.                                     privatesay(player, "20% of your Health was damaged for camping!")
  77.                                 end
  78.                             elseif punishment == "move" then
  79.                                 if (m_objectId ~= nil) then
  80.                                     countercamp = 0
  81.                                     movobjectcoords(m_objectId, players[hash].spawns[1], players[hash].spawns[2], players[hash].spawns[3])
  82.                                     privatesay(player, "You were moved for camping!")
  83.                                 end
  84.                             end
  85.                     else
  86.                         countercamp = 0
  87.                         privatesay(player, "Stop camping...")
  88.                     end
  89.                 end
  90.             end
  91.         end
  92.     end
  93.     return true
  94. end
  95.  
  96. function OnPlayerSpawnEnd(player)
  97.     coords[gethash(player)] = readfloat(getplayer(player) + 0xF8)
  98.     local playerobjId = getplayerobjectid(player)
  99.     local x, y, z = getobjectcoords(playerobjId)
  100.     local hash = gethash(player)
  101.     players[hash] = players[hash] or {}
  102.     players[hash].spawns = players[hash].spawns or {}
  103.     players[hash].spawns[1] = x
  104.     players[hash].spawns[2] = y
  105.     players[hash].spawns[3] = z
  106.     players[hash].haveflag = false
  107. end
  108.  
  109. function OnWeaponPickup(player, weapId, slot, mapId)
  110.     local hash = gethash(player)
  111.     local tagname = gettaginfo(mapId)
  112.     if tagname == "weapons\\flag\\flag" then
  113.         players[hash].haveflag = true
  114.     end
  115. end
  116.  
  117. function OnWeaponDrop(player, weapId, slot, mapId)
  118.     local hash = gethash(player)
  119.     local tagname = gettaginfo(mapId)
  120.     if tagname == "weapons\\flag\\flag" then
  121.         players[hash].haveflag = false
  122.     end
  123. end
  124.  
  125. registertimer(10, "WeaponMonitor")
  126.  
  127. function WeaponMonitor(id, count)
  128.  
  129.     for player = 0,15 do
  130.         weapons[player] = weapons[player] or {}
  131.         local m_player = getplayer(player)
  132.         if m_player then
  133.             local temp = {} --?
  134.             local objId = readdword(m_player, 0x34)
  135.             local m_object = getobject(objId)
  136.             if m_object then
  137.                 for i = 0,3 do
  138.                     local weapId = readdword(m_object, 0x2F8 + (i * 4))
  139.                     local m_weapon = getobject(weapId)
  140.                     if m_weapon then
  141.                         local mapId = readdword(m_weapon)
  142.                         if weapons[player][i] then
  143.                             if weapons[player][i].weapId ~= weapId then
  144.                                 OnWeaponDrop(player, weapons[player][i].weapId, i, weapons[player][i].mapId)
  145.                                 weapons[player][i] = {}
  146.                                 weapons[player][i].weapId = weapId
  147.                                 weapons[player][i].mapId = mapId
  148.                                 OnWeaponPickup(player, weapId, i, mapId)
  149.                             end
  150.                         else
  151.                             weapons[player][i] = {}
  152.                             weapons[player][i].weapId = weapId
  153.                             weapons[player][i].mapId = mapId
  154.                             OnWeaponPickup(player, weapId, i, mapId)
  155.                         end
  156.                     else
  157.                         if weapons[player][i] then
  158.                             OnWeaponDrop(player, weapons[player][i].weapId, i, weapons[player][i].mapId)
  159.                             weapons[player][i] = nil
  160.                         end
  161.                     end
  162.                 end
  163.             else
  164.                 for i = 0,3 do
  165.                     if weapons[player][i] then
  166.                         OnWeaponDrop(player, weapons[player][i].weapId, i, weapons[player][i].mapId)
  167.                         weapons[player][i] = nil
  168.                     end
  169.                 end
  170.             end
  171.         end
  172.     end
  173.  
  174.     return true
  175. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement