Advertisement
HR_Shaft

Hyperspace! for Phasor v2

Apr 19th, 2014
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 20.79 KB | None | 0 0
  1. --[[ ###  Hyperspace!  ###]]--
  2. --[[ ###  by H® Shaft  ###]]--
  3. --[[ ### for Phasor v2 ###]]--
  4.  
  5. -- enables players to hyperspace jump to random locations by pressing their flashlight key ('q' standard key), in or out of a vehicle
  6. -- All games: allows broad use of the entire map, not just spawn locations. Hyperspace coordinates are balanced for team games
  7. -- CTF and Oddball: Make a quick getaway!
  8. -- Natural danger: sometimes you will hyperspace and die (fall thru map, under vehicles, etc)
  9.  
  10. -- edit --
  11. hyper_limit = 3     --| Number of times a player may hyperspace jump during one life.
  12.  
  13. -- don't edit --
  14. hyperspace_coord = {}
  15. hyper_calls = {}
  16.  
  17. function GetRequiredVersion()
  18.     return 200
  19. end
  20.  
  21. function OnScriptLoad(process, game, persistent)
  22.     if game == "PC" then
  23.         GAME = "PC"
  24.         map_name = readstring(0x698F21)
  25.     elseif game == "CE" then
  26.         GAME = "CE"
  27.         map_name = readstring(0x61D151)
  28.     end
  29.     for i=0,15 do
  30.         if getplayer(i) then
  31.             hyper_calls[i] = 0
  32.         end
  33.     end    
  34.     LoadCoords()
  35. end
  36.  
  37. function OnNewGame(map)
  38.     if GAME == "PC" then
  39.         map_name = readstring(0x698F21)
  40.     elseif GAME == "CE" then
  41.         map_name = readstring(0x61D151)
  42.     end
  43.     for i=0,15 do
  44.         if getplayer(i) then
  45.             hyper_calls[i] = 0
  46.         end
  47.     end    
  48.     LoadCoords()
  49. end
  50.  
  51. function OnClientUpdate(player)
  52.     local m_playerObjId = getplayerobjectid(player)
  53.     if m_playerObjId and isinvehicle(player) then
  54.         local m_vehicleId = getvehicleobjectid(player)
  55.         if getdriverplayer(getobject(m_vehicleId)) == player and readbit(getobject(m_playerObjId) + 0x208, 4) then
  56.             if hyper_calls[player] < hyper_limit then
  57.                 OnHyperSpace(m_vehicleId)
  58.                 hyper_calls[player] = hyper_calls[player] + 1
  59.                 sendconsoletext(player, "Hyperspace!  You have " .. hyper_limit - hyper_calls[player] .. " hyperspace jumps remaining.")
  60.             else
  61.                 sendconsoletext(player, "You are out of hyperspace jumps for this life.")
  62.             end
  63.         end
  64.     elseif m_playerObjId and not isinvehicle(player) and readbit(getobject(m_playerObjId) + 0x208, 4) then
  65.         if hyper_calls[player] < hyper_limit then
  66.             OnHyperSpace(m_playerObjId)
  67.             hyper_calls[player] = hyper_calls[player] + 1
  68.             sendconsoletext(player, "Hyperspace!  You have " .. hyper_limit - hyper_calls[player] .. " hyperspace jumps remaining.")
  69.         else
  70.             sendconsoletext(player, "You are out of hyperspace jumps for this life.")          
  71.         end
  72.     end  
  73. end
  74.  
  75. function OnHyperSpace(m_objectId)
  76.     local coord = SelectHyperCoord()
  77.     if coord then
  78.         movobjectcoords(m_objectId, hyperspace_coord[coord][1], hyperspace_coord[coord][2], hyperspace_coord[coord][3])
  79.     end
  80. end
  81.  
  82. function SelectHyperCoord(arg)
  83.     local hypercount = #hyperspace_coord
  84.     if hypercount > 0 then
  85.         return getrandomnumber(1, hypercount+1)
  86.     end
  87.     return nil 
  88. end
  89.  
  90. function OnPlayerKill(killer, victim, mode)
  91.     if getplayer(victim) then
  92.         hyper_calls[victim] = 0
  93.     end
  94. end
  95.  
  96. function getvehicleobjectid(player)
  97.     local m_objectId = getplayerobjectid(player)
  98.     if m_objectId then return readdword(getobject(m_objectId) + 0x11C) end
  99. end
  100.  
  101. function getdriverplayer(m_vehicle)
  102.     local m_objectId = readdword(m_vehicle + 0x324)
  103.     if m_objectId ~= 0xFFFFFFFF then return objectidtoplayer(m_objectId) end
  104. end
  105.  
  106. function OnVehicleEntry(player, veh_id, seat, mapid, relevant)
  107.     if seat == 0 then
  108.         privatesay(player, "Driver: Press Flashlight Button to activate Hyperspace jump.")
  109.     end
  110.     return nil
  111. end
  112.  
  113. function OnPlayerJoin(player)
  114.     if getplayer(player) then
  115.         hyper_calls[player] = 0
  116.         sendconsoletext(player, "Press Flashlight Button to activate Hyperspace jump.", 6, 0)
  117.     end
  118. end
  119.  
  120. function OnServerChat(player, type, message)
  121.     local response = nil
  122.     -- use to add your own coordinates: type 'coord' to retrieve your xyz coordinates
  123.     -- returns your coordinates in or out of vehicle: x, y, z
  124.     if string.lower(message) == "coord" then
  125.         local m_playerObjId = getplayerobjectid(player)
  126.         if m_playerObjId then
  127.             if isinvehicle(player) then
  128.                 local m_vehicleId = readdword(getobject(m_playerObjId) + 0x11C)
  129.                 m_objectId = m_vehicleId
  130.             elseif m_playerObjId then
  131.                 m_objectId = m_playerObjId
  132.             end
  133.             if m_objectId then
  134.                 local x,y,z = getobjectcoords(m_objectId)          
  135.                 sendconsoletext(player, "X: " .. x .. " Y: " .. y .. " Z: " .. z, 15, 0)
  136.             end
  137.         end
  138.         response = true
  139.     end
  140.  
  141.     return response
  142. end
  143.  
  144. function LoadCoords()
  145.     if map_name == "bloodgulch" then
  146.         hyperspace_coord[1] = {27.765, -68.956, 0.814}
  147.         hyperspace_coord[2] = {78.675, -65.064, 5.124}
  148.         hyperspace_coord[3] = {71.056, -87.134, 5.934}
  149.         hyperspace_coord[4] = {24.034, -108.528, 2.814}
  150.         hyperspace_coord[5] = {68.872, -94.818, 1.934}
  151.         hyperspace_coord[6] = {95.161, -90.663, 5.414}
  152.         hyperspace_coord[7] = {104.015, -108.722, 2.014}
  153.         hyperspace_coord[8] = {99.938, -112.221, 4.484}
  154.         hyperspace_coord[9] = {75.196, -132.243, 0.224}
  155.         hyperspace_coord[10] = {46.746, -150.693, 4.664}
  156.         hyperspace_coord[11] = {62.088, -155.783, 6.094}
  157.         hyperspace_coord[12] = {115.724, -127.820, 1.904}
  158.         hyperspace_coord[13] = {125.209, -180.481, 6.514}
  159.         hyperspace_coord[14] = {78.985, -179.657, 1.854}
  160.         hyperspace_coord[15] = {58.753, -123.087, 0.554}   
  161.     elseif map_name == "dangercanyon" then
  162.         hyperspace_coord[1] = {34.736, -7.265, -0.776}
  163.         hyperspace_coord[2] = {51.490, 29.940, -9.556}
  164.         hyperspace_coord[3] = {27.078, 26.459, 0.454}
  165.         hyperspace_coord[4] = {21.222, 53.724, -8.886}
  166.         hyperspace_coord[5] = {4.750, 36.134, -7.886}
  167.         hyperspace_coord[6] = {-4.682, 47.397, -7.886}
  168.         hyperspace_coord[7] = {-26.567, 46.216, -9.516}
  169.         hyperspace_coord[8] = {-26.740, 26.168, 0.424}
  170.         hyperspace_coord[9] = {-58.930, 19.913, -9.046}
  171.         hyperspace_coord[10] = {-35.574, -7.524, -0.826}
  172.         hyperspace_coord[11] = {-0.095, 16.004, -0.480}
  173.         hyperspace_coord[12] = {-16.163, 20.354, 0.480}
  174.         hyperspace_coord[13] = {16.305, 20.547, 0.480}
  175.         hyperspace_coord[14] = {4.931, 33.303, 0.480}
  176.         hyperspace_coord[15] = {-4.972, 33.261, 0.480}
  177.         hyperspace_coord[16] = {-5.517, 54.629, 0.710}
  178.         hyperspace_coord[17] = {5.023, 55.362, 0.710}      
  179.     elseif map_name == "deathisland" then
  180.         hyperspace_coord[1] = {-33.178, -24.972, 10.068}
  181.         hyperspace_coord[2] = {-37.525, 21.940, 15.068}
  182.         hyperspace_coord[3] = {-75.184, 18.807, 2.218}
  183.         hyperspace_coord[4] = {-68.700, 19.106, 15.638}
  184.         hyperspace_coord[5] = {-30.180, 53.309, 11.168}
  185.         hyperspace_coord[6] = {-18.347, 35.498, 15.138}
  186.         hyperspace_coord[7] = {15.143, 44.042, 4.318}
  187.         hyperspace_coord[8] = {8.737, 28.474, 10.558}
  188.         hyperspace_coord[9] = {5.428, 10.959, 12.518}
  189.         hyperspace_coord[10] = {-28.905, 9.967, 23.038}
  190.         hyperspace_coord[11] = {-22.920, -28.805, 20.398}
  191.         hyperspace_coord[12] = {11.705, -20.327, 18.938}
  192.         hyperspace_coord[13] = {4.943, -28.034, 3.628}
  193.         hyperspace_coord[14] = {-23.681, -41.145, 8.318}
  194.         hyperspace_coord[15] = {43.185, -41.258, 2.678}
  195.         hyperspace_coord[16] = {43.238, -36.708, 13.958}
  196.         hyperspace_coord[17] = {35.804, -1.491, 9.388}
  197.         hyperspace_coord[18] = {33.087, 33.355, 7.898}
  198.         hyperspace_coord[19] = {18.616, 30.431, 18.388}
  199.         hyperspace_coord[20] = {8.155, -2.428, 20.878}
  200.         hyperspace_coord[21] = {40.705, 45.331, 3.418}
  201.         hyperspace_coord[22] = {34.775, 17.417, 5.378}
  202.         hyperspace_coord[23] = {-69.873, 12.690, 2.268}
  203.         hyperspace_coord[24] = {-29.030, -7.034, 5.938}
  204.     elseif map_name == "icefields" then
  205.         hyperspace_coord[1] = {22.750, 9.500, 1.3}
  206.         hyperspace_coord[2] = {-0.625, -0.458, 2.925}
  207.         hyperspace_coord[3] = {-22.699, 15.685, 9.275}
  208.         hyperspace_coord[4] = {-29.200, 49.053, 9.135}
  209.         hyperspace_coord[5] = {-52.994, 65.216, 2.705}
  210.         hyperspace_coord[6] = {-77.914, 54.044, 1.3}
  211.         hyperspace_coord[7] = {-45.024, 28.381, 1.3}
  212.         hyperspace_coord[8] = {-5.641, 36.686, 1.3}
  213.     elseif map_name == "gephyrophobia" then
  214.         hyperspace_coord[1] = {68.81, -110.08, -0.184}
  215.         hyperspace_coord[2] = {64.28, -74.03, -0.184}
  216.         hyperspace_coord[3] = {68.95, -39.61, -0.184}
  217.         hyperspace_coord[4] = {-19.89, -32.06, -0.184}
  218.         hyperspace_coord[5] = {-21.19, -78.55, -0.184}
  219.         hyperspace_coord[6] = {-21.34, -106.19, -0.184}    
  220.         hyperspace_coord[7] = {39.549, -69.047, -12.195}
  221.         hyperspace_coord[8] = {14.079, -74.159, -12.195}
  222.         hyperspace_coord[9] = {26.886, -72.053, 11.405}
  223.         hyperspace_coord[10] = {23.062, -40.741, -17.845}
  224.         hyperspace_coord[11] = {30.367, -105.614, -17.845}
  225.         hyperspace_coord[12] = {26.840, -72.365, -16.675}
  226.     elseif map_name == "infinity" then
  227.         hyperspace_coord[1] = {0.728, -165.882, 13.411}
  228.         hyperspace_coord[2] = {49.620, -138.104, 15.361}
  229.         hyperspace_coord[3] = {-42.124, -118.236, 14.071}
  230.         hyperspace_coord[4] = {-20.727, -63.191, 12.821}
  231.         hyperspace_coord[5] = {27.663, -66.958, 11.601}
  232.         hyperspace_coord[6] = {55.543, -0.009, 10.051}
  233.         hyperspace_coord[7] = {-1.968, 49.324, 10.121}
  234.         hyperspace_coord[8] = {-51.869, 4.706, 11.761}
  235.         hyperspace_coord[9] = {3.624, -41.338, 27.761}
  236.         hyperspace_coord[10] = {2.766, -84.036, 27.641}
  237.         hyperspace_coord[11] = {-0.536, -78.371, 13.781}
  238.         hyperspace_coord[12] = {22.859, -45.771, 14.38}
  239.     elseif map_name == "sidewinder" then
  240.         hyperspace_coord[1] = {-32.938, -13.044, -0.721}
  241.         hyperspace_coord[2] = {33.985, -12.170, -1.581}
  242.         hyperspace_coord[3] = {-0.321, 25.175, -3.651}
  243.         hyperspace_coord[4] = {-35.259, 10.442, -3.251}
  244.         hyperspace_coord[5] = {40.533, 11.924, -3.641}
  245.         hyperspace_coord[6] = {10.084, -12.067, 0.509}
  246.         hyperspace_coord[7] = {-4.426, -11.080, 0.509}
  247.         hyperspace_coord[8] = {-45.192, 39.458, 0.349}
  248.         hyperspace_coord[9] = {46.377, 39.846, 0.349}
  249.     elseif map_name == "timberland" then
  250.         hyperspace_coord[1] = {-38.672, 33.566, -19.331}
  251.         hyperspace_coord[2] = {32.380, 31.987, -20.941}
  252.         hyperspace_coord[3] = {25.598, 13.687, -20.681}
  253.         hyperspace_coord[4] = {-17.864, 12.050, -20.441}
  254.         hyperspace_coord[5] = {-24.920, -12.816, -20.441}
  255.         hyperspace_coord[6] = {21.240, -9.139, -20.671}
  256.         hyperspace_coord[7] = {39.357, -34.002, -19.341}
  257.         hyperspace_coord[8] = {-28.002, -30.099, -19.831}
  258.         hyperspace_coord[9] = {3.732, -15.392, -21.501}
  259.         hyperspace_coord[10] = {1.619, 16.556, -21.501}
  260.     elseif map_name == "beavercreek" then -- battle creek  
  261.         hyperspace_coord[1] = {16.984, 19.294, 5.364}
  262.         hyperspace_coord[2] = {10.970, 21.504, 3.104}
  263.         hyperspace_coord[3] = {6.433, 17.221, 3.224}
  264.         hyperspace_coord[4] = {6.429, 10.395, 3.224}
  265.         hyperspace_coord[5] = {-0.528, 18.334, -0.046}
  266.         hyperspace_coord[6] = {3.401, 9.412, -0.046}
  267.         hyperspace_coord[7] = {17.798, 5.751, 3.744}
  268.         hyperspace_coord[8] = {13.403, 6.129, 5.014}
  269.         hyperspace_coord[9] = {22.597, 16.795, 2.244}
  270.         hyperspace_coord[10] = {22.852, 10.768, 2.244}
  271.         hyperspace_coord[11] = {28.746, 8.869, -0.016}
  272.         hyperspace_coord[12] = {24.236, 18.087, -0.016}
  273.         hyperspace_coord[13] = {13.967, 14.560, -0.246}
  274.     elseif map_name == "boardingaction" then
  275.         hyperspace_coord[1] = {18.010, 19.843, 5.471}
  276.         hyperspace_coord[2] = {20.968, -10.919, 5.471}
  277.         hyperspace_coord[3] = {21.019, -3.501, 3.081}
  278.         hyperspace_coord[4] = {17.766, 14.506, 3.081}
  279.         hyperspace_coord[5] = {18.928, 18.882, -2.009}
  280.         hyperspace_coord[6] = {16.315, 0.910, -2.009}
  281.         hyperspace_coord[7] = {20.069, -19.093, -2.009}
  282.         hyperspace_coord[8] = {1.412, -19.032, -2.009}
  283.         hyperspace_coord[9] = {3.289, -0.977, -2.009}
  284.         hyperspace_coord[10] = {2.671, 16.779, -4.509}
  285.         hyperspace_coord[11] = {3.108, -13.714, -4.509}
  286.         hyperspace_coord[12] = {0.086, -10.078, 0.431}
  287.         hyperspace_coord[13] = {0.553, 14.843, 0.431}
  288.         hyperspace_coord[14] = {0.218, 18.366, 2.951}
  289.         hyperspace_coord[15] = {0.518, -14.468, 2.951}
  290.         hyperspace_coord[16] = {1.560, -19.892, 5.401}
  291.         hyperspace_coord[17] = {-1.495, 11.778, 5.401}
  292.     elseif map_name == "carousel" then -- derelict
  293.         hyperspace_coord[1] = {0.045, 0.460, -0.575}
  294.         hyperspace_coord[2] = {9.145, 0.269, -0.575}
  295.         hyperspace_coord[3] = {0.048, -8.718, -0.575}
  296.         hyperspace_coord[4] = {-9.010, -0.065, -0.575}
  297.         hyperspace_coord[5] = {-0.024, 8.831, -0.575}
  298.         hyperspace_coord[6] = {13.755, 5.636, -0.575}
  299.         hyperspace_coord[7] = {-13.835, -5.731, -0.575}
  300.         hyperspace_coord[8] = {0.012, -0.063, -2.395}
  301.         hyperspace_coord[9] = {0.009, -5.978, -2.395}
  302.         hyperspace_coord[10] = {5.951, -0.144, -2.395}
  303.         hyperspace_coord[11] = {0.055, 6.002, -2.395}
  304.         hyperspace_coord[12] = {-5.774, 0.020, -2.395}
  305.         hyperspace_coord[13] = {1.694, 13.831, -3.255}
  306.         hyperspace_coord[14] = {-1.822, -13.972, -3.255}
  307.     elseif map_name == "chillout" then
  308.         hyperspace_coord[1] = {1.512, 10.120, 0.861}
  309.         hyperspace_coord[2] = {-1.749, 11.100, 4.301}
  310.         hyperspace_coord[3] = {5.190, 12.174, 2.241}
  311.         hyperspace_coord[4] = {5.051, 7.015, 3.681}
  312.         hyperspace_coord[5] = {1.508, 4.784, 3.291}
  313.         hyperspace_coord[6] = {3.651, -0.384, 2.531}
  314.         hyperspace_coord[7] = {-0.944, -0.475, 2.901}
  315.         hyperspace_coord[8] = {1.463, -1.988, 0.111}
  316.         hyperspace_coord[9] = {9.715, 0.897, 0.111}
  317.         hyperspace_coord[10] = {8.550, 10.841, 0.111}
  318.         hyperspace_coord[11] = {-6.089, 1.016, 0.111}
  319.         hyperspace_coord[12] = {-9.279, 0.963, 1.781}
  320.         hyperspace_coord[13] = {-7.982, 6.448, 0.301}
  321.         hyperspace_coord[14] = {11.075, 3.795, 3.656}
  322.         hyperspace_coord[15] = {8.558, 1.047, 2.546}
  323.     elseif map_name == "damnation" then
  324.         hyperspace_coord[1] = {3.606, 7.521, 3.521}
  325.         hyperspace_coord[2] = {-7.431, 7.966, 3.521}
  326.         hyperspace_coord[3] = {-9.837, 1.488, -0.069}
  327.         hyperspace_coord[4] = {-1.893, -1.537, -0.069}
  328.         hyperspace_coord[5] = {2.431, 1.635, 0.171}
  329.         hyperspace_coord[6] = {-6.946, -6.078, 0.011}
  330.         hyperspace_coord[7] = {-5.797, -7.364, 3.591}
  331.         hyperspace_coord[8] = {5.887, 2.985, 3.591}
  332.         hyperspace_coord[9] = {1.126, -5.936, 3.591}
  333.         hyperspace_coord[10] = {7.188, -9.800, 4.611}
  334.         hyperspace_coord[11] = {9.843, -5.068, 6.821}
  335.         hyperspace_coord[12] = {-0.717, -0.966, 8.341}
  336.         hyperspace_coord[13] = {-6.386, 11.847, 3.531}
  337.         hyperspace_coord[14] = {1.300, 13.085, 1.471}
  338.     elseif map_name == "hangemhigh" then
  339.         hyperspace_coord[1] = {16.02, -7.17, -3.46}
  340.         hyperspace_coord[2] = {21.04, -1.80, -4.40}
  341.         hyperspace_coord[3] = {34.57, -5.06, -5.58}
  342.         hyperspace_coord[4] = {29.01, -16.60, -5.58}
  343.         hyperspace_coord[5] = {15.63, -18.05, -5.58}
  344.         hyperspace_coord[6] = {7.12, -21.80, -7.95}
  345.         hyperspace_coord[7] = {21.56, -2.44, -9.25}
  346.         hyperspace_coord[7] = {31.54, 11.73, -7.95}
  347.         hyperspace_coord[7] = {34.85, 14.85, -5.13}
  348.     elseif map_name == "longest" then
  349.         hyperspace_coord[1] = {-6.813, -9.464, 2.151}
  350.         hyperspace_coord[2] = {2.110, -10.611, 2.151}
  351.         hyperspace_coord[3] = {4.885, -19.451, 2.151}
  352.         hyperspace_coord[4] = {-3.831, -18.137, 2.151}
  353.         hyperspace_coord[5] = {-15.149, -10.811, 0.161}
  354.         hyperspace_coord[6] = {13.305, -18.204, 0.161}
  355.     elseif map_name == "prisoner" then
  356.         hyperspace_coord[1] = {-11.247, 3.474, 1.513}
  357.         hyperspace_coord[2] = {3.645, 4.985, 1.513}
  358.         hyperspace_coord[3] = {-9.275, 3.999, 3.363}
  359.         hyperspace_coord[4] = {9.139, -3.615, 3.363}
  360.         hyperspace_coord[5] = {-1.508, -0.147, 1.493}
  361.         hyperspace_coord[6] = {10.011, 3.252, -0.237}
  362.         hyperspace_coord[7] = {-9.109, 3.958, -0.237}  
  363.     elseif map_name == "putput" then -- chiron tl34
  364.         hyperspace_coord[1] = {33.424, -9.752, 1.503}
  365.         hyperspace_coord[2] = {-3.036, -5.018, 0.833}
  366.         hyperspace_coord[3] = {-3.162, -34.607, 3.573}
  367.         hyperspace_coord[4] = {13.607, -31.400, 2.923}
  368.         hyperspace_coord[5] = {14.796, -20.330, 0.293}
  369.     elseif map_name == "ratrace" then
  370.         hyperspace_coord[1] = {6.930, 2.812, -0.333}
  371.         hyperspace_coord[2] = {-7.843, -14.639, -2.013}
  372.         hyperspace_coord[3] = {20.718, 0.094, -1.963}
  373.         hyperspace_coord[4] = {2.537, -24.147, -3.453}
  374.         hyperspace_coord[5] = {11.573, -11.296, 0.357}
  375.         hyperspace_coord[6] = {-3.391, -13.534, 0.357}
  376.         hyperspace_coord[7] = {16.691, -19.692, -1.003}
  377.     elseif map_name == "wizard" then
  378.         hyperspace_coord[1] = {4.586, -5.058, -4.2}
  379.         hyperspace_coord[2] = {5.155, 4.820, -4.2}
  380.         hyperspace_coord[3] = {-4.733, 5.064, -4.2}
  381.         hyperspace_coord[4] = {-4.794, -4.913, -4.2}
  382.         hyperspace_coord[5] = {-9.209, -9.249, -2.3}
  383.         hyperspace_coord[6] = {9.270, 9.235, -2.3}
  384.     end
  385. end
  386.  
  387. -- Start sendconsoletext overloaded by Nugget
  388. console = {}
  389. console.__index = console
  390. consoletimer = registertimer(100, "ConsoleTimer")
  391. phasor_sendconsoletext = sendconsoletext
  392.  
  393. function sendconsoletext(player, message, time, order, align, height, func)
  394.     if player then
  395.         console[player] = console[player] or {}
  396.         local temp = {}
  397.         temp.player = player
  398.         temp.id = nextid(player, order)
  399.         temp.message = message or ""
  400.         temp.time = time or 0.7
  401.         temp.remain = temp.time
  402.         temp.align = align or "left"
  403.         temp.height = height or 0
  404.         if type(func) == "function" then
  405.             temp.func = func
  406.         elseif type(func) == "string" then
  407.             temp.func = _G[func]
  408.         end
  409.         console[player][temp.id] = temp
  410.         setmetatable(console[player][temp.id], console)
  411.         return console[player][temp.id]
  412.     end
  413. end
  414.  
  415. function nextid(player, order)
  416.     if not order then
  417.         local x = 0
  418.         for k,v in pairs(console[player]) do
  419.             if k > x + 1 then
  420.                 return x + 1
  421.             end
  422.            
  423.             x = x + 1
  424.         end
  425.         return x + 1
  426.     else
  427.         local original = order
  428.         while console[player][order] do
  429.             order = order + 0.001
  430.             if order == original + 0.999 then break end
  431.         end
  432.         return order
  433.     end
  434. end
  435.  
  436. function getmessage(player, order)
  437.     if console[player] then
  438.         if order then
  439.             return console[player][order]
  440.         end
  441.     end
  442. end
  443.  
  444. function getmessages(player)
  445.     return console[player]
  446. end
  447.  
  448. function getmessageblock(player, order)
  449.     local temp = {}
  450.     for k,v in opairs(console[player]) do
  451.         if k >= order and k < order + 1 then
  452.             table.insert(temp, console[player][k])
  453.         end
  454.     end
  455.     return temp
  456. end
  457.  
  458. function console:getmessage()
  459.     return self.message
  460. end
  461.  
  462. function console:append(message, reset)
  463.     if console[self.player] then
  464.         if console[self.player][self.id] then
  465.             if getplayer(self.player) then
  466.                 if reset then
  467.                     if reset == true then
  468.                         console[self.player][self.id].remain = console[self.player][self.id].time
  469.                     elseif tonumber(reset) then
  470.                         console[self.player][self.id].time = tonumber(reset)
  471.                         console[self.player][self.id].remain = tonumber(reset)
  472.                     end
  473.                 end
  474.                
  475.                 console[self.player][self.id].message = message or ""
  476.                 return true
  477.             end
  478.         end
  479.     end
  480. end
  481.  
  482. function console:shift(order)
  483.     local temp = console[self.player][self.id]
  484.     console[self.player][self.id] = console[self.player][order]
  485.     console[self.player][order] = temp
  486. end
  487.  
  488. function console:pause(time)
  489.     console[self.player][self.id].pausetime = time or 5
  490. end
  491.  
  492. function console:delete()
  493.     console[self.player][self.id] = nil
  494. end
  495.  
  496. function ConsoleTimer(id, count)
  497.     for i,_ in opairs(console) do
  498.         if tonumber(i) then
  499.             if getplayer(i) then
  500.                 for k,v in opairs(console[i]) do
  501.                     if console[i][k].pausetime then
  502.                         console[i][k].pausetime = console[i][k].pausetime - 0.1
  503.                         if console[i][k].pausetime <= 0 then
  504.                             console[i][k].pausetime = nil
  505.                         end
  506.                     else
  507.                         if console[i][k].func then
  508.                             if not console[i][k].func(i) then
  509.                                 console[i][k] = nil
  510.                             end
  511.                         end
  512.                         if console[i][k] then
  513.                             console[i][k].remain = console[i][k].remain - 0.1
  514.                             if console[i][k].remain <= 0 then
  515.                                 console[i][k] = nil
  516.                             end
  517.                         end
  518.                     end
  519.                 end
  520.                 if table.len(console[i]) > 0 then
  521.                     local paused = 0
  522.                     for k,v in pairs(console[i]) do
  523.                         if console[i][k].pausetime then
  524.                             paused = paused + 1
  525.                         end
  526.                     end
  527.                     if paused < table.len(console[i]) then
  528.                         local str = ""
  529.                         for i = 0,30 do
  530.                             str = str .. " \n"
  531.                         end
  532.                         phasor_sendconsoletext(i, str)
  533.                         for k,v in opairs(console[i]) do
  534.                             if not console[i][k].pausetime then
  535.                                 if console[i][k].align == "right" or console[i][k].align == "center" then
  536.                                     phasor_sendconsoletext(i, consolecenter(string.sub(console[i][k].message, 1, 78)))
  537.                                 else
  538.                                     phasor_sendconsoletext(i, string.sub(console[i][k].message, 1, 78))
  539.                                 end
  540.                             end
  541.                         end
  542.                     end
  543.                 end
  544.             else
  545.                 console[i] = nil
  546.             end
  547.         end
  548.     end
  549.     return true
  550. end
  551.  
  552. function consolecenter(text)
  553.     if text then
  554.         local len = string.len(text)
  555.         for i = len + 1, 78 do
  556.             text = " " .. text
  557.         end
  558.         return text
  559.     end
  560. end
  561.  
  562. function opairs(t)
  563.     local keys = {}
  564.     for k,v in pairs(t) do
  565.         table.insert(keys, k)
  566.     end    
  567.     table.sort(keys,
  568.     function(a,b)
  569.         if type(a) == "number" and type(b) == "number" then
  570.             return a < b
  571.         end
  572.         an = string.lower(tostring(a))
  573.         bn = string.lower(tostring(b))
  574.         if an ~= bn then
  575.             return an < bn
  576.         else
  577.             return tostring(a) < tostring(b)
  578.         end
  579.     end)
  580.     local count = 1
  581.     return function()
  582.         if table.unpack(keys) then
  583.             local key = keys[count]
  584.             local value = t[key]
  585.             count = count + 1
  586.             return key,value
  587.         end
  588.     end
  589. end
  590.  
  591. function table.len(t)
  592.     local count = 0
  593.     for k,v in pairs(t) do
  594.         count = count + 1
  595.     end
  596.     return count
  597. end
  598. -- Stop sendconsoletext overloaded 
  599.  
  600. -- Created by H® Shaft thank you to Oxide, AelitePrime, Nugget & Wizard.
  601. -- Visit http://halorace.org/forum/index.php?topic=514.0 or
  602. -- Visit http://pastebin.com/u/HR_Shaft for more phasor scripts
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement