Advertisement
Guest User

Vanter's vehicle control

a guest
Aug 14th, 2013
758
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. new Speedlimit[MAX_PLAYERS];
  2. #define SpeedCheck(%0,%1,%2,%3,%4) floatround(floatsqroot(%4?(%0*%0+%1*%1+%2*%2):(%0*%0+%1*%1) ) *%3*1.6)
  3. //Under OnGameModeInIt
  4. ManualVehicleEngineAndLights();
  5. //======================================Stocks=======================================//
  6.  
  7. //Vehicle speed
  8. stock GetVehicleSpeed(vehicleid, get3d)
  9. {
  10. new Float:x, Float:y, Float:z;
  11. GetVehicleVelocity(vehicleid, x, y, z);
  12. return SpeedCheck(x, y, z, 100.0, get3d);
  13. }
  14. stock ModifyVehicleSpeed(vehicleid,mph) //Miles Per Hour
  15. {
  16. new Float:Vx,Float:Vy,Float:Vz,Float:DV,Float:multiple;
  17. GetVehicleVelocity(vehicleid,Vx,Vy,Vz);
  18. DV = floatsqroot(Vx*Vx + Vy*Vy + Vz*Vz);
  19. if(DV > 0) //Directional velocity must be greater than 0 (display strobes if 0)
  20. {
  21. multiple = ((mph + DV * 100) / (DV * 100)); //Multiplying DV by 100 calculates speed in MPH
  22. return SetVehicleVelocity(vehicleid,Vx*multiple,Vy*multiple,Vz*multiple);
  23. }
  24. return 0;
  25. }
  26. //================================================Commands=============================================//
  27.  
  28. //------------------------------Vehicle commands------------------------------//
  29. CMD:speed(playerid, params[])
  30. {
  31. new string[128], speed;
  32. if(sscanf(params, "i", speed)) return SendClientMessage(playerid, COLOR_ERROR, "[USAGE] /speed (MPH)");
  33. if(speed < 0) return SendClientMessage(playerid, COLOR_RED, "[ERROR] invalid MPH speed.");
  34. Speedlimit[playerid] = speed;
  35. if(speed == 0) format(string, sizeof(string), "[VEHICLE] You have turned your speed limit off.", speed);
  36. else format(string, sizeof(string), "[VEHICLE] You have set your speed limit to %d MPH.", speed);
  37. SendClientMessage(playerid, COLOR_YELLOW, string);
  38. return 1;
  39. }
  40.  
  41. CMD:engine(playerid, params[])
  42. {
  43. #pragma unused params
  44. new vehicleid, engine,lights,alarm,doors,bonnet,boot,objective;
  45. vehicleid = GetPlayerVehicleID(playerid);
  46. GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
  47. if(!IsPlayerInAnyVehicle(playerid))
  48. return SendClientMessage(playerid, COLOR_RED, "[ERROR] You must be in a vehicle in order to use this command.");
  49. if(GetPlayerVehicleSeat(playerid) != 0)
  50. return SendClientMessage(playerid, COLOR_RED, "[ERROR] You must be in the driver seat in order to use this command.");
  51. if(engine == 1)
  52. {
  53. SetVehicleParamsEx(vehicleid,0,lights,alarm,doors,bonnet,boot,objective);
  54. SendClientMessage(playerid, COLOR_YELLOW, "[VEHICLE] Engine shut off.");
  55. }
  56. else
  57. {
  58. SetVehicleParamsEx(vehicleid,1,lights,alarm,doors,bonnet,boot,objective);
  59. SendClientMessage(playerid, COLOR_YELLOW, "[VEHICLE] Engine started.");
  60. }
  61. return 1;
  62. }
  63.  
  64. CMD:lights(playerid, params[])
  65. {
  66. #pragma unused params
  67. new vehicleid, engine,lights,alarm,doors,bonnet,boot,objective;
  68. vehicleid = GetPlayerVehicleID(playerid);
  69. GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
  70. if(!IsPlayerInAnyVehicle(playerid))
  71. return SendClientMessage(playerid, COLOR_RED, "[ERROR] You must be in a vehicle in order to use this command.");
  72. if(GetPlayerVehicleSeat(playerid) != 0)
  73. return SendClientMessage(playerid, COLOR_RED, "[ERROR] You must be in the driver seat in order to use this command.");
  74. if(lights == 1)
  75. {
  76. SetVehicleParamsEx(vehicleid,engine,0,alarm,doors,bonnet,boot,objective);
  77. SendClientMessage(playerid, COLOR_YELLOW, "[VEHICLE] lights turned off.");
  78. }
  79. else
  80. {
  81. SetVehicleParamsEx(vehicleid,engine,1,alarm,doors,bonnet,boot,objective);
  82. SendClientMessage(playerid, COLOR_YELLOW, "[VEHICLE] lights turned on.");
  83. }
  84. return 1;
  85. }
  86.  
  87. CMD:bonnet(playerid, params[])
  88. {
  89. #pragma unused params
  90. new vehicleid, engine,lights,alarm,doors,bonnet,boot,objective;
  91. vehicleid = GetPlayerVehicleID(playerid);
  92. GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
  93. if(!IsPlayerInAnyVehicle(playerid))
  94. return SendClientMessage(playerid, COLOR_RED, "[ERROR] You must be in a vehicle in order to use this command.");
  95. if(GetPlayerVehicleSeat(playerid) != 0)
  96. return SendClientMessage(playerid, COLOR_RED, "[ERROR] You must be in the driver seat in order to use this command.");
  97. if(bonnet == 1)
  98. {
  99. SetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,0,boot,objective);
  100. SendClientMessage(playerid, COLOR_YELLOW, "[VEHICLE] Bonnet closed.");
  101. }
  102. else
  103. {
  104. SetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,1,boot,objective);
  105. SendClientMessage(playerid, COLOR_YELLOW, "[VEHICLE] Bonnet opened.");
  106. }
  107. return 1;
  108. }
  109.  
  110. CMD:boot(playerid, params[])
  111. {
  112. #pragma unused params
  113. new vehicleid, engine,lights,alarm,doors,bonnet,boot,objective;
  114. vehicleid = GetPlayerVehicleID(playerid);
  115. GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
  116. if(!IsPlayerInAnyVehicle(playerid))
  117. return SendClientMessage(playerid, COLOR_RED, "[ERROR] You must be in a vehicle in order to use this command.");
  118. if(GetPlayerVehicleSeat(playerid) != 0)
  119. return SendClientMessage(playerid, COLOR_RED, "[ERROR] You must be in the driver seat in order to use this command.");
  120. if(boot == 1)
  121. {
  122. SetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,0,objective);
  123. SendClientMessage(playerid, COLOR_YELLOW, "[VEHICLE] Boot closed.");
  124. }
  125. else
  126. {
  127. SetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,1,objective);
  128. SendClientMessage(playerid, COLOR_YELLOW, "[VEHICLE] Boot opened.");
  129. }
  130. return 1;
  131. }
  132.  
  133. CMD:lock(playerid, params[])
  134. {
  135. #pragma unused params
  136. if(IsPlayerInAnyVehicle(playerid))
  137. {
  138. new State=GetPlayerState(playerid);
  139. if(State!=PLAYER_STATE_DRIVER)
  140. {
  141. SendClientMessage(playerid,COLOR_RED,"[ERROR] You must be in the driver's seat in order to use this command.");
  142. return 1;
  143. }
  144. new i;
  145. for(i=0;i<MAX_PLAYERS;i++)
  146. {
  147. if(i != playerid)
  148. {
  149. SetVehicleParamsForPlayer(GetPlayerVehicleID(playerid),i, 0, 1);
  150. }
  151. }
  152. SendClientMessage(playerid, COLOR_YELLOW, "[VEHICLE] Vehicle locked.");
  153. new Float:pX, Float:pY, Float:pZ;
  154. GetPlayerPos(playerid,pX,pY,pZ);
  155. PlayerPlaySound(playerid,1056,pX,pY,pZ);
  156. }
  157. else
  158. {
  159. SendClientMessage(playerid, COLOR_RED,"[ERROR] You must be in a vehicle in order to use this command.");
  160. }
  161. return 1;
  162. }
  163.  
  164. CMD:unlock(playerid, params[])
  165. {
  166. #pragma unused params
  167. if(IsPlayerInAnyVehicle(playerid))
  168. {
  169. new State=GetPlayerState(playerid);
  170. if(State!=PLAYER_STATE_DRIVER)
  171. {
  172. SendClientMessage(playerid,COLOR_RED,"[ERROR] You must be in the driver's seat in order to use this command.");
  173. return 1;
  174. }
  175. new i;
  176. for(i=0;i<MAX_PLAYERS;i++)
  177. {
  178. SetVehicleParamsForPlayer(GetPlayerVehicleID(playerid),i, 0, 0);
  179. }
  180. SendClientMessage(playerid, COLOR_YELLOW, "[VEHICLE] Vehicle unlocked.");
  181. new Float:pX, Float:pY, Float:pZ;
  182. GetPlayerPos(playerid,pX,pY,pZ);
  183. PlayerPlaySound(playerid,1057,pX,pY,pZ);
  184. }
  185. else
  186. {
  187. SendClientMessage(playerid, COLOR_RED,"[ERROR] You must be in a vehicle in order to use this command.");
  188. }
  189. return 1;
  190. }
  191. ///====================================================================================///
  192. //Under ONPlayerUpdate
  193.  
  194. if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER && Speedlimit[playerid])
  195. {
  196. new a, b, c;
  197. GetPlayerKeys(playerid, a, b ,c);
  198. if(a == 8 && GetVehicleSpeed(GetPlayerVehicleID(playerid), 0) > Speedlimit[playerid])
  199. {
  200. new newspeed = GetVehicleSpeed(GetPlayerVehicleID(playerid), 0) - Speedlimit[playerid];
  201. ModifyVehicleSpeed(GetPlayerVehicleID(playerid), -newspeed);
  202. }
  203. }
  204.  
  205. //Thank you
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement