Advertisement
Guest User

Conquest 1.03

a guest
Jul 7th, 2012
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.57 KB | None | 0 0
  1. -- Conquest 1.03
  2.  
  3. -- Change these to whatever you want
  4. base_radius = 5.75 -- Radius of sphere (centered about the flag) of which players must be inside of to affect the control percentages
  5. red_starting_percent = 100 -- Amount of control Red Team has over their own base at the beginning of the game
  6. blue_starting_percent = 100 -- Amount of control Blue Team has over their own base at the beginning of the game
  7. red_max_percent = 100 -- Maximum amount of control Red Team can have over their own base
  8. blue_max_percent = 100 -- Maximum amount of control Blue Team can have over their own base
  9.  
  10. -- Don't mess with these
  11. red_base = {}
  12. blue_base = {}
  13. red_conquest = false
  14. blue_conquest = false
  15. red_base_contested = false
  16. blue_base_contested = false
  17. red_empty = true
  18. blue_empty = true
  19. red_percent = red_starting_percent
  20. blue_percent = blue_starting_percent
  21. messages = {}
  22. command_execute = false
  23.  
  24. function GetRequiredVersion()
  25.  
  26.     return 10057
  27. end
  28.  
  29. function OnScriptLoad(process)
  30.  
  31.  
  32. end
  33.  
  34. function OnScriptUnload()
  35.  
  36.    
  37. end
  38.  
  39. function OnNewGame(map)
  40.  
  41.     redzone = registertimer(10, "PlayersInRedZone")
  42.     bluezone = registertimer(10, "PlayersInBlueZone")
  43.     scoretimer = registertimer(500, "ScoreTimer")
  44. end
  45.  
  46. function OnGameEnd(mode)
  47.  
  48.     if mode == 1 then
  49.         removetimer(redzone)
  50.         removetimer(bluezone)
  51.     elseif mode == 2 then
  52.         removetimer(scoretimer)
  53.     end
  54. end
  55.  
  56. function OnServerChat(player, chattype, message)
  57.  
  58.     return 1
  59. end
  60.  
  61. function OnServerCommand(player, command)
  62.  
  63.     local hash = gethash(player)
  64.     if hash then
  65.         if not command_execute then
  66.             command_execute = true
  67.             local str = svcmd(command, player)
  68.             messages[hash].str = str
  69.             messages[hash].time = 10
  70.            
  71.             return 0
  72.         end
  73.     end
  74.    
  75.     command_execute = false
  76.    
  77.     return 1
  78. end
  79.  
  80. function OnTeamDecision(team)
  81.  
  82.     return team
  83. end
  84.  
  85. function OnPlayerJoin(player, team)
  86.  
  87.     local hash = gethash(player)
  88.     messages[hash] = {}
  89. end
  90.  
  91. function OnPlayerLeave(player, team)
  92.  
  93.     local hash = gethash(player)
  94.     messages[hash] = {}
  95. end
  96.  
  97. function OnPlayerKill(killer, victim, mode)
  98.  
  99.  
  100. end
  101.  
  102. function OnKillMultiplier(player, multiplier)
  103.  
  104.  
  105. end
  106.  
  107. function OnPlayerSpawn(player, m_objId)
  108.  
  109.  
  110. end
  111.  
  112. function OnPlayerSpawnEnd(player, m_objId)
  113.  
  114.  
  115. end
  116.  
  117. function OnTeamChange(relevant, player, cur_team, dest_team)
  118.  
  119.     return 1
  120. end
  121.  
  122. function OnObjectCreation(m_objId, player, tagName)
  123.  
  124.     if tagName == "weapons\\flag\\flag" then
  125.         local m_object = getobject(m_objId)
  126.         local team = readbyte(m_object, 0xB8)
  127.         if team == 0 then
  128.             red_base = pack(getobjectcoords(m_objId))
  129.         else
  130.             blue_base = pack(getobjectcoords(m_objId))
  131.         end
  132.     end
  133. end
  134.  
  135. function OnObjectInteraction(player, m_objId, tagType, tagName)
  136.  
  137.     if tagName == "weapons\\flag\\flag" then
  138.         return 0
  139.     end
  140.    
  141.     return 1
  142. end
  143.  
  144. function OnWeaponAssignment(player, m_objId, slot, tagName)
  145.  
  146.     return 0
  147. end
  148.  
  149. function OnWeaponReload(player, m_weapId)
  150.  
  151.     return 1
  152. end
  153.  
  154. function OnDamageLookup(receiver, causer, tagData, tagName)
  155.  
  156.  
  157. end
  158.  
  159. function OnVehicleEntry(relevant, player, m_vehicleId, tagName, seat)
  160.  
  161.     return 1
  162. end
  163.  
  164. function OnVehicleEject(player, forced)
  165.  
  166.     return 1
  167. end
  168.  
  169. function OnClientUpdate(player, m_objId)
  170.  
  171.  
  172. end
  173.  
  174. function pack(...)
  175.  
  176.     return {...}
  177. end
  178.  
  179. function inSphere(m_objId, x, y, z, r)
  180.  
  181.     local ox, oy, oz = getobjectcoords(m_objId)
  182.     local x_dist = x - ox
  183.     local y_dist = y - oy
  184.     local z_dist = z - oz
  185.     local dist = math.sqrt(x_dist ^ 2 + y_dist ^ 2 + z_dist ^ 2)
  186.     if dist <= r then
  187.         return true
  188.     end
  189. end
  190.  
  191. function PlayersInRedZone(id, count)
  192.  
  193.     local x, y, z = unpack(red_base)
  194.    
  195.     if x then
  196.         local reds = 0
  197.         local blues = 0
  198.         for i = 0,15 do
  199.             if gethash(i) then
  200.                 local team = getteam(i)
  201.                 local m_player = getplayer(i)
  202.                 local m_objId = readdword(m_player, 0x34)
  203.                 local m_object = getobject(m_objId)
  204.                 if m_object then
  205.                     if inSphere(m_objId, x, y, z, base_radius) then
  206.                         if team == 1 then
  207.                             blues = blues + 1
  208.                         else
  209.                             reds = reds + 1
  210.                         end
  211.                     end
  212.                 end
  213.             end
  214.         end
  215.        
  216.         if blues > 0 and reds == 0 then
  217.             blue_conquest = true
  218.             red_base_contested = false
  219.             red_empty = false
  220.             red_percent = red_percent - 0.05
  221.             if math.ceil(red_percent) <= 0 then
  222.                 red_percent = 0
  223.                 say("Blue Team wins!")
  224.                 svcmd("sv_map_next")
  225.                 return 0
  226.             end
  227.         elseif blues > 0 and reds > 0 then
  228.             blue_conquest = false
  229.             red_base_contested = true
  230.             red_empty = false
  231.         elseif reds > 0 and blues == 0 then
  232.             blue_conquest = false
  233.             red_base_contested = false
  234.             red_empty = false
  235.             if red_percent < red_max_percent then
  236.                 red_percent = red_percent + 0.05
  237.             else
  238.                 red_percent = red_max_percent
  239.             end
  240.         elseif reds == 0 and blues == 0 then
  241.             blue_conquest = false
  242.             red_base_contested = false
  243.             red_empty = true
  244.         end
  245.     end
  246.            
  247.     return 1
  248. end
  249.  
  250. function PlayersInBlueZone(id, count)
  251.  
  252.     local x, y, z = unpack(blue_base)
  253.    
  254.     if x then
  255.         local blues = 0
  256.         local reds = 0
  257.         for i = 0,15 do
  258.             if gethash(i) then
  259.                 local team = getteam(i)
  260.                 local m_player = getplayer(i)
  261.                 local m_objId = readdword(m_player, 0x34)
  262.                 local m_object = getobject(m_objId)
  263.                 if m_object then
  264.                     if inSphere(m_objId, x, y, z, base_radius) then
  265.                         if team == 0 then
  266.                             reds = reds + 1
  267.                         else
  268.                             blues = blues + 1
  269.                         end
  270.                     end
  271.                 end
  272.             end
  273.         end
  274.        
  275.         if reds > 0 and blues == 0 then
  276.             red_conquest = true
  277.             blue_base_contested = false
  278.             blue_empty = false
  279.             blue_percent = blue_percent - 0.05
  280.             if math.ceil(blue_percent) <= 0 then
  281.                 blue_percent = 0
  282.                 say("Red Team wins!")
  283.                 svcmd("sv_map_next")
  284.                 return 0
  285.             end
  286.         elseif reds > 0 and blues > 0 then
  287.             red_conquest = false
  288.             blue_base_contested = true
  289.             blue_empty = false
  290.         elseif blues > 0 and reds == 0 then
  291.             red_conquest = false
  292.             blue_base_contested = false
  293.             blue_empty = false
  294.             if blue_percent < blue_max_percent then
  295.                 blue_percent = blue_percent + 0.05
  296.             else
  297.                 blue_percent = blue_max_percent
  298.             end
  299.         elseif blues == 0 and reds == 0 then
  300.             red_conquest = false
  301.             blue_base_contested = false
  302.             blue_empty = true
  303.         end
  304.     end
  305.            
  306.     return 1
  307. end
  308.  
  309. function ScoreTimer(id, count)
  310.  
  311.     for i = 0,15 do
  312.         local hash = gethash(i)
  313.         if hash then
  314.             local newlines = ""
  315.             for x = 1,30 do
  316.                 newlines = newlines .. " \n"
  317.             end
  318.             hprintf(newlines, i)
  319.             local red_message = "Red Base Control: " .. math.round(red_percent, 2) .. "%"
  320.             local blue_message = "Blue Base Control: " .. math.round(blue_percent, 2) .. "%"
  321.             if blue_conquest then
  322.                 red_message = "- " .. red_message
  323.             end
  324.            
  325.             if red_conquest then
  326.                 blue_message = "- " .. blue_message
  327.             end
  328.            
  329.             if red_base_contested then
  330.                 red_message = red_message .. " (Contested)"
  331.             end
  332.            
  333.             if blue_base_contested then
  334.                 blue_message = blue_message .. " (Contested)"
  335.             end
  336.            
  337.             if not blue_conquest and not red_base_contested and red_percent < red_max_percent and not red_empty then
  338.                 red_message = "+ " .. red_message
  339.             end
  340.            
  341.             if not red_conquest and not blue_base_contested and blue_percent < blue_max_percent and not blue_empty then
  342.                 blue_message = "+ " .. blue_message
  343.             end
  344.            
  345.             if messages[hash].str then
  346.                 messages[hash].time = messages[hash].time - 0.5
  347.                 if messages[hash].time > 0 then
  348.                     hprintf(messages[hash].str, i)
  349.                 else
  350.                     messages[hash].str = nil
  351.                     messages[hash].time = nil
  352.                 end
  353.             end
  354.            
  355.             hprintf(red_message, i)
  356.             hprintf(blue_message, i)
  357.         end
  358.     end
  359.    
  360.     return 1
  361. end
  362.  
  363. function math.round(input, precision)
  364.  
  365.     return math.floor(input * (10 ^ precision) + 0.5) / (10 ^ precision)
  366. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement