Advertisement
HR_Shaft

Hog NOS (Nitrous Oxide Boost) for Phasor v2+

Aug 7th, 2014
418
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 32.95 KB | None | 0 0
  1.     --[[
  2.         Creators: AelitePrime, H® Shaft, and H® Bugz
  3.         Script Name: Nitro Hogs Script
  4.         Website: http://phasorscripts.wordpress.com/
  5.         Xfire: eliteprime14789x, nervebooger2012, and hlnbugz
  6.         Included Scripts: Nuggetz sendconsoletext overload, and Vehicle Speed
  7.         Version: 1.0 Nitrous Oxide System (NOS)
  8.        
  9.         Note: *** Script is currently only compatible with Hog type vehicles.***
  10.        
  11.     ]]--
  12.  
  13. -- Script tables
  14. emergency_brake = {} -- Do not touch
  15. default_speed = {} -- Do not touch
  16. nos_boost = {} -- Do not touch
  17. nos_deceleration_rate = {} -- Do not touch
  18. nos_duration = {} -- Do not touch
  19. nos_fuel = {} -- Do not touch
  20. nos_fuel_decrease_rate = {} -- Do not touch
  21. pause_time = {} -- Do not touch
  22. nos_acceleration_rate = {} -- Do not touch
  23. engine_protection_overide = {} -- Do not touch
  24.  
  25. -- Player tables
  26. player_fuel = {} -- Do not touch
  27. count = {} -- Do not touch
  28. delay = {} -- Do not touch
  29. using = {} -- Do not touch
  30. nos = {} -- Do not touch
  31.  
  32. --[[
  33.  
  34. If you will be using this script for Halo CE you will need to add the name(s) of the map(s) you will be using to each of the tables you want to set values to.
  35. I made the script compatible with all maps but with no extra features which include: nos fuel, nos duration, pause time, emergency brake, nos deceleration rate, nos acceleration rate, and engine protection overide.
  36. The only features that are active is default speed, and nos boost. If you which to enable a feature for a map you will need to add it to the table like I said before. Here is an example:
  37.  
  38. table_name_here.    map_name_here   =   value_here  -- This is a generic example
  39. nos_boost.          coldsnap        =   15          -- This will set the nos boost for coldsnap to 15
  40.  
  41. I recommened you test out each map with this script and see how you like it. You will most likely need to do some teaky to the settings to your preference and game style that you want in yout server(s).
  42.  
  43. Note: *** Script is currently only compatible with Hog type vehicles.***
  44.  
  45. ]]--
  46.  
  47. -- Modify -- Modify -- Modify -- Modify -- Modify -- Modify -- Modify -- Modify -- Modify -- Modify -- Modify -- Modify --
  48.  
  49. -- If this is set to true then If the driver clicks their crouch button the vehicle will come to a complete stop.
  50. --                              Map:                        Boolean:
  51. emergency_brake.                beavercreek         =       nil -- battle creek
  52. emergency_brake.                bloodgulch          =       true
  53. emergency_brake.                boardingaction      =       nil
  54. emergency_brake.                carousel            =       nil -- derelict
  55. emergency_brake.                chillout            =       nil
  56. emergency_brake.                damnation           =       nil
  57. emergency_brake.                dangercanyon        =       true
  58. emergency_brake.                deathisland         =       true
  59. emergency_brake.                gephyrophobia       =       true
  60. emergency_brake.                hangemhigh          =       nil
  61. emergency_brake.                icefields           =       true
  62. emergency_brake.                infinity            =       true
  63. emergency_brake.                longest             =       nil
  64. emergency_brake.                prisoner            =       nil
  65. emergency_brake.                putput              =       nil -- chiron tl34
  66. emergency_brake.                ratrace             =       nil
  67. emergency_brake.                sidewinder          =       true   
  68. emergency_brake.                timberland          =       true       
  69. emergency_brake.                wizard              =       nil
  70.  
  71. -- Default boost speed of players in a vehicle (0 = normal speed)
  72. --                              Map:                        Speed:
  73. default_speed.                  beavercreek         =       0 -- battle creek
  74. default_speed.                  bloodgulch          =       0
  75. default_speed.                  boardingaction      =       0
  76. default_speed.                  carousel            =       0 -- derelict
  77. default_speed.                  chillout            =       0
  78. default_speed.                  damnation           =       0
  79. default_speed.                  dangercanyon        =       0
  80. default_speed.                  deathisland         =       0
  81. default_speed.                  gephyrophobia       =       0
  82. default_speed.                  hangemhigh          =       0
  83. default_speed.                  icefields           =       0
  84. default_speed.                  infinity            =       0
  85. default_speed.                  longest             =       0
  86. default_speed.                  prisoner            =       0
  87. default_speed.                  putput              =       0 -- chiron tl34
  88. default_speed.                  ratrace             =       0
  89. default_speed.                  sidewinder          =       0  
  90. default_speed.                  timberland          =       0
  91. default_speed.                  wizard              =       0
  92.  
  93. --[[
  94. Maximum NOS Boost a player will receive.
  95.     (0, 20) = Almost no Syncing issues
  96.     (20, 35) = Some Syncing issues, but not too bad.
  97.     (35, 50) = Syncing issues noticable but still drivable
  98.     (50, 75) = Syncing issues are barely bearable
  99.     >75 = Syncing issues are unbearable
  100. ]]--
  101. --                              Map:                        Speed:
  102. nos_boost.                      beavercreek         =       0 -- battle creek
  103. nos_boost.                      bloodgulch          =       20
  104. nos_boost.                      boardingaction      =       0
  105. nos_boost.                      carousel            =       0 -- derelict
  106. nos_boost.                      chillout            =       0
  107. nos_boost.                      damnation           =       0
  108. nos_boost.                      dangercanyon        =       13
  109. nos_boost.                      deathisland         =       20
  110. nos_boost.                      gephyrophobia       =       15
  111. nos_boost.                      hangemhigh          =       0
  112. nos_boost.                      icefields           =       12
  113. nos_boost.                      infinity            =       20
  114. nos_boost.                      longest             =       0
  115. nos_boost.                      prisoner            =       0
  116. nos_boost.                      putput              =       0 -- chiron tl34
  117. nos_boost.                      ratrace             =       0
  118. nos_boost.                      sidewinder          =       15 
  119. nos_boost.                      timberland          =       12
  120. nos_boost.                      wizard              =       0
  121.  
  122. -- Time NOS will last before it starts to decrease. To disable nos_duration make the time nil
  123. --                              Map:                        Time:
  124. nos_duration.                   beavercreek         =       nil -- battle creek
  125. nos_duration.                   bloodgulch          =       9
  126. nos_duration.                   boardingaction      =       nil
  127. nos_duration.                   carousel            =       nil -- derelict
  128. nos_duration.                   chillout            =       nil
  129. nos_duration.                   damnation           =       nil
  130. nos_duration.                   dangercanyon        =       9
  131. nos_duration.                   deathisland         =       9
  132. nos_duration.                   gephyrophobia       =       9
  133. nos_duration.                   hangemhigh          =       nil
  134. nos_duration.                   icefields           =       9
  135. nos_duration.                   infinity            =       9
  136. nos_duration.                   longest             =       nil
  137. nos_duration.                   prisoner            =       nil
  138. nos_duration.                   putput              =       nil -- chiron tl34
  139. nos_duration.                   ratrace             =       nil
  140. nos_duration.                   sidewinder          =       9
  141. nos_duration.                   timberland          =       9
  142. nos_duration.                   wizard              =       nil
  143.  
  144. -- Increments in which NOS will increase until the it reaches nos_boost or player stops it. If nil then player will go directly from default speed to nos boost.
  145. --                              Map:                        Rate per second:
  146. nos_acceleration_rate.          beavercreek         =       nil -- battle creek
  147. nos_acceleration_rate.          bloodgulch          =       nil
  148. nos_acceleration_rate.          boardingaction      =       nil
  149. nos_acceleration_rate.          carousel            =       nil -- derelict
  150. nos_acceleration_rate.          chillout            =       nil
  151. nos_acceleration_rate.          damnation           =       nil
  152. nos_acceleration_rate.          dangercanyon        =       5
  153. nos_acceleration_rate.          deathisland         =       5
  154. nos_acceleration_rate.          gephyrophobia       =       5
  155. nos_acceleration_rate.          hangemhigh          =       nil
  156. nos_acceleration_rate.          icefields           =       5
  157. nos_acceleration_rate.          infinity            =       5
  158. nos_acceleration_rate.          longest             =       nil
  159. nos_acceleration_rate.          prisoner            =       nil
  160. nos_acceleration_rate.          putput              =       nil -- chiron tl34
  161. nos_acceleration_rate.          ratrace             =       nil
  162. nos_acceleration_rate.          sidewinder          =       5
  163. nos_acceleration_rate.          timberland          =       5
  164. nos_acceleration_rate.          wizard              =       nil
  165.  
  166. -- Increments in which NOS will deplete. If set to nil then you will go directly from nos boost to default speed
  167. --                              Map:                        Rate per second:
  168. nos_deceleration_rate.          beavercreek         =       nil -- battle creek
  169. nos_deceleration_rate.          bloodgulch          =       nil
  170. nos_deceleration_rate.          boardingaction      =       nil
  171. nos_deceleration_rate.          carousel            =       nil -- derelict
  172. nos_deceleration_rate.          chillout            =       nil
  173. nos_deceleration_rate.          damnation           =       nil
  174. nos_deceleration_rate.          dangercanyon        =       nil
  175. nos_deceleration_rate.          deathisland         =       nil
  176. nos_deceleration_rate.          gephyrophobia       =       nil
  177. nos_deceleration_rate.          hangemhigh          =       nil
  178. nos_deceleration_rate.          icefields           =       nil
  179. nos_deceleration_rate.          infinity            =       nil
  180. nos_deceleration_rate.          longest             =       nil
  181. nos_deceleration_rate.          prisoner            =       nil
  182. nos_deceleration_rate.          putput              =       nil -- chiron tl34
  183. nos_deceleration_rate.          ratrace             =       nil
  184. nos_deceleration_rate.          sidewinder          =       nil
  185. nos_deceleration_rate.          timberland          =       nil
  186. nos_deceleration_rate.          wizard              =       nil
  187.  
  188. --[[
  189.     Amount of 'fuel' you have for NOS. Make nil to disable.
  190.     The amount of fuel wasted per nos ~ (nos_duration + (nos_boost/nos_deceleration_rate))*nos_fuel_decrease_rate
  191.     The equation will only work if each variable has an actual number and nos_deceleration ~= 0 and nos_fuel_decrease_rate ~= 0
  192. ]]--
  193. --                              Map:                        Speed:
  194. nos_fuel.                       beavercreek         =       nil -- battle creek
  195. nos_fuel.                       bloodgulch          =       100
  196. nos_fuel.                       boardingaction      =       nil
  197. nos_fuel.                       carousel            =       nil -- derelict
  198. nos_fuel.                       chillout            =       nil
  199. nos_fuel.                       damnation           =       nil
  200. nos_fuel.                       dangercanyon        =       100
  201. nos_fuel.                       deathisland         =       100
  202. nos_fuel.                       gephyrophobia       =       100
  203. nos_fuel.                       hangemhigh          =       nil
  204. nos_fuel.                       icefields           =       100
  205. nos_fuel.                       infinity            =       100
  206. nos_fuel.                       longest             =       nil
  207. nos_fuel.                       prisoner            =       nil
  208. nos_fuel.                       putput              =       nil -- chiron tl34
  209. nos_fuel.                       ratrace             =       nil
  210. nos_fuel.                       sidewinder          =       100
  211. nos_fuel.                       timberland          =       100
  212. nos_fuel.                       wizard              =       nil
  213.  
  214. --[[
  215.     Increments in which the NOS fuel will deplete. If nos fuel decrease_rate is x, then it will deplete x times each second.
  216.     If nos fuel is not nil, then you are required to set a value. If you do not a default value will be assigned when the script/game starts.
  217. ]]--
  218. --                              Map:                        Speed:
  219. nos_fuel_decrease_rate.         beavercreek         =       nil -- battle creek
  220. nos_fuel_decrease_rate.         bloodgulch          =       1
  221. nos_fuel_decrease_rate.         boardingaction      =       nil
  222. nos_fuel_decrease_rate.         carousel            =       nil -- derelict
  223. nos_fuel_decrease_rate.         chillout            =       nil
  224. nos_fuel_decrease_rate.         damnation           =       nil
  225. nos_fuel_decrease_rate.         dangercanyon        =       1
  226. nos_fuel_decrease_rate.         deathisland         =       1
  227. nos_fuel_decrease_rate.         gephyrophobia       =       1
  228. nos_fuel_decrease_rate.         hangemhigh          =       nil
  229. nos_fuel_decrease_rate.         icefields           =       1
  230. nos_fuel_decrease_rate.         infinity            =       1
  231. nos_fuel_decrease_rate.         longest             =       nil
  232. nos_fuel_decrease_rate.         prisoner            =       nil
  233. nos_fuel_decrease_rate.         putput              =       nil -- chiron tl34
  234. nos_fuel_decrease_rate.         ratrace             =       nil
  235. nos_fuel_decrease_rate.         sidewinder          =       1
  236. nos_fuel_decrease_rate.         timberland          =       1
  237. nos_fuel_decrease_rate.         wizard              =       nil
  238.  
  239. --[[
  240.     Amount of time before you are able to use NOS again after activating it. When you active NOS Boost this pause time will be assigned to a delay, and until the delay is out
  241.     the player will not be able to re-enabled nos.
  242. ]]--
  243. --                              Map:                        Time(In Seconds):
  244. pause_time.                     beavercreek         =       nil -- battle creek
  245. pause_time.                     bloodgulch          =       10
  246. pause_time.                     boardingaction      =       nil
  247. pause_time.                     carousel            =       nil -- derelict
  248. pause_time.                     chillout            =       nil
  249. pause_time.                     damnation           =       nil
  250. pause_time.                     dangercanyon        =       10
  251. pause_time.                     deathisland         =       10
  252. pause_time.                     gephyrophobia       =       10
  253. pause_time.                     hangemhigh          =       nil
  254. pause_time.                     icefields           =       10
  255. pause_time.                     infinity            =       10
  256. pause_time.                     longest             =       nil
  257. pause_time.                     prisoner            =       nil
  258. pause_time.                     putput              =       nil -- chiron tl34
  259. pause_time.                     ratrace             =       nil
  260. pause_time.                     sidewinder          =       10
  261. pause_time.                     timberland          =       10
  262. pause_time.                     wizard              =       nil
  263.  
  264.  
  265. --[[
  266.     For every second you use NOS, another second is added to the amount of time you will need to wait until you are able to use NOS.
  267.     This boolean will disable that feature if you want to.
  268. ]]--
  269. --                              Map:                        Time(In Seconds):
  270. engine_protection_overide.      beavercreek         =       nil -- battle creek
  271. engine_protection_overide.      bloodgulch          =       true
  272. engine_protection_overide.      boardingaction      =       nil
  273. engine_protection_overide.      carousel            =       nil -- derelict
  274. engine_protection_overide.      chillout            =       nil
  275. engine_protection_overide.      damnation           =       nil
  276. engine_protection_overide.      dangercanyon        =       true
  277. engine_protection_overide.      deathisland         =       true
  278. engine_protection_overide.      gephyrophobia       =       true
  279. engine_protection_overide.      hangemhigh          =       nil
  280. engine_protection_overide.      icefields           =       true
  281. engine_protection_overide.      infinity            =       true
  282. engine_protection_overide.      longest             =       nil
  283. engine_protection_overide.      prisoner            =       nil
  284. engine_protection_overide.      putput              =       nil -- chiron tl34
  285. engine_protection_overide.      ratrace             =       nil
  286. engine_protection_overide.      sidewinder          =       true
  287. engine_protection_overide.      timberland          =       true
  288. engine_protection_overide.      wizard              =       nil
  289.  
  290.  
  291. -- Do not modify -- Do not modify -- Do not modify -- Do not modify -- Do not modify -- Do not modify -- Do not modify --
  292.  
  293. player_speed = {}
  294. velocity_multiplier = 0.00645 -- do not touch unless you know what it does
  295. turning_value = 0.999 -- do not touch unless you know what it does
  296. turning_value_increment = 0.005 -- do not touch unless you know what it does
  297. turn_multiplier = 0.99 -- do not touch unless you know what it does
  298. speed_accurary = 10000  -- do not touch unless you know what it does
  299. map_name = "nil"
  300.  
  301.  
  302. function GetRequiredVersion()
  303.     return 200
  304. end
  305.  
  306. function OnScriptLoad(process, game, persistent)
  307.     -- retrieves map name
  308.     if game == "PC" then
  309.         map_name = readstring(0x698F21)
  310.     else
  311.         map_name = readstring(0x61D151)
  312.     end
  313.     -- Used when the map is not in the table
  314.     if map_name then
  315.         default_speed[map_name] = default_speed[map_name] or 0
  316.         nos_boost[map_name] = nos_boost[map_name] or 5
  317.         if nos_fuel[map_name] then
  318.             nos_fuel_decrease_rate[map_name] = nos_fuel_decrease_rate[map_name] or 1
  319.         end
  320.     end
  321.     -- Initialize the timers for the script
  322.     vehicletimer = registertimer(0, "VehicleSpeedTimer")
  323.     timer = registertimer(1000, "Timer")
  324. end
  325.  
  326. function OnScriptUnload()
  327.     -- Remove script timers
  328.     removetimer(timer)
  329.     removetimer(vehicletimer)
  330. end
  331.  
  332. function OnNewGame(map)
  333.     map_name = map
  334.     -- Used when the map is not in the table
  335.     default_speed[map_name] = default_speed[map_name] or 0
  336.     nos_boost[map_name] = nos_boost[map_name] or 5
  337.     if nos_fuel[map_name] then
  338.         nos_fuel_decrease_rate[map_name] = nos_fuel_decrease_rate[map_name] or 1
  339.     end
  340. end
  341.  
  342. function OnClientUpdate(player)
  343.     -- Detects when the player clicks their flashlight button (NOS Activator)
  344.     local m_playerObjId = getplayerobjectid(player)
  345.     if m_playerObjId and isinvehicle(player) then
  346.         local m_vehicle = getobject(getvehicleobjectid(player))
  347.         if getdriverplayer(m_vehicle) == player and readbit(getobject(m_playerObjId) + 0x208, 4) then
  348.             OnNosBoost(player, m_vehicle)
  349.         end
  350.     end
  351. end
  352.  
  353. function OnNosBoost(player, m_vehicle)
  354.     if checkfuel(player) then -- Checks if the player has any fuel left
  355.         if validvehicle(m_vehicle) then -- Checks if we are able to apply velocity to the vehicle
  356.             -- Determines what the activation does
  357.             if not nos[player] then
  358.                 if default_speed[map_name] == nos_boost[map_name] then
  359.                     sendconsoletext(player, "NOS is currently not available on this map.", 2, 3)
  360.                 elseif (delay[player] or 0) == 0 and getplayervehiclespeed(player) == default_speed[map_name] then
  361.                     nos[player] = true
  362.                     sendconsoletext(player, "NOS Boost!", 2, 3)
  363.                     sendconsoletext(getgunnerplayer(m_vehicle), "Driver has enabled NOS Boost!", 2, 4)
  364.                     if pause_time[map_name] then
  365.                         delay[player] = (pause_time[map_name])
  366.                     end
  367.                 elseif getplayervehiclespeed(player) ~= default_speed[map_name] then
  368.                     nos[player] = false
  369.                     sendconsoletext(player, "NOS Stopped!", 2, 8)
  370.                     sendconsoletext(getgunnerplayer(m_vehicle), "NOS Stopped!", 2, 9)
  371.                     setplayervehiclespeed(player, default_speed[map_name])
  372.                     count[player] = 0
  373.                     if engine_protection_overide[map_name] then
  374.                         delay[player] = (using[player])
  375.                         using[player] = 0
  376.                     end
  377.                 elseif (delay[player] or 0) > 0 then
  378.                     sendconsoletext(player, "Engine is about to overheat. NOS is not available.", 1, 5)
  379.                     if delay[player] > 1 then
  380.                         sendconsoletext(player, "Wait another " .. (delay[player] or 0) .. " seconds.", 1, 6)  
  381.                     else
  382.                         sendconsoletext(player, "Wait 1 more second.", 1, 7)  
  383.                     end
  384.                 end
  385.             else
  386.                 nos[player] = false
  387.                 sendconsoletext(player, "NOS Stopped!", 2, 8)
  388.                 sendconsoletext(getgunnerplayer(m_vehicle), "NOS Stopped!", 2, 9)
  389.                 setplayervehiclespeed(player, default_speed[map_name])
  390.                 count[player] = 0
  391.                 if engine_protection_overide[map_name] then
  392.                     delay[player] = (using[player])
  393.                     using[player] = 0
  394.                 end
  395.             end
  396.         else
  397.             sendconsoletext(player, "You are not in a valid vehicle. NOS is not available.", 1, 5)
  398.         end
  399.     else
  400.         sendconsoletext(player, "You are out of fuel. NOS is not available.", 1, 6)  
  401.     end
  402. end
  403.  
  404. function OnVehicleEntry(player, m_vehicleId, seat, mapId, relevant)
  405.     -- Sends the messages to the driver of the vehicle if it is a valid vehicle
  406.     if seat == 0 and validvehicle(getobject(m_vehicleId)) then
  407.         privatesay(player, "Press Flashlight button to activate/stop Nitro!")
  408.         privatesay(player, "Press Crouch Button for an emergency brake!")
  409.     end
  410.     return nil
  411. end
  412.  
  413. function OnVehicleEject(player, relevant)
  414.     local m_vehicle = getobject(getvehicleobjectid(player))
  415.     if  getdriverplayer(m_vehicle) == player then
  416.         -- Disables NOS and stops all velocity
  417.         nos[player] = false
  418.         writefloat(m_vehicle + 0x68, 0)
  419.         writefloat(m_vehicle + 0x6C, 0)
  420.     end
  421.     return nil
  422. end
  423.  
  424. function Timer(id, c)
  425.     for player=0,15 do
  426.         if getplayer(player) then
  427.             local player_speed = (getplayervehiclespeed(player) or 0)
  428.             if isinvehicle(player) then
  429.                 if checkfuel(player) then
  430.                     local bool = false
  431.                     if nos[player] then
  432.                         bool = true
  433.                         -- Count used for delay
  434.                         if engine_protection_overide[map_name] then
  435.                             using[player] = (using[player] or 0) + 1
  436.                         end
  437.                         -- Determines if NOS is increasing or decreasing
  438.                         if nos_duration[map_name] and (count[player] or 0) >= nos_duration[map_name] then
  439.                             nos[player] = false
  440.                         else
  441.                             -- Determines how to apply the speed
  442.                             if nos_acceleration_rate[map_name] then
  443.                                 local new_speed = player_speed+nos_acceleration_rate[map_name]
  444.                                 if new_speed < nos_boost[map_name] then
  445.                                     setplayervehiclespeed(player, new_speed)
  446.                                 else
  447.                                     setplayervehiclespeed(player, nos_boost[map_name])
  448.                                 end
  449.                             else
  450.                                 setplayervehiclespeed(player, nos_boost[map_name])
  451.                             end
  452.                             count[player] = (count[player] or 0) + 1
  453.                         end
  454.                     elseif not nos[player] and player_speed > default_speed[map_name] then
  455.                         bool = true
  456.                         nosDepleting(player)
  457.                     end
  458.                     if bool then
  459.                         -- Shows current fuel and boost
  460.                         if nos_fuel[map_name] then
  461.                             sendconsoletext(player, "Fuel: " .. (player_fuel[player] or nos_fuel[map_name]), nil, 2)
  462.                         end
  463.                         sendconsoletext(player, "Boost: " .. getplayervehiclespeed(player) - default_speed[map_name] .. "%", nil, 2)
  464.                     end
  465.                 end
  466.             elseif player_speed ~= default_speed[map_name] or nos[player] then
  467.                 -- Stops all NOS properties when player is not in a vehicle
  468.                 nos[player] = false
  469.                 if engine_protection_overide[map_name] then
  470.                     delay[player] = (using[player])
  471.                     using[player] = 0
  472.                 end
  473.                 setplayervehiclespeed(player, default_speed[map_name])
  474.                 count[player] = 0
  475.             end
  476.             -- delay depletion
  477.             if (delay[player] or 0) > 0 then delay[player] = delay[player] - 1 end
  478.         else
  479.             -- When the player slot is empty it sets everything back to default.
  480.             if count[player] ~= 0 then    
  481.                 count[player] = 0
  482.             end
  483.             if using[player] ~= 0 then
  484.                 using[player] = 0
  485.             end
  486.             if player_speed ~= default_speed[map_name] then
  487.                 setplayervehiclespeed(player, default_speed[map_name])
  488.             end
  489.             if nos[player] then
  490.                 nos[player] = false
  491.             end
  492.         end
  493.     end
  494.     return true
  495. end
  496.  
  497. function VehicleSpeedTimer(id, count)
  498.     for player=0,15 do
  499.         if getplayer(player) then
  500.             if isinvehicle(player) then
  501.                 local m_vehicleId = getvehicleobjectid(player)
  502.                 if m_vehicleId then
  503.                     local m_vehicle = getobject(m_vehicleId)
  504.                     if m_vehicle and getdriverplayer(m_vehicle) == player then
  505.                         if player_speed[player] == nil then player_speed[player] = (default_speed[map_name] or 0)/speed_accurary end
  506.                         local m_object = getobject(getplayerobjectid(player))
  507.                         if emergency_brake[map_name] and readbit(m_object + 0x208, 0) then -- Emergency brake, and crouch button
  508.                             -- Stops all velocity for x and y
  509.                             writefloat(m_vehicle + 0x68, 0)
  510.                             writefloat(m_vehicle + 0x6C, 0)
  511.                         elseif player_speed[player] ~= 0 then -- Only when player_speed is not 0
  512.                             writebit(m_vehicle + 0x10, 2, 0) -- Syncing issues
  513.                             writefloat(m_vehicle + 0x8C, readfloat(m_vehicle, 0x8C)*turn_multiplier) -- reduces pitch velocity for better handling
  514.                             writefloat(m_vehicle + 0x90, readfloat(m_vehicle, 0x90)*turn_multiplier) -- reduces yaw velocity for better handling
  515.                             writefloat(m_vehicle + 0x94, readfloat(m_vehicle, 0x94)*turn_multiplier) -- reduces roll velocity for better handling
  516.                             local obj_x_vel = readfloat(m_vehicle + 0x68)
  517.                             local obj_y_vel = readfloat(m_vehicle + 0x6C)
  518.                             -- Determines how to apply the velocity
  519.                             if readbit(m_object + 0x208, 1) then -- Space bar (brake)
  520.                                 writefloat(m_vehicle + 0x68, obj_x_vel-(obj_x_vel*(velocity_multiplier+player_speed[player]))) -- Reduce the x velocity
  521.                                 writefloat(m_vehicle + 0x6C, obj_y_vel-(obj_y_vel*(velocity_multiplier+player_speed[player]))) -- Reduce the y velocity
  522.                             else
  523.                                 writefloat(m_vehicle + 0x68, obj_x_vel+(obj_x_vel*(velocity_multiplier+player_speed[player]))) -- Increase the x velocity
  524.                                 writefloat(m_vehicle + 0x6C, obj_y_vel+(obj_y_vel*(velocity_multiplier+player_speed[player]))) -- Increase the y velocity
  525.                             end
  526.                             -- Reduce the pitch and roll when it is above a certain point(turning value).
  527.                             for i=0,2 do
  528.                                 local offset = 0x74 + 4*i
  529.                                 local value = readfloat(m_vehicle + offset)
  530.                                 if value > turning_value then
  531.                                     writefloat(m_vehicle + offset, value-turning_value_increment)
  532.                                 elseif value < -turning_value then
  533.                                     writefloat(m_vehicle + offset, value+turning_value_increment)
  534.                                 end
  535.                             end
  536.                         end
  537.                     end
  538.                 end
  539.             end
  540.         else
  541.             -- When the player slot is empty it sets everything back to default.
  542.             if player_speed[player] ~= (default_speed[map_name]  or 0)  then
  543.                 player_speed[player] = (default_speed[map_name]  or 0)
  544.             end
  545.             if nos_fuel[map_name] and player_fuel[player] ~= nos_fuel[map_name] then
  546.                 player_fuel[player] = nos_fuel[map_name]
  547.             end
  548.         end
  549.     end
  550.     return true
  551. end
  552.  
  553. function checkfuel(player)
  554.     -- Determines if the player has any fuel left.
  555.     if (count[player] or 0) > 0 and nos_fuel[map_name] then
  556.         if nos_fuel[map_name] and player_fuel[player] == nil then player_fuel[player] = nos_fuel[map_name] end
  557.         if player_fuel[player] and player_fuel[player] > 0 then
  558.             player_fuel[player] = player_fuel[player] - nos_fuel_decrease_rate[map_name]
  559.         end
  560.         if player_fuel[player] <= 0 then
  561.             sendconsoletext(player, "You are out of NOS for the game!")
  562.             setplayervehiclespeed(player, default_speed[map_name])
  563.             count[player] = 0
  564.             return false
  565.         end
  566.     end
  567.     return true
  568. end
  569.  
  570. function getdriverplayer(m_vehicle)
  571.     -- Retrieves driver player
  572.     local m_objectId = readdword(m_vehicle + 0x324)
  573.     if m_objectId and m_objectId ~= 0xFFFFFFFF then
  574.         return objectidtoplayer(m_objectId)
  575.     end
  576. end
  577.  
  578. function getgunnerplayer(m_vehicle)
  579.     -- Retrieves gunner player
  580.     local m_objectId = readdword(m_vehicle + 0x328)
  581.     if m_objectId and m_objectId ~= 0xFFFFFFFF then
  582.         return objectidtoplayer(m_objectId)
  583.     end
  584. end
  585.  
  586. function getplayerfuel(player)
  587.     -- Retrieves fuel of player
  588.    return (player_fuel[player] or nos_fuel[map_name])
  589. end
  590.  
  591. function getplayervehiclespeed(player)
  592.     -- Retrieves speed of player
  593.     return (player_speed[player] or default_speed[map_name])*speed_accurary
  594. end
  595.  
  596. function getvehicleobjectid(player)
  597.     -- Retrieves player m_vehicleId
  598.     local m_objectId = getplayerobjectid(player)
  599.     if m_objectId then
  600.         return readdword(getobject(m_objectId) + 0x11C)
  601.     end
  602. end
  603.  
  604. function nosDepleting(player)
  605.     -- Determines NOS depletion
  606.     sendconsoletext(player, "NOS depleting!")
  607.     if nos_deceleration_rate[map_name] then -- Used if rate is not nil
  608.         setplayervehiclespeed(player, getplayervehiclespeed(player) - (nos_deceleration_rate[map_name] or 0))
  609.     else -- Sets the speed to default if rate is nil
  610.         setplayervehiclespeed(player, default_speed[map_name])
  611.     end
  612.     if getplayervehiclespeed(player) <= default_speed[map_name] then
  613.         sendconsoletext(player, "NOS depleted! You are back to normal speed", 2)
  614.         sendconsoletext(getgunnerplayer(getobject(getvehicleobjectid(player))), "NOS depleted! You are back to normal speed", 2)
  615.         setplayervehiclespeed(player, default_speed[map_name])
  616.         count[player] = 0
  617.         if engine_protection_overide[map_name] then
  618.             delay[player] = (using[player])
  619.             using[player] = 0
  620.         end
  621.     end
  622. end
  623.  
  624. function setplayefuel(player, fuel)
  625.     -- Sets player fuel
  626.     if tonumber(fuel) then
  627.         player_fuel[player] = tonumber(fuel)
  628.     end
  629. end
  630.  
  631. function setplayervehiclespeed(player, speed)
  632.     -- Sets player speed
  633.     if tonumber(speed) then
  634.         player_speed[player] = tonumber(speed)/speed_accurary
  635.     end
  636. end
  637.  
  638. function round(input, precision) -- rounds the number to the specified decimal place
  639.     return math.floor((input * 10^(tonumber(precision) or 0) + 0.5)) / (10^(tonumber(precision) or 0))
  640. end
  641.  
  642. function validvehicle(m_vehicle)
  643.     -- Checks if it's a valid vehicle by checking if the name has 'hog' or 'puma' in the tag name.
  644.     -- It is a really stupid way to determinig it, but it is compatible with most CE maps this way.
  645.     local name = gettaginfo(readdword(m_vehicle))
  646.     if string.find(name, "hog") or string.find(name, "puma") then
  647.         return true
  648.     end
  649.     return false
  650. end
  651.  
  652. -- Start sendconsoletext overloaded
  653. console = {}
  654. console.__index = console
  655. registertimer(100, "ConsoleTimer")
  656. phasor_sendconsoletext = sendconsoletext
  657.  
  658. function sendconsoletext(player, message, time, order, align, height, func)
  659.     if player then
  660.         console[player] = console[player] or {}
  661.        
  662.         local temp = {}
  663.         temp.player = player
  664.         temp.id = nextid(player, order)
  665.         temp.message = message or ""
  666.         temp.time = time or 0.7
  667.         temp.remain = temp.time
  668.         temp.align = align or "left"
  669.         temp.height = height or 0
  670.        
  671.         if type(func) == "function" then
  672.             temp.func = func
  673.         elseif type(func) == "string" then
  674.             temp.func = _G[func]
  675.         end
  676.        
  677.         console[player][temp.id] = temp
  678.         setmetatable(console[player][temp.id], console)
  679.         return console[player][temp.id]
  680.     end
  681. end
  682.  
  683. function nextid(player, order)
  684.  
  685.     if not order then
  686.         local x = 0
  687.         for k,v in pairs(console[player]) do
  688.             if k > x + 1 then
  689.                 return x + 1
  690.             end
  691.            
  692.             x = x + 1
  693.         end
  694.        
  695.         return x + 1
  696.     else
  697.         local original = order
  698.         while console[player][order] do
  699.             order = order + 0.001
  700.             if order == original + 0.999 then break end
  701.         end
  702.        
  703.         return order
  704.     end
  705. end
  706.  
  707. function getmessage(player, order)
  708.  
  709.     if console[player] then
  710.         if order then
  711.             return console[player][order]
  712.         end
  713.     end
  714. end
  715.  
  716. function getmessages(player)
  717.  
  718.     return console[player]
  719. end
  720.  
  721. function getmessageblock(player, order)
  722.  
  723.     local temp = {}
  724.    
  725.     for k,v in opairs(console[player]) do
  726.         if k >= order and k < order + 1 then
  727.             table.insert(temp, console[player][k])
  728.         end
  729.     end
  730.    
  731.     return temp
  732. end
  733.  
  734. function console:getmessage()
  735.  
  736.     return self.message
  737. end
  738.  
  739. function console:append(message, reset)
  740.  
  741.     if console[self.player] then
  742.         if console[self.player][self.id] then
  743.             if getplayer(self.player) then
  744.                 if reset then
  745.                     if reset == true then
  746.                         console[self.player][self.id].remain = console[self.player][self.id].time
  747.                     elseif tonumber(reset) then
  748.                         console[self.player][self.id].time = tonumber(reset)
  749.                         console[self.player][self.id].remain = tonumber(reset)
  750.                     end
  751.                 end
  752.                
  753.                 console[self.player][self.id].message = message or ""
  754.                 return true
  755.             end
  756.         end
  757.     end
  758. end
  759.  
  760. function console:shift(order)
  761.  
  762.     local temp = console[self.player][self.id]
  763.     console[self.player][self.id] = console[self.player][order]
  764.     console[self.player][order] = temp
  765. end
  766.  
  767. function console:pause(time)
  768.  
  769.     console[self.player][self.id].pausetime = time or 5
  770. end
  771.  
  772. function console:delete()
  773.  
  774.     console[self.player][self.id] = nil
  775. end
  776.  
  777. function ConsoleTimer(id, count)
  778.  
  779.     for i,_ in opairs(console) do
  780.         if tonumber(i) then
  781.             if getplayer(i) then
  782.                 for k,v in opairs(console[i]) do
  783.                     if console[i][k].pausetime then
  784.                         console[i][k].pausetime = console[i][k].pausetime - 0.1
  785.                         if console[i][k].pausetime <= 0 then
  786.                             console[i][k].pausetime = nil
  787.                         end
  788.                     else
  789.                         if console[i][k].func then
  790.                             if not console[i][k].func(i) then
  791.                                 console[i][k] = nil
  792.                             end
  793.                         end
  794.                         if console[i][k] then
  795.                             console[i][k].remain = console[i][k].remain - 0.1
  796.                             if console[i][k].remain <= 0 then
  797.                                 console[i][k] = nil
  798.                             end
  799.                         end
  800.                     end
  801.                 end
  802.                 if table.len(console[i]) > 0 then
  803.                     local paused = 0
  804.                     for k,v in pairs(console[i]) do
  805.                         if console[i][k].pausetime then
  806.                             paused = paused + 1
  807.                         end
  808.                     end
  809.                     if paused < table.len(console[i]) then
  810.                         local str = ""
  811.                         for i = 0,30 do
  812.                             str = str .. " \n"
  813.                         end
  814.                         phasor_sendconsoletext(i, str)
  815.                         for k,v in opairs(console[i]) do
  816.                             if not console[i][k].pausetime then
  817.                                 if console[i][k].align == "right" or console[i][k].align == "center" then
  818.                                     phasor_sendconsoletext(i, consolecenter(string.sub(console[i][k].message, 1, 78)))
  819.                                 else
  820.                                     phasor_sendconsoletext(i, string.sub(console[i][k].message, 1, 78))
  821.                                 end
  822.                             end
  823.                         end
  824.                     end
  825.                 end
  826.             else
  827.                 console[i] = nil
  828.             end
  829.         end
  830.     end
  831.    
  832.     return true
  833. end
  834.  
  835. function consolecenter(text)
  836.     if text then
  837.         local len = string.len(text)
  838.         for i = len + 1, 78 do
  839.             text = " " .. text
  840.         end
  841.        
  842.         return text
  843.     end
  844. end
  845.  
  846. function opairs(t)
  847.    
  848.     local keys = {}
  849.     for k,v in pairs(t) do
  850.         table.insert(keys, k)
  851.     end    
  852.     table.sort(keys,
  853.     function(a,b)
  854.         if type(a) == "number" and type(b) == "number" then
  855.             return a < b
  856.         end
  857.         an = string.lower(tostring(a))
  858.         bn = string.lower(tostring(b))
  859.         if an ~= bn then
  860.             return an < bn
  861.         else
  862.             return tostring(a) < tostring(b)
  863.         end
  864.     end)
  865.     local count = 1
  866.     return function()
  867.         if table.unpack(keys) then
  868.             local key = keys[count]
  869.             local value = t[key]
  870.             count = count + 1
  871.             return key,value
  872.         end
  873.     end
  874. end
  875.  
  876. function table.len(t)
  877.  
  878.     local count = 0
  879.     for k,v in pairs(t) do
  880.         count = count + 1
  881.     end
  882.    
  883.     return count
  884. end
  885. -- Stop sendconsoletext overloaded
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement