mose1.txt 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. /*----------------------------------------------------------------------------*\
  2. ============================
  3. y_mouse - On-screen mouse.
  4. ============================
  5. Description:
  6. Makes a mouse cursor on the screen.
  7. Legal:
  8. Version: MPL 1.1
  9. The contents of this file are subject to the Mozilla Public License Version
  10. 1.1 (the "License"); you may not use this file except in compliance with
  11. the License. You may obtain a copy of the License at
  12. http://www.mozilla.org/MPL/
  13. Software distributed under the License is distributed on an "AS IS" basis,
  14. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  15. for the specific language governing rights and limitations under the
  16. License.
  17. The Original Code is the YSI vararg include.
  18. The Initial Developer of the Original Code is Alex "Y_Less" Cole.
  19. Portions created by the Initial Developer are Copyright (C) 2011
  20. the Initial Developer. All Rights Reserved.
  21. Contributors:
  22. ZeeX, koolk, JoeBullet/Google63, g_aSlice/Slice
  23. Thanks:
  24. JoeBullet/Google63 - Handy arbitrary ASM jump code using SCTRL.
  25. ZeeX - Very productive conversations.
  26. koolk - IsPlayerinAreaEx code.
  27. TheAlpha - Danish translation.
  28. breadfish - German translation.
  29. Fireburn - Dutch translation.
  30. yom - French translation.
  31. 50p - Polish translation.
  32. Zamaroht - Spanish translation.
  33. Dracoblue, sintax, mabako, Xtreme, other coders - Producing other modes
  34. for me to strive to better.
  35. Pixels^ - Running XScripters where the idea was born.
  36. Matite - Pestering me to release it and using it.
  37. Very special thanks to:
  38. Thiadmer - PAWN, whose limits continue to amaze me!
  39. Kye/Kalcor - SA:MP.
  40. SA:MP Team past, present and future - SA:MP.
  41. Version:
  42. 1.0
  43. Changelog:
  44. 02/05/11:
  45. First version.
  46. Functions:
  47. Public:
  48. -
  49. Core:
  50. -
  51. Stock:
  52. -
  53. Static:
  54. -
  55. Inline:
  56. -
  57. API:
  58. -
  59. Callbacks:
  60. -
  61. Definitions:
  62. -
  63. Enums:
  64. -
  65. Macros:
  66. -
  67. Tags:
  68. -
  69. Variables:
  70. Global:
  71. -
  72. Static:
  73. -
  74. Commands:
  75. -
  76. Compile options:
  77. -
  78. Operators:
  79. -
  80. \*----------------------------------------------------------------------------*/
  81. #include "internal\y_version"
  82. #include "y_hooks"
  83. enum E_MOUSE_PLAYER_RESTORE
  84. {
  85. Float:E_MOUSE_PLAYER_RESTORE_X,
  86. Float:E_MOUSE_PLAYER_RESTORE_Y,
  87. Float:E_MOUSE_PLAYER_RESTORE_Z,
  88. Float:E_MOUSE_PLAYER_RESTORE_A,
  89. E_MOUSE_PLAYER_RESTORE_INT,
  90. E_MOUSE_PLAYER_RESTORE_VW
  91. }
  92. static stock
  93. Text:YSI_g_sCursor[MAX_PLAYERS] = {Text:-1, ...},
  94. YSI_g_sMouseData[MAX_PLAYERS],
  95. Float:YSI_g_sMousePos[MAX_PLAYERS][2],
  96. YSI_g_sRestore[MAX_PLAYERS][E_MOUSE_PLAYER_RESTORE],
  97. YSI_g_sCameraVehicle;
  98. stock Mouse_Move(playerid, Float:dx, Float:dy)
  99. {
  100. Mouse_SetPos(playerid, YSI_g_sMousePos[playerid][0] + dx, YSI_g_sMousePos[playerid][1] + dy);
  101. }
  102. stock Mouse_SetPos(playerid, Float:x, Float:y)
  103. {
  104. if (x > 640.0) x = 640.0;
  105. else if (x < 0.0) x = 0.0;
  106. if (y > 480.0) y = 480.0;
  107. else if (y < 0.0) y = 0.0;
  108. if (YSI_g_sMousePos[playerid][0] != x)
  109. {
  110. YSI_g_sMousePos[playerid][0] = x;
  111. YSI_g_sMousePos[playerid][1] = y;
  112. }
  113. else if (YSI_g_sMousePos[playerid][1] != y)
  114. {
  115. YSI_g_sMousePos[playerid][1] = y;
  116. }
  117. else
  118. {
  119. return;
  120. }
  121. if (YSI_g_sCursor[playerid] != Text:-1)
  122. {
  123. TextDrawDestroy(YSI_g_sCursor[playerid]);
  124. }
  125. new
  126. Text:t = TextDrawCreate(x, y, "\\");
  127. YSI_g_sCursor[playerid] = t;
  128. TextDrawFont(t, 0);
  129. TextDrawLetterSize(t, 5.0, 5.0);
  130. TextDrawColor(t, 0xFF0000AA);
  131. TextDrawShowForPlayer(playerid, t);
  132. }
  133. stock Mouse_GetPos(playerid, &Float:x, &Float:y)
  134. {
  135. x = YSI_g_sMousePos[playerid][0];
  136. y = YSI_g_sMousePos[playerid][1];
  137. }
  138. stock Mouse_Enable(playerid)
  139. {
  140. // Save settings.
  141. GetPlayerPos(playerid, YSI_g_sRestore[playerid][E_MOUSE_PLAYER_RESTORE_X], YSI_g_sRestore[playerid][E_MOUSE_PLAYER_RESTORE_Y], YSI_g_sRestore[playerid][E_MOUSE_PLAYER_RESTORE_Z]);
  142. GetPlayerFacingAngle(playerid, YSI_g_sRestore[playerid][E_MOUSE_PLAYER_RESTORE_A]);
  143. YSI_g_sRestore[playerid][E_MOUSE_PLAYER_RESTORE_INT] = GetPlayerInterior(playerid);
  144. YSI_g_sRestore[playerid][E_MOUSE_PLAYER_RESTORE_VW] = GetPlayerVirtualWorld(playerid);
  145. // May put the player in a vehicle in an interior, but on the ground so they
  146. // can't see anything, then change the VW of the vehicle so they can't even
  147. // see themselves (and while I'm at it, desync them).
  148. SetVehiclePos(YSI_g_sCameraVehicle, 1946.195800, 1302.83012, 80.509375);
  149. SetPlayerPos(playerid, -6000.0, -6000.0, -6000.0);
  150. //SetPlayerFacingAngle(playerid, 0.0);
  151. //SetCameraBehindPlayer(playerid);
  152. // "Extreme" start delay.
  153. YSI_g_sMouseData[playerid] = 0x100000FF;
  154. // LinkVehicleToInterior(YSI_g_sCameraVehicle, 1);
  155. // SetPlayerInterior(playerid, 1);
  156. // These are NOT the same world to hide the vehicle.
  157. // SetVehicleVirtualWorld(YSI_g_sCameraVehicle, 0xA137C013);
  158. // SetPlayerVirtualWorld(playerid, 0xA137C014);
  159. // Everyone gets put in the same vehicle.
  160. PutPlayerInVehicle(playerid, YSI_g_sCameraVehicle, 0);
  161. Mouse_SetPos(playerid, 320.0, 240.0);
  162. // SetPlayerHealth(playerid, FLOAT_INFINITY);
  163. // SetVehicleVirtualWorld(YSI_g_sCameraVehicle, 0xA137C013);
  164. // SetPlayerVirtualWorld(playerid, 0xA137C014);
  165. }
  166. stock Mouse_Disable(playerid)
  167. {
  168. RemovePlayerFromVehicle(playerid);
  169. SetPlayerPos(playerid, YSI_g_sRestore[playerid][E_MOUSE_PLAYER_RESTORE_X], YSI_g_sRestore[playerid][E_MOUSE_PLAYER_RESTORE_Y], YSI_g_sRestore[playerid][E_MOUSE_PLAYER_RESTORE_Z]);
  170. SetPlayerFacingAngle(playerid, YSI_g_sRestore[playerid][E_MOUSE_PLAYER_RESTORE_A]);
  171. SetPlayerInterior(playerid, YSI_g_sRestore[playerid][E_MOUSE_PLAYER_RESTORE_INT]);
  172. SetPlayerVirtualWorld(playerid, YSI_g_sRestore[playerid][E_MOUSE_PLAYER_RESTORE_VW]);
  173. YSI_g_sMouseData[playerid] = 0;
  174. }
  175. hook OnScriptInit()
  176. {
  177. YSI_g_sCameraVehicle = CreateVehicle(564, 1946.195800, 1302.83012, 80.509375, 0.0, 0, 0, -1);
  178. }
  179. hook OnPlayerUpdate99(playerid)
  180. {
  181. if (YSI_g_sMouseData[playerid])
  182. {
  183. if (++YSI_g_sMouseData[playerid] == 0x10000100) //0x10000002) //
  184. {
  185. // SetPlayerInterior(playerid, 1);
  186. // PutPlayerInVehicle(playerid, YSI_g_sCameraVehicle, 0);
  187. // These are NOT the same world to hide the vehicle.
  188. //SetVehicleVirtualWorld(YSI_g_sCameraVehicle, 0xA137C013);
  189. //SetPlayerVirtualWorld(playerid, 0xA137C014);
  190. // Reset.
  191. SetVehiclePos(YSI_g_sCameraVehicle, 1946.195800, 1302.83012, 80.509375);
  192. SetVehicleZAngle(YSI_g_sCameraVehicle, 0.0);
  193. // SetPlayerFacingAngle(playerid, 0.0);
  194. SetPlayerCameraPos(playerid, 1946.195800, 1302.83012, 80.509375);
  195. YSI_g_sMouseData[playerid] = 0x10000000;
  196. SetCameraBehindPlayer(playerid);
  197. }
  198. //if (YSI_g_sMouseData[playerid] & 1)
  199. //{
  200. // SetCameraBehindPlayer(playerid);
  201. //}
  202. new
  203. Float:x,
  204. Float:y,
  205. Float:z;
  206. GetPlayerCameraFrontVector(playerid, x, y, z);
  207. /*if (y >= 0)
  208. {
  209. y = -0.01;
  210. }*/
  211. z += 0.098737;
  212. // Invert.
  213. //y = 1.0 / y;
  214. // Invert and project to a large screen!
  215. //x /= y * -10.0;
  216. /*if (!(-0.001 < x < 0.001))
  217. {
  218. //x /= -y; // * -8.0;
  219. }
  220. else
  221. {
  222. //z = 0.0;
  223. }
  224. if (!(-0.001 < z < 0.001))
  225. {
  226. //z /= y; // * 8.0;
  227. }
  228. else
  229. {
  230. //z = 0.0;
  231. }*/
  232. /*if (x < -0.02) x = -30.0;
  233. else if (x > 0.02) x = 30.0;
  234. else x = 0;
  235. if (y < -0.16) y = -30.0;
  236. else if (y > -0.12) y = 30.0;
  237. else y = 0.0;
  238. // Update.*/
  239. //Mouse_Move(playerid, x, z);
  240. printf("TO: %f %f %f", x, y, z);
  241. GetPlayerCameraPos(playerid, x, y, z);
  242. printf("POS: %f %f %f", x, y, z);
  243. SetVehicleVelocity(YSI_g_sCameraVehicle, 0.2, 0.0, 0.001);
  244. return 0;
  245. }
  246. // Do not sync anyone as in this vehicle ever!
  247. return GetPlayerVehicleID(playerid) != YSI_g_sCameraVehicle;
  248. }