mouse.inc 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*******************************************************/
  2. /* Experimental Cursor FilterScript for SA-MP */
  3. /* Made by iPLEOMAX ©. */
  4. /* > Works well when player is aiming wtih a */
  5. /* Sniper Rifle/HeatSeeker/RPG. */
  6. /* > I gave sniper so that they can't */
  7. /* boom themselves.. xD */
  8. /* WARNING! You are not allowed to remove any credits! */
  9. /*******************************************************/
  10. #include < a_samp >
  11. #define frc(%0) floatround(%0*100, floatround_ceil)
  12. #define iM_MODE_CREATE 1
  13. #define iM_MODE_UPDATE 2
  14. new Text:CursorBG;
  15. enum iM_Configs
  16. {
  17. bool:Enabled,
  18. Timer,
  19. CX, CY,
  20. Text:PointerP1,
  21. Text:PointerP2
  22. };
  23. new iM[MAX_PLAYERS][iM_Configs];
  24. public OnFilterScriptInit()
  25. {
  26. print("\n * On-Screen Cursor FS Loaded! - iPLEOMAX \n");
  27. CursorBG = TextDrawCreate(665.000000, 0.000000, "ScreenB");
  28. TextDrawBackgroundColor(CursorBG, 255);
  29. TextDrawFont(CursorBG, 1);
  30. TextDrawLetterSize(CursorBG, 0.000000, 50.800003);
  31. TextDrawColor(CursorBG, -1);
  32. TextDrawSetOutline(CursorBG, 0);
  33. TextDrawSetProportional(CursorBG, 1);
  34. TextDrawSetShadow(CursorBG, 1);
  35. TextDrawUseBox(CursorBG, 1);
  36. TextDrawBoxColor(CursorBG, 255);
  37. TextDrawTextSize(CursorBG, -65.000000, 0.000000);
  38. return true;
  39. }
  40. public OnFilterScriptExit() { print(" * On-Screen Cursor FS exited."); return true; }
  41. public OnPlayerDisconnect( playerid, reason ) { return DisableCursor( playerid ); }
  42. public OnPlayerCommandText( playerid, cmdtext[] )
  43. {
  44. if (!strcmp("/cursor", cmdtext, true))
  45. {
  46. if(!iM[playerid][Enabled]) { EnableCursor( playerid ); }
  47. else { DisableCursor( playerid ); }
  48. return true;
  49. }
  50. if (!strcmp("/backgr", cmdtext, true))
  51. {
  52. TextDrawShowForPlayer( playerid, CursorBG );
  53. return true;
  54. }
  55. return false;
  56. }
  57. public OnPlayerKeyStateChange( playerid, newkeys, oldkeys )
  58. {
  59. if(newkeys & KEY_FIRE && iM[playerid][Enabled])
  60. {
  61. new str[64];
  62. format(str, sizeof(str), "Mouse Location - X: %i, Y: %i", iM[playerid][CX], iM[playerid][CY]);
  63. SendClientMessage(playerid, -1, str);
  64. }
  65. }
  66. forward EnableCursor( playerid );
  67. public EnableCursor( playerid )
  68. {
  69. if(GetPlayerState(playerid) != 1) return SendClientMessage(playerid, -1, "You need to be on-foot to use this command.");
  70. TextDrawShowForPlayer( playerid, CursorBG );
  71. GivePlayerWeapon( playerid, 34, -1 );
  72. //SetPlayerInterior(playerid, 1);
  73. SetPlayerVirtualWorld( playerid, playerid+MAX_PLAYERS );
  74. iM[playerid][CX] = 320; iM[playerid][CY] = 240;
  75. iM[playerid][Timer] = SetTimerEx( "CursorCheck", 100, true, "d", playerid );
  76. iM[playerid][Enabled] = true;
  77. return true;
  78. }
  79. forward DisableCursor( playerid );
  80. public DisableCursor( playerid )
  81. {
  82. KillTimer( iM[playerid][Timer] );
  83. TextDrawDestroy( iM[playerid][PointerP1] );
  84. TextDrawDestroy( iM[playerid][PointerP2] );
  85. TextDrawHideForPlayer( playerid, CursorBG );
  86. SpawnPlayer( playerid );
  87. SetPlayerInterior( playerid, 0 );
  88. SetPlayerVirtualWorld( playerid, 0 );
  89. iM[playerid][Enabled] = false;
  90. return true;
  91. }
  92. forward CursorCheck( playerid );
  93. public CursorCheck( playerid )
  94. {
  95. if(!iM[playerid][Enabled]) return true;
  96. if(GetPlayerState(playerid) != 1) return true;
  97. SetPlayerFacingAngle(playerid, 0);
  98. SetCameraBehindPlayer(playerid);
  99. new Float:P[3];
  100. GetPlayerCameraFrontVector( playerid, P[0], P[1], P[2] );
  101. Cursor( playerid, iM[playerid][CX]+frc(P[0])-1, iM[playerid][CY]+(frc(P[2])+4)*-1 );
  102. return true;
  103. }
  104. stock Cursor( playerid, X, Y )
  105. {
  106. if(X>640) X=640; if(Y>480) Y=480;
  107. if(X<0) X=0; if(Y<0) Y=0;
  108. iM[playerid][CX]=X;
  109. iM[playerid][CY]=Y;
  110. TextDrawDestroy( iM[playerid][PointerP1] );
  111. TextDrawDestroy( iM[playerid][PointerP2] );
  112. iM[playerid][PointerP1] = TextDrawCreate(X, Y, "\\_");
  113. TextDrawBackgroundColor(iM[playerid][PointerP1], 255);
  114. TextDrawFont(iM[playerid][PointerP1], 1);
  115. TextDrawLetterSize(iM[playerid][PointerP1], 0.670000, 1.200000);
  116. TextDrawColor(iM[playerid][PointerP1], -1);
  117. TextDrawSetOutline(iM[playerid][PointerP1], 0);
  118. TextDrawSetProportional(iM[playerid][PointerP1], 1);
  119. TextDrawSetShadow(iM[playerid][PointerP1], 0);
  120. iM[playerid][PointerP2] = TextDrawCreate(X-2.000000, Y-1.000000, "\\_");
  121. TextDrawBackgroundColor(iM[playerid][PointerP2], 255);
  122. TextDrawFont(iM[playerid][PointerP2], 2);
  123. TextDrawLetterSize(iM[playerid][PointerP2], 1.120000, 1.200000);
  124. TextDrawColor(iM[playerid][PointerP2], -1);
  125. TextDrawSetOutline(iM[playerid][PointerP2], 0);
  126. TextDrawSetProportional(iM[playerid][PointerP2], 1);
  127. TextDrawSetShadow(iM[playerid][PointerP2], 0);
  128. TextDrawShowForPlayer( playerid, iM[playerid][PointerP1] );
  129. TextDrawShowForPlayer( playerid, iM[playerid][PointerP2] );
  130. }