Advertisement
Guest User

Donny

a guest
Sep 4th, 2009
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.54 KB | None | 0 0
  1. #include <a_samp>
  2. #include <zcmd>
  3.  
  4. #define IsKeyPressed(%1) ( newkeys & %1 ) && !( oldkeys & %1 )
  5. #define PLAYER_VELOCITY_KEY KEY_SPRINT
  6. #define VEHICLE_VELOCITY_KEY KEY_HANDBRAKE
  7.  
  8. new
  9. bool:gUseVelocity[ MAX_PLAYERS ] = { true, ... },
  10. gDirection[ MAX_PLAYERS ] = { 0, ... },
  11. Float:gPower[ MAX_PLAYERS ] = { 1.0, ... };
  12.  
  13. public OnPlayerConnect( playerid )
  14. {
  15. gUseVelocity[ playerid ] = true;
  16. gDirection[ playerid ] = 0;
  17. gPower[ playerid ] = 1.0;
  18. return 1;
  19. }
  20.  
  21. public OnPlayerDisconnect( playerid, reason )
  22. {
  23. gUseVelocity[ playerid ] = true;
  24. gDirection[ playerid ] = 0;
  25. gPower[ playerid ] = 1.0;
  26. return 1;
  27. }
  28.  
  29. forward zcmd_velocity( playerid, params[] );
  30. public zcmd_velocity( playerid, params[] )
  31. {
  32. gUseVelocity[ playerid ] = !gUseVelocity[ playerid ];
  33. if ( gUseVelocity[ playerid ] ) SendClientMessage( playerid, 0xffffffff, "Velocity feature enabled" );
  34. else SendClientMessage( playerid, 0xffffffff, "Velocity feature disabled" );
  35. return 1;
  36. }
  37.  
  38. forward zcmd_dir( playerid, params[] );
  39. public zcmd_dir( playerid, params[] )
  40. {
  41. if ( isnull( params ) )
  42. {
  43. gDirection[ playerid ] = 0;
  44. SendClientMessage( playerid, 0xffffffff, "Your direction is now set to forwards" );
  45. }
  46. else
  47. {
  48. switch ( strval( params ) )
  49. {
  50. case 1:
  51. {
  52. gDirection[ playerid ] = 1;
  53. SendClientMessage( playerid, 0xffffffff, "Your direction is now set to backwards" );
  54. }
  55. case 2:
  56. {
  57. gDirection[ playerid ] = 2;
  58. SendClientMessage( playerid, 0xffffffff, "Your direction is now set to left" );
  59. }
  60. case 3:
  61. {
  62. gDirection[ playerid ] = 3;
  63. SendClientMessage( playerid, 0xffffffff, "Your direction is now set to right" );
  64. }
  65. case 4:
  66. {
  67. gDirection[ playerid ] = 4;
  68. SendClientMessage( playerid, 0xffffffff, "Your direction is now set to up" );
  69. }
  70. case 5:
  71. {
  72. gDirection[ playerid ] = 5;
  73. SendClientMessage( playerid, 0xffffffff, "Your direction is now set to down" );
  74. }
  75. default:
  76. {
  77. gDirection[ playerid ] = 0;
  78. SendClientMessage( playerid, 0xffffffff, "Your direction is now set to forwards" );
  79. }
  80. }
  81. }
  82. return 1;
  83. }
  84.  
  85. forward zcmd_pow( playerid, params[] );
  86. public zcmd_pow( playerid, params[] )
  87. {
  88. if ( isnull( params ) )
  89. {
  90. gPower[ playerid ] = 1.0;
  91. SendClientMessage( playerid, 0xffffffff, "Your power is now set to 1.0" );
  92. }
  93. else
  94. {
  95. new
  96. string[ 128 ];
  97.  
  98. format( string, 128, "Your power is now set to %.4f", floatstr( params ) );
  99. SendClientMessage( playerid, 0xffffffff, string );
  100. gPower[ playerid ] = floatstr( params );
  101. }
  102. return 1;
  103. }
  104.  
  105. public OnPlayerKeyStateChange( playerid, newkeys, oldkeys )
  106. {
  107. if ( gUseVelocity[ playerid ] )
  108. {
  109. if ( IsKeyPressed( VEHICLE_VELOCITY_KEY ) )
  110. {
  111. if ( IsPlayerInAnyVehicle( playerid ) )
  112. {
  113. switch ( gDirection[ playerid ] )
  114. {
  115. case 0: AddVehicleVelocityDirection( GetPlayerVehicleID( playerid ), gPower[ playerid ] ); //forwards
  116. case 1: AddVehicleVelocityDirection( GetPlayerVehicleID( playerid ), -gPower[ playerid ] ); //backwards
  117. case 2: AddVehicleVelocityDirection( GetPlayerVehicleID( playerid ), -gPower[ playerid ], false ); //left
  118. case 3: AddVehicleVelocityDirection( GetPlayerVehicleID( playerid ), gPower[ playerid ], false ); //right
  119. case 4:
  120. {
  121. new
  122. Float:x,
  123. Float:y,
  124. Float:z;
  125.  
  126. GetVehicleVelocity( GetPlayerVehicleID( playerid ), x, y, z );
  127. SetVehicleVelocity( GetPlayerVehicleID( playerid ), x, y, z + gPower[ playerid ] ); //up
  128. }
  129. case 5:
  130. {
  131. new
  132. Float:x,
  133. Float:y,
  134. Float:z;
  135.  
  136. GetVehicleVelocity( GetPlayerVehicleID( playerid ), x, y, z );
  137. SetVehicleVelocity( GetPlayerVehicleID( playerid ), x, y, z - gPower[ playerid ] ); //down
  138. }
  139. default: AddVehicleVelocityDirection( GetPlayerVehicleID( playerid ), gPower[ playerid ] ); //forwards
  140. }
  141. }
  142. }
  143. else
  144. {
  145. if ( IsKeyPressed( PLAYER_VELOCITY_KEY ) )
  146. {
  147. if ( !IsPlayerInAnyVehicle( playerid ) )
  148. {
  149. switch ( gDirection[ playerid ] )
  150. {
  151. case 0: AddPlayerVelocityDirection( playerid, gPower[ playerid ] ); //forwards
  152. case 1: AddPlayerVelocityDirection( playerid, -gPower[ playerid ] ); //backwards
  153. case 2: AddPlayerVelocityDirection( playerid, -gPower[ playerid ], false ); //left
  154. case 3: AddPlayerVelocityDirection( playerid, gPower[ playerid ], false ); //right
  155. case 4:
  156. {
  157. new
  158. Float:x,
  159. Float:y,
  160. Float:z;
  161.  
  162. GetPlayerVelocity( playerid, x, y, z );
  163. SetPlayerVelocity( playerid, x, y, z + gPower[ playerid ] ); //up
  164. }
  165. case 5:
  166. {
  167. new
  168. Float:x,
  169. Float:y,
  170. Float:z;
  171.  
  172. GetPlayerVelocity( playerid, x, y, z );
  173. SetPlayerVelocity( playerid, x, y, z - gPower[ playerid ] ); //down
  174. }
  175. default: AddPlayerVelocityDirection( playerid, gPower[ playerid ] ); //forwards
  176. }
  177. }
  178. }
  179. }
  180. }
  181. return 1;
  182. }
  183.  
  184. AddVehicleVelocityDirection( vehicleid, Float:power = 1.0, bool:updown = true )
  185. {
  186. new
  187. Float:x,
  188. Float:y,
  189. Float:z,
  190. Float:angle;
  191.  
  192. GetVehicleVelocity( vehicleid, x, y, z );
  193. GetVehicleZAngle( vehicleid, angle );
  194.  
  195. switch ( updown )
  196. {
  197. case false : //left or right (use negative power for left)
  198. {
  199. x += ( power * floatcos( angle, degrees ) );
  200. y += ( power * floatsin( angle, degrees ) );
  201. }
  202. case true : //front or back (use negative power for backwards)
  203. {
  204. x += ( power * floatsin( -angle, degrees ) );
  205. y += ( power * floatcos( -angle, degrees ) );
  206. }
  207. }
  208.  
  209. SetVehicleVelocity( vehicleid, x, y, z );
  210. return true;
  211. }
  212.  
  213. AddPlayerVelocityDirection( playerid, Float:power = 1.0, bool:updown = true )
  214. {
  215. new
  216. Float:x,
  217. Float:y,
  218. Float:z,
  219. Float:angle;
  220.  
  221. GetPlayerVelocity( playerid, x, y, z );
  222. GetPlayerFacingAngle( playerid, angle );
  223.  
  224. switch ( updown )
  225. {
  226. case false : //left or right (use negative power for left)
  227. {
  228. x += ( power * floatcos( angle, degrees ) );
  229. y += ( power * floatsin( angle, degrees ) );
  230. }
  231. case true : //front or back (use negative power for backwards)
  232. {
  233. x += ( power * floatsin( -angle, degrees ) );
  234. y += ( power * floatcos( -angle, degrees ) );
  235. }
  236. }
  237.  
  238. SetPlayerVelocity( playerid, x, y, z );
  239. return true;
  240. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement