Advertisement
Combreal

AntiVehicleCamp2.lua

Jan 29th, 2014
633
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.85 KB | None | 0 0
  1. -- For vehicle collision off - inspired from Eliteprime, Wizard, Shaft and Bugs's works --
  2.                         -- With the great help of A§H»Wizard --
  3.  
  4. playerRunoverCounter = {}
  5. playerIsHit = {}
  6. survives = 3  -- Number of times +1 the player will die before surviving by runovers
  7. eject = {}
  8.  
  9. function GetRequiredVersion()
  10.     return 200
  11. end
  12.  
  13.  
  14. function OnScriptLoad(processid, game, persistent)
  15.     first_timer  = registertimer(20, "IsEjectVehi")
  16. end
  17.  
  18. function OnDamageLookup(receiving, causing, mapId, tagdata)
  19.     if causing and receiving then
  20.         local c_player = objectidtoplayer(causing)
  21.         local r_player = objectidtoplayer(receiving)
  22.         if c_player and r_player and isinvehicle(c_player) then
  23.             if not isinvehicle(r_player) then
  24.                 local dmg = gettaginfo(mapId)
  25.                 if dmg == "globals\\vehicle_collision" then
  26.                     if not playerIsHit[r_player] then
  27.                         if not playerRunoverCounter[r_player] then playerRunoverCounter[r_player] = 0 end
  28.                         playerRunoverCounter[r_player] = playerRunoverCounter[r_player] + 1
  29.                         if playerRunoverCounter[r_player] >= survives then
  30.                             return false
  31.                         else
  32.                             playerIsHit[r_player] = true
  33.                             second_timer = registertimer(1000, "Alrdycrashed", r_player)
  34.                         end
  35.                     end
  36.                 end
  37.             end
  38.         end
  39.     end
  40.     return true
  41. end
  42.  
  43. function OnServerCommand(player, command)
  44.     local t = tokenizecmdstring(command)
  45.     local count = #t
  46.     if count > 0 then
  47.         if t[1] == "sv_ejectvehi" and count == 2 then
  48.             local player = t[2]
  49.             player = rresolveplayer(player)
  50.             if getplayer(player) then
  51.                 EjectVehi(player)
  52.                 return false
  53.             end
  54.         end
  55.     end
  56. end
  57.  
  58. function OnPlayerJoin(player)
  59.     eject[gethash(player)] = false
  60. end
  61.  
  62. function OnPlayerLeave(player)
  63.     eject[gethash(player)] = false
  64. end
  65.  
  66. function IsEjectVehi(id, count)
  67.     for player = 0, 15 do
  68.         if getplayer(player) then
  69.             if eject[gethash(player)] == true then
  70.                 if player and isinvehicle(player) then
  71.                     exitvehicle(player)
  72.                     eject[gethash(player)] = false
  73.                 end
  74.             end
  75.         end
  76.     end
  77.     return true
  78. end
  79.  
  80. function EjectVehi(player)
  81.     if eject[gethash(player)] ~= nil then
  82.         if eject[gethash(player)] ~= true then
  83.             eject[gethash(player)] = true
  84.             sendconsoletext(player, "You have been ejected from your vehicle, stop camping!")
  85.         end
  86.     end
  87. end
  88.  
  89. function OnGameEnd(stage)
  90.     if stage == 1 then
  91.         if first_timer then
  92.             removetimer(first_timer)
  93.         end
  94.         if second_timer then
  95.             removetimer(second_timer)
  96.         end
  97.         for player = 0, 15 do
  98.             if getplayer(player) then
  99.                 eject[gethash(player)] = false
  100.                 playerIsHit[player] = false
  101.                 playerRunoverCounter[player] = false
  102.             end
  103.         end
  104.     end
  105. end
  106.  
  107. function getplayervehicleid(player)
  108.     local m_objectId = getplayerobjectid(player)
  109.     if m_objectId then return readdword(getobject(m_objectId) + 0x11C) end
  110. end
  111.  
  112.  
  113. function Alrdycrashed(id, count, player)
  114.     playerIsHit[player] = nil
  115.     return false
  116. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement