Advertisement
sseebbyy

[VC:MP 0.4] Nitrous Oxide Systems - Real

Nov 20th, 2014
548
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.54 KB | None | 0 0
  1. /*
  2. [Smoother] Nitrous Oxide System for VC:MP 0.4 !
  3. All credits goes to Seby. (aka sseebbyy)
  4.  
  5. This system boost your car's speed and acceleration when you press ALT KEY. :)
  6. When a player uses NOS on car, the rear lights of car will become green !
  7. */
  8.  
  9. nosTimer <- null;
  10.  
  11. nosSpeedBoost <- 1.2; // the speed boost applied when NOS is enabled
  12. nosAcceleration <- 10; // how much will NOS increase the acceleration of car
  13. nosMaxSpeed <- 100; // how much will NOS increase the max speed of car
  14.  
  15. nosValueDuration <- 300; // DO NOT CHANGE IT without editing the code properly, and maybe editing the sprites too ! It sets the duration of nitro. Now it is 30 seconds.
  16. nosValueReloadingTime <- 60; // How much time you wait after using NOS (60 = 1 minute)
  17.  
  18. nosSecondsPassed <- array( 1000, 9 );
  19. nosEnabled <- array( 1000, 0 );
  20. nosDuration <- array( 1000, nosValueDuration );
  21. nosReloadingTime <- array( 1000, 0 );
  22.  
  23. nosUnit <- array( 10, null );
  24. nosUnitPosX <- array( 10, null );
  25. nosUnitAlpha <- array( 10, null );
  26. nosBarPosX <- -340; // nos bar pos X - you can change it however you want, all nos sprites will move too.
  27. nosBarPosY <- 230; // nos bar pos Y - you can change it however you want, all nos sprites will move too.
  28. nosBarAlpha <- 150; // it's the alpha of emty nos bar
  29. nosUnitDistance <- 25; // the distance between units
  30. nosUnitAlpha0 <- 50; // the unit's alpha 0, the one from left.
  31. nosUnitAlphaDifference <- 15; // how much alpha will take the next unit in plus
  32.  
  33. // =========================================== S E R V E R E V E N T S ==============================================
  34.  
  35. function onScriptLoad()
  36. {
  37. print("[Real] Nitrous Oxide System - by Seby - was loaded.");
  38. ALT_KEY <- BindKey(true, 0x12, 0, 0);
  39. nosLoadSprites();
  40. }
  41.  
  42. function onScriptUnload()
  43. {
  44. print("ERROR - Nitrous Oxide System - by Seby - was not loaded !!");
  45. }
  46.  
  47. // =========================================== B I N D E V E N T S ==============================================
  48.  
  49. function onKeyDown( player, key )
  50. {
  51. switch(key)
  52. {
  53. case ALT_KEY:
  54. if(player.Vehicle)
  55. {
  56. if( nosEnabled[player.Vehicle.ID] == 1 ) return;
  57. else
  58. {
  59. local veh = player.Vehicle,
  60. type = GetVehicleType( veh.Model );
  61. if(type == "Car")
  62. {
  63. if( nosReloadingTime[veh.ID] > time() ) MessagePlayer( "[#FF3636][NOS] [#FFFF36]You can use it once at every " + nosValueReloadingTime + " seconds !",player );
  64. else
  65. ActivateNOS( veh );
  66. }
  67. }
  68. }
  69. break;
  70.  
  71. default: break;
  72. }
  73. }
  74.  
  75. // =========================================== P L A Y E R E V E N T S ==============================================
  76.  
  77. function onPlayerEnterVehicle( player, vehicle, door )
  78. {
  79. if( nosEnabled[vehicle.ID] == 0 && nosReloadingTime[vehicle.ID] < time() ) nosSecondsPassed[vehicle.ID] = 9;
  80. nosShowBar( player );
  81. }
  82.  
  83. function onPlayerExitVehicle( player, vehicle )
  84. {
  85. nosHideBar( player );
  86. }
  87.  
  88. // ========================================== V E H I C L E E V E N T S =============================================
  89.  
  90. function onVehicleExplode( vehicle )
  91. {
  92. if(nosEnabled[vehicle.ID] == 1) DeactivateNOS( vehicle );
  93. }
  94.  
  95. function onVehicleRespawn( vehicle )
  96. {
  97. if(nosEnabled[vehicle.ID] == 1) DeactivateNOS( vehicle );
  98. }
  99.  
  100. // ================================== E N D OF O F F I C I A L E V E N T S ======================================
  101.  
  102. function GetVehicleType( model )
  103. {
  104. // by Force
  105. // Returns: Car / Bike / Heli / Plane / Boat / RC
  106. switch ( model ) {
  107. case 136:
  108. case 160:
  109. case 176:
  110. case 182:
  111. case 183:
  112. case 184:
  113. case 190:
  114. case 202:
  115. case 203:
  116. case 214:
  117. case 223:
  118. return "Boat";
  119. case 155:
  120. case 165:
  121. case 217:
  122. case 218:
  123. case 227:
  124. return "Heli";
  125. case 166:
  126. case 178:
  127. case 191:
  128. case 192:
  129. case 193:
  130. case 198:
  131. return "Bike";
  132. case 171:
  133. case 194:
  134. case 195:
  135. case 231:
  136. return "RC";
  137. case 180:
  138. case 181:
  139. return "Plane";
  140. default:
  141. return "Car";
  142. }
  143. }
  144.  
  145. function ActivateNOS( vehicle )
  146. {
  147. if(!vehicle) return;
  148. else
  149. {
  150. if(nosEnabled[vehicle.ID] == 0)
  151. {
  152. local type = GetVehicleType( vehicle.Model ),
  153. defaultMaxSpeed = vehicle.GetHandlingData(13),
  154. defaultAcceleration = vehicle.GetHandlingData(14);
  155.  
  156. if(type == "Car")
  157. {
  158. vehicle.SetHandlingData(13, defaultMaxSpeed+nosMaxSpeed); // increases MaxSpeed with 100
  159. vehicle.SetHandlingData(14, defaultAcceleration+nosAcceleration); // increases Acceleration with 10
  160. vehicle.Lights=true; // turns on the car's lights because the green of the rear lights can't happen without having lights on
  161. vehicle.SetHandlingData(30,-7); // makes the rear lights green
  162.  
  163. nosEnabled[vehicle.ID] = 1;
  164. nosDuration[vehicle.ID] = nosValueDuration;
  165. nosSecondsPassed[vehicle.ID] = 9;
  166.  
  167. if( vehicle.RelativeSpeed != Vector( 0, 0, 0 ) )
  168. vehicle.RelativeSpeed *= nosSpeedBoost;
  169.  
  170. PlaySound( vehicle.World, 65, vehicle.Pos );
  171. nosShowBar( vehicle.Driver );
  172. nosTimer = NewTimer( "DecreaseNOS", 3000, (nosValueDuration / 10) + 1, vehicle.ID );
  173. }
  174. }
  175. }
  176. }
  177.  
  178. function DeactivateNOS( vehicle )
  179. {
  180. if(!vehicle) return;
  181. else
  182. {
  183. if(nosEnabled[vehicle.ID] == 1)
  184. {
  185. local type = GetVehicleType( vehicle.Model );
  186.  
  187. if(type == "Car")
  188. {
  189. vehicle.ResetHandlingData(13); // resets the MaxSpeed
  190. vehicle.ResetHandlingData(14); // resets the Acceleration
  191. vehicle.Lights=false; // turns back the lights off
  192. vehicle.ResetHandlingData(30); // resets the lights color
  193.  
  194. nosEnabled[vehicle.ID] = 0;
  195. nosDuration[vehicle.ID] = 0;
  196.  
  197. nosReloadingTime[vehicle.ID] = time() + nosValueReloadingTime;
  198. nosTimer.Delete();
  199. }
  200. }
  201. }
  202. }
  203.  
  204. function DecreaseNOS( vehID )
  205. {
  206. if( FindVehicle( vehID ) )
  207. {
  208. if(nosEnabled[vehID] == 0) return;
  209. else
  210. {
  211. local veh = FindVehicle( vehID ),
  212. type = GetVehicleType( veh.Model );
  213.  
  214. if(type == "Car")
  215. {
  216. if( veh.Driver && nosUnit[nosSecondsPassed[vehID]] ) nosUnit[nosSecondsPassed[vehID]].HideFromPlayer( veh.Driver );
  217. if( nosSecondsPassed[vehID] != 0 ) nosSecondsPassed[vehID] -= 1;
  218.  
  219. if(nosDuration[vehID] != 0)
  220. {
  221. nosDuration[vehID] -= nosValueDuration / 10;
  222. }
  223. else
  224. {
  225. DeactivateNOS( veh );
  226. }
  227. }
  228. }
  229. }
  230. else return;
  231. }
  232.  
  233. function nosLoadSprites()
  234. {
  235. nosBar <- CreateSprite( "NOS_bar.png", nosBarPosX, nosBarPosY, 0, 0, 0, nosBarAlpha );
  236. for( local i = 0; i <= 9; i++ )
  237. {
  238. if(i == 0)
  239. {
  240. nosUnitAlpha[i] = nosUnitAlpha0;
  241. nosUnitPosX[i] = nosBarPosX + 13;
  242. nosUnit[i] = CreateSprite( "NOS_unit.png", nosUnitPosX[i], nosBarPosY, 0, 0, 0, nosUnitAlpha[i] );
  243. }
  244. else
  245. {
  246. nosUnitAlpha[i] = nosUnitAlpha[i-1] + nosUnitAlphaDifference;
  247. nosUnitPosX[i] = nosUnitPosX[i-1] + nosUnitDistance;
  248. nosUnit[i] = CreateSprite( "NOS_unit.png", nosUnitPosX[i], nosBarPosY, 0, 0, 0, nosUnitAlpha[i] );
  249. }
  250. }
  251. }
  252.  
  253. function nosShowBar( player )
  254. {
  255. if( player )
  256. {
  257. if(player.Vehicle)
  258. {
  259. local veh = player.Vehicle;
  260.  
  261. if( nosBar ) nosBar.ShowForPlayer( player );
  262. for( local i = 0; i <= nosSecondsPassed[veh.ID]; i++ )
  263. if( nosEnabled[veh.ID] == 1 )
  264. {
  265. if( nosUnit[i] ) nosUnit[i].ShowForPlayer( player );
  266. }
  267. else
  268. if( nosUnit[i] && nosReloadingTime[veh.ID] < time() ) nosUnit[i].ShowForPlayer( player );
  269. }
  270. }
  271. }
  272.  
  273. function nosHideBar( player )
  274. {
  275. if( player )
  276. {
  277. if( nosBar ) nosBar.HideFromPlayer( player );
  278. for( local i = 0; i <= 9; i++ )
  279. if( nosUnit[i] ) nosUnit[i].HideFromPlayer( player );
  280. }
  281. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement