Advertisement
adri1

Simple Physics example

Oct 31st, 2015
677
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.81 KB | None | 0 0
  1.  
  2. //Experimental FS by adri1
  3. //==============================================================================
  4.  
  5. #include <a_samp>
  6. #include <zcmd>
  7. #include <sscanf2>
  8.  
  9. new ob, st, count, rotob, angleob,
  10. Float:Vel = 10.0, Float:angle = 0.0, Float:rotation = 0.0, Float:gravity = 9.8,
  11. Float:VelX, Float:VelY,
  12. Text:TDEditor_TD;
  13.  
  14. #define INITIAL_X 0.0
  15. #define INITIAL_Y 0.0
  16. #define INITIAL_Z 50.0
  17.  
  18. public OnFilterScriptInit()
  19. {
  20. ob = CreateObject(1946, INITIAL_X, INITIAL_Y, INITIAL_Z, 0.00000, 0.00000, 0.00000, 1000.0);
  21. CreateObject(19757, 0.00000, 0.00000, 50.00000, 0.00000, 0.00000, 0.00000, 1000.0);
  22. CreateObject(19757, 0.00000, 0.00000, 50.00000, 90.00000, 0.00000, 0.00000, 1000.0);
  23. CreateObject(19757, 0.00000, 0.00000, 50.00000, 90.00000, 90.00000, 0.00000, 1000.0);
  24.  
  25. SetObjectMaterial(CreateObject(18981, 0.00000, 0.00000, 5.00000, 0.00000, 90.00000, 0.00000, 1000.0), 0, 18646, "matcolours", "yellow");
  26. CreateObject(18981, 25.00000, 0.00000, 5.00000, 0.00000, 90.00000, 0.00000, 1000.0);
  27. CreateObject(18981, 0.00000, 25.00000, 5.00000, 0.00000, 90.00000, 0.00000, 1000.0);
  28. CreateObject(18981, 0.00000, -25.00000, 5.00000, 0.00000, 90.00000, 0.00000, 1000.0);
  29. CreateObject(18981, -25.00000, 0.00000, 5.00000, 0.00000, 90.00000, 0.00000, 1000.0);
  30. SetObjectMaterial(CreateObject(18981, 25.00000, 25.00000, 5.00000, 0.00000, 90.00000, 0.00000, 1000.0), 0, 18646, "matcolours", "yellow");
  31. SetObjectMaterial(CreateObject(18981, -25.00000, 25.00000, 5.00000, 0.00000, 90.00000, 0.00000, 1000.0), 0, 18646, "matcolours", "yellow");
  32. SetObjectMaterial(CreateObject(18981, 25.00000, -25.00000, 5.00000, 0.00000, 90.00000, 0.00000, 1000.0), 0, 18646, "matcolours", "yellow");
  33. SetObjectMaterial(CreateObject(18981, -25.00000, -25.00000, 5.00000, 0.00000, 90.00000, 0.00000, 1000.0), 0, 18646, "matcolours", "yellow");
  34.  
  35. rotob = CreateObject(1946, 0.00000, 0.00000, 52.00000, 0.00000, 0.00000, 0.00000, 1000.0);
  36. AttachObjectToObject(CreateObject(19130, 0.00000, 0.00000, 52.00000, 0.00000, 0.00000, 0.00000, 1000.0), rotob, 0.0, 0.5, 0.0, 0.0, 90.0, -90.0, true);
  37.  
  38. angleob = CreateObject(18644, 0.00000, 0.00000, 50.00000, 90-0.00000, 0.00000, 0.00000, 1000.0);
  39. AttachObjectToObject(CreateObject(19130, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1000.0), angleob, 0.0, 0.5, 0.0, 90.0, 0.0, 0.0, true);
  40.  
  41. TDEditor_TD = TextDrawCreate(500.000000, 355.000000, "Initial_speed:_50~n~Rotation:_90~n~Angle:_30.0~n~Gravity:_9.8");
  42. TextDrawLetterSize(TDEditor_TD, 0.400000, 1.600000);
  43. TextDrawTextSize(TDEditor_TD, 650.000000, 0.000000);
  44. TextDrawAlignment(TDEditor_TD, 1);
  45. TextDrawColor(TDEditor_TD, -1);
  46. TextDrawUseBox(TDEditor_TD, 1);
  47. TextDrawBoxColor(TDEditor_TD, 255);
  48. TextDrawSetShadow(TDEditor_TD, 0);
  49. TextDrawSetOutline(TDEditor_TD, 0);
  50. TextDrawBackgroundColor(TDEditor_TD, 255);
  51. TextDrawFont(TDEditor_TD, 1);
  52. TextDrawSetProportional(TDEditor_TD, 1);
  53. TextDrawSetShadow(TDEditor_TD, 0);
  54. return 1;
  55. }
  56.  
  57. public OnFilterScriptExit()
  58. {
  59. KillTimer(st);
  60. DestroyObject(ob);
  61. DestroyObject(ob+1);
  62. DestroyObject(ob+2);
  63. DestroyObject(ob+3);
  64. DestroyObject(ob+4);
  65. DestroyObject(ob+5);
  66. DestroyObject(ob+6);
  67. DestroyObject(ob+7);
  68. DestroyObject(ob+8);
  69. DestroyObject(ob+9);
  70. DestroyObject(ob+10);
  71. DestroyObject(ob+11);
  72. DestroyObject(ob+12);
  73. DestroyObject(rotob);
  74. DestroyObject(rotob+1);
  75. DestroyObject(angleob);
  76. DestroyObject(angleob+1);
  77. TextDrawDestroy(TDEditor_TD);
  78. return 1;
  79. }
  80.  
  81. forward Update();
  82. public Update()
  83. {
  84. /*
  85.  
  86. https://i.gyazo.com/b54795fc07cfa761bb7e1e084143ed76.png
  87. XY = X0+V0X*t
  88. Z = Y0+V0Y*T-(gravity/2)*t^2
  89.  
  90. */
  91.  
  92. new Float:X, Float:Y, Float:Z;
  93. GetObjectPos(ob, X, Y, Z);
  94. if(Z <= 5.8)
  95. {
  96. KillTimer(st);
  97. return 1;
  98. }
  99.  
  100. new Float:t = (GetTickCount() - count)*0.001; //MILISECONDS TO SECOUND
  101.  
  102. X = (INITIAL_X+(VelX*t))*floatsin(rotation, degrees);
  103. Y = (INITIAL_Y+(VelX*t))*floatcos(rotation, degrees);
  104. Z = INITIAL_Z+(VelY*t)+((-gravity/2)*floatpower(t, 2));
  105. SetObjectPos(ob, X, Y, Z);
  106.  
  107. /* MoveObject(ob, (Vel*t), Y, (50+(-4.9*floatpower(t, 2))), ((gravity*t))); */
  108. return 1;
  109. }
  110.  
  111. public OnPlayerUpdate(playerid)
  112. {
  113. new Keys,ud,lr;
  114. GetPlayerKeys(playerid,Keys,ud,lr);
  115.  
  116. if(Keys & KEY_WALK) //ANGLE
  117. {
  118. if(lr == KEY_LEFT)
  119. {
  120. angle -= 1.0;
  121. SetObjectRot(angleob, 90-angle, 0.0, -rotation);
  122. UpdateTextDraw();
  123. }
  124. else if(lr == KEY_RIGHT)
  125. {
  126. angle += 1.0;
  127. SetObjectRot(angleob, 90-angle, 0.0, -rotation);
  128. UpdateTextDraw();
  129. }
  130. return 1;
  131. }
  132.  
  133. if(Keys & KEY_FIRE) //ROTATION
  134. {
  135. if(lr == KEY_LEFT)
  136. {
  137. rotation -= 3.0;
  138. SetObjectRot(rotob, 0.0, 0.0, -rotation);
  139. SetObjectRot(angleob, 90-angle, 0.0, -rotation);
  140. UpdateTextDraw();
  141. }
  142. else if(lr == KEY_RIGHT)
  143. {
  144. rotation += 3.0;
  145. SetObjectRot(rotob, 0.0, 0.0, -rotation);
  146. SetObjectRot(angleob, 90-angle, 0.0, -rotation);
  147. UpdateTextDraw();
  148. }
  149. return 1;
  150. }
  151.  
  152. return 1;
  153. }
  154.  
  155. public OnPlayerConnect(playerid)
  156. {
  157. TextDrawShowForPlayer(playerid, TDEditor_TD);
  158. UpdateTextDraw();
  159. return 1;
  160. }
  161.  
  162. CMD:go(playerid, params[])
  163. {
  164. VelX = Vel*floatsin(angle, degrees);
  165. VelY = Vel*floatcos(angle, degrees);
  166. count = GetTickCount();
  167. st = SetTimer("Update", 10, 1);
  168. return 1;
  169. }
  170.  
  171. CMD:restart(playerid, params[])
  172. {
  173. KillTimer(st);
  174. SetObjectPos(ob, INITIAL_X, INITIAL_Y, INITIAL_Z);
  175. return 1;
  176. }
  177.  
  178. CMD:rotation(playerid, params[])
  179. {
  180. if(sscanf(params, "f", rotation)) return SendClientMessage(playerid, -1, "{996600}ERROR: /rotation [Float: rotation]");
  181. SetObjectRot(rotob, 0.0, 0.0, -rotation);
  182. SetObjectRot(angleob, 90-angle, 0.0, -rotation);
  183. UpdateTextDraw();
  184. return 1;
  185. }
  186.  
  187. CMD:angle(playerid, params[])
  188. {
  189. if(sscanf(params, "f", angle)) return SendClientMessage(playerid, -1, "{996600}ERROR: /rotation [Float: rotation]");
  190. SetObjectRot(angleob, 90-angle, 0.0, -rotation);
  191. UpdateTextDraw();
  192. return 1;
  193. }
  194.  
  195. CMD:speed(playerid, params[])
  196. {
  197. if(sscanf(params, "f", Vel)) return SendClientMessage(playerid, -1, "{996600}ERROR: /speed [Float: initial speed]");
  198. VelX = Vel*floatsin(angle, degrees);
  199. VelY = Vel*floatcos(angle, degrees);
  200. UpdateTextDraw();
  201. return 1;
  202. }
  203.  
  204. CMD:gravity(playerid, params[])
  205. {
  206. if(sscanf(params, "f", gravity)) return SendClientMessage(playerid, -1, "{996600}ERROR: /gravity [Float: gravity (9.8 earth)]");
  207. UpdateTextDraw();
  208. return 1;
  209. }
  210.  
  211. UpdateTextDraw()
  212. {
  213. new str[128];
  214. format(str, sizeof(str), "Initial_speed:_%.1f~n~Rotation:_%.1f~n~Angle:_%.1f~n~Gravity:_%.1f", Vel, rotation, angle, gravity);
  215. TextDrawSetString(TDEditor_TD, str);
  216. }
  217.  
  218. //Experimental FS by adri1
  219. //==============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement