1
0

y_mouse.inc 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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, -4000.0, -4000.0, 10.0);
  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] = 0x1000000F;
  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. hook OnPlayerConnect(playerid)
  167. {
  168. YSI_g_sMouseData[playerid] = 0;
  169. }
  170. stock Mouse_Disable(playerid)
  171. {
  172. RemovePlayerFromVehicle(playerid);
  173. 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]);
  174. SetPlayerFacingAngle(playerid, YSI_g_sRestore[playerid][E_MOUSE_PLAYER_RESTORE_A]);
  175. SetPlayerInterior(playerid, YSI_g_sRestore[playerid][E_MOUSE_PLAYER_RESTORE_INT]);
  176. SetPlayerVirtualWorld(playerid, YSI_g_sRestore[playerid][E_MOUSE_PLAYER_RESTORE_VW]);
  177. SetCameraBehindPlayer(playerid);
  178. YSI_g_sMouseData[playerid] = 0;
  179. }
  180. hook OnScriptInit()
  181. {
  182. YSI_g_sCameraVehicle = CreateVehicle(564, -4000.0, -4000.0, 10.0, 0.0, 0, 0, -1);
  183. }
  184. hook OnPlayerUpdate99(playerid)
  185. {
  186. // I have no idea why, but this combination of parameters seems to trigger
  187. // the fast updates to work fully. No idea why (it does seem to be ONLY
  188. // this combination, which makes it frankly amazing that I found it).
  189. if (YSI_g_sMouseData[playerid])
  190. {
  191. static
  192. Float:sLastVector[MAX_PLAYERS][3];
  193. if (++YSI_g_sMouseData[playerid] == 0x10000010) //0x10000002) //
  194. {
  195. // SetPlayerInterior(playerid, 1);
  196. // PutPlayerInVehicle(playerid, YSI_g_sCameraVehicle, 0);
  197. // These are NOT the same world to hide the vehicle.
  198. //SetVehicleVirtualWorld(YSI_g_sCameraVehicle, 0xA137C013);
  199. //SetPlayerVirtualWorld(playerid, 0xA137C014);
  200. // Reset.
  201. SetVehiclePos(YSI_g_sCameraVehicle, -4000.0, -4000.0, 10.0);
  202. SetVehicleZAngle(YSI_g_sCameraVehicle, 0.0);
  203. // SetPlayerFacingAngle(playerid, 0.0);
  204. // SetPlayerCameraPos(playerid, 1946.195800, 1302.83012, 80.509375);
  205. YSI_g_sMouseData[playerid] = 0x10000000;
  206. SetCameraBehindPlayer(playerid);
  207. //SetVehicleVelocity(YSI_g_sCameraVehicle, 0.0, 0.2, 0.1);
  208. }
  209. //else
  210. //{
  211. SetVehicleVelocity(YSI_g_sCameraVehicle, 0.0, 0.2, 0.0);
  212. //}
  213. //if (YSI_g_sMouseData[playerid] & 1)
  214. //{
  215. // SetCameraBehindPlayer(playerid);
  216. //}
  217. new
  218. Float:x,
  219. Float:y,
  220. Float:z;
  221. GetPlayerCameraFrontVector(playerid, x, y, z);
  222. /*if (y >= 0)
  223. {
  224. y = -0.01;
  225. }*/
  226. //z += 0.098737;
  227. // Invert.
  228. //y = 1.0 / y;
  229. // Invert and project to a large screen!
  230. //x /= y * -10.0;
  231. /*if (!(-0.001 < x < 0.001))
  232. {
  233. //x /= -y; // * -8.0;
  234. }
  235. else
  236. {
  237. //z = 0.0;
  238. }
  239. if (!(-0.001 < z < 0.001))
  240. {
  241. //z /= y; // * 8.0;
  242. }
  243. else
  244. {
  245. //z = 0.0;
  246. }*/
  247. /*if (x < -0.02) x = -30.0;
  248. else if (x > 0.02) x = 30.0;
  249. else x = 0;
  250. if (y < -0.16) y = -30.0;
  251. else if (y > -0.12) y = 30.0;
  252. else y = 0.0;
  253. // Update.*/
  254. printf("%f %f %f",
  255. sLastVector[playerid][0] - x,
  256. sLastVector[playerid][1] - y,
  257. sLastVector[playerid][2] - z);
  258. sLastVector[playerid][0] = x;
  259. sLastVector[playerid][1] = y;
  260. sLastVector[playerid][2] = z;
  261. //Mouse_Move(playerid, x, z);
  262. //printf("TO: %f %f %f", x, y, z);
  263. //GetPlayerCameraPos(playerid, x, y, z);
  264. //printf("POS: %f %f %f", x, y, z);
  265. return 0;
  266. }
  267. // Do not sync anyone as in this vehicle ever!
  268. return GetPlayerVehicleID(playerid) != YSI_g_sCameraVehicle;
  269. }