seif_cursor.inc 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. /*
  2. seif_cursor by Seif - A SA-MP 0.2.2 cursor
  3. */
  4. /*x---------------------------------Important-------------------------------------x*/
  5. //**INCLUDES**//
  6. #include <a_samp>
  7. //**PRAGMAS**//
  8. //**MISC**//
  9. /*x---------------------------------Defining-------------------------------------x*/
  10. //**KEYS**//
  11. #define CURSOR_UP KEY_UP
  12. #define CURSOR_DOWN KEY_DOWN
  13. #define CURSOR_RIGHT KEY_RIGHT
  14. #define CURSOR_LEFT KEY_LEFT
  15. #define CURSOR_BOOST KEY_SPRINT
  16. #define CURSOR_CLICK KEY_FIRE
  17. #define CURSOR_TOGGLE KEY_WALK+KEY_SPRINT // ON FOOT: walk + sprint to be able to toggle on/off cursor usage
  18. #define CURSOR_TOGGLE_V KEY_FIRE+320 // WHEN INSIDE VEHICLES: fire + look behind to be able to toggle on/off cursor usage
  19. #define DEFAULT_SPEED 5
  20. #define DEFAULT_SPEED2 10
  21. #define ENABLE_SPEEDCOMMAND_ADJUST // If uncommented, it will enable players to adjust cursor's speeds with a command
  22. #define MAX_BOXES 50
  23. //**VARIABLES**//
  24. new Text:Cursorpt1[MAX_PLAYERS];
  25. new Text:Cursorpt2[MAX_PLAYERS];
  26. new Text:Cursorpt3[MAX_PLAYERS];
  27. new Text:Cursorpt4[MAX_PLAYERS];
  28. new Text:CursorBox[MAX_BOXES];
  29. new Float:CursorX[MAX_PLAYERS];
  30. new Float:CursorY[MAX_PLAYERS];
  31. new Float:cursorposx[MAX_PLAYERS];
  32. new Float:cursorposy[MAX_PLAYERS];
  33. new Float:BoxX[MAX_BOXES];
  34. new Float:BoxY[MAX_BOXES];
  35. new Float:BoxX2[MAX_BOXES];
  36. new CursorSpeed[MAX_PLAYERS];
  37. new Cursorx2Speed[MAX_PLAYERS];
  38. new cursortime[MAX_PLAYERS];
  39. new bool:CursorMode[MAX_PLAYERS];
  40. new boxes;
  41. // **FORWARDS** //
  42. forward CreateCursor();
  43. forward UpdateCursor(playerid, Float:x, Float:y);
  44. forward GetCursorPos(playerid, &Float:x, &Float:y);
  45. forward IsHoldingKey(playerid);
  46. forward ShowCursorForPlayer(playerid);
  47. forward HideCursorForPlayer(playerid);
  48. forward KillCursor();
  49. forward Cursor_OnPlayerKeyStateChange(playerid, newkeys, oldkeys);
  50. forward Cursor_OnPlayerCommandText(playerid, cmdtext[]);
  51. forward Cursor_OnPlayerConnect(playerid);
  52. forward OnPlayerClickCursor(playerid, Float:x, Float:y);
  53. forward CursorActivity(playerid);
  54. forward CursorToPoint(playerid, Float:radius, Float:x, Float:y);
  55. forward CursorClick(playerid);
  56. /*x---------------------------------CallBacks-------------------------------------x*/
  57. public ShowCursorForPlayer(playerid)
  58. {
  59. TextDrawShowForPlayer(playerid, Cursorpt1[playerid]);
  60. TextDrawShowForPlayer(playerid, Cursorpt2[playerid]);
  61. TextDrawShowForPlayer(playerid, Cursorpt3[playerid]);
  62. TextDrawShowForPlayer(playerid, Cursorpt4[playerid]);
  63. }
  64. public HideCursorForPlayer(playerid)
  65. {
  66. TextDrawHideForPlayer(playerid, Cursorpt1[playerid]);
  67. TextDrawHideForPlayer(playerid, Cursorpt2[playerid]);
  68. TextDrawHideForPlayer(playerid, Cursorpt3[playerid]);
  69. TextDrawHideForPlayer(playerid, Cursorpt4[playerid]);
  70. }
  71. public Cursor_OnPlayerConnect(playerid)
  72. {
  73. for(new i = 0; i < MAX_BOXES; i++)
  74. {
  75. TextDrawShowForPlayer(playerid, CursorBox[i]);
  76. }
  77. HideCursorForPlayer(playerid);
  78. CursorMode[playerid] = false;
  79. CursorSpeed[playerid] = DEFAULT_SPEED;
  80. Cursorx2Speed[playerid] = DEFAULT_SPEED2;
  81. return 1;
  82. }
  83. public KillCursor()
  84. {
  85. for(new i = 0; i < GetMaxPlayers(); i++)
  86. {
  87. TextDrawDestroy(Cursorpt1[i]);
  88. TextDrawDestroy(Cursorpt2[i]);
  89. TextDrawDestroy(Cursorpt3[i]);
  90. TextDrawDestroy(Cursorpt4[i]);
  91. }
  92. /*if (playerid == INVALID_PLAYER_ID)
  93. {
  94. for(new i = 0; i < MAX_PLAYERS; i++)
  95. {
  96. TextDrawDestroy(Cursorpt1[i]);
  97. TextDrawDestroy(Cursorpt2[i]);
  98. TextDrawDestroy(Cursorpt3[i]);
  99. TextDrawDestroy(Cursorpt4[i]);
  100. }
  101. }
  102. else
  103. {
  104. TextDrawDestroy(Cursorpt1[playerid]);
  105. TextDrawDestroy(Cursorpt2[playerid]);
  106. TextDrawDestroy(Cursorpt3[playerid]);
  107. TextDrawDestroy(Cursorpt4[playerid]);
  108. }*/
  109. }
  110. public Cursor_OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  111. {
  112. if (newkeys == CURSOR_TOGGLE || newkeys == CURSOR_TOGGLE_V)
  113. {
  114. if (CursorMode[playerid] == false)
  115. {
  116. ShowCursorForPlayer(playerid);
  117. TogglePlayerControllable(playerid, false);
  118. cursortime[playerid] = SetTimerEx("IsHoldingKey",100,1,"d",playerid);
  119. CursorMode[playerid] = true;
  120. }
  121. else
  122. {
  123. HideCursorForPlayer(playerid);
  124. TogglePlayerControllable(playerid, true);
  125. KillTimer(cursortime[playerid]);
  126. CursorMode[playerid] = false;
  127. }
  128. }
  129. if (newkeys == CURSOR_CLICK)
  130. {
  131. if (CursorMode[playerid] == true)
  132. {
  133. if (!IsPlayerInAnyVehicle(playerid)) ClearAnimations(playerid);
  134. new Float:x,Float:y;
  135. GetCursorPos(playerid,x,y);
  136. TextDrawColor(Cursorpt1[playerid], 0xE60000FF);
  137. TextDrawColor(Cursorpt2[playerid], 0xE60000FF);
  138. TextDrawColor(Cursorpt3[playerid], 0xE60000FF);
  139. TextDrawColor(Cursorpt4[playerid], 0xE60000FF);
  140. ShowCursorForPlayer(playerid);
  141. OnPlayerClickCursor(playerid, x, y);
  142. SetTimerEx("CursorClick",300,0,"d",playerid);
  143. }
  144. }
  145. }
  146. public CreateCursor()
  147. {
  148. for(new p; p < GetMaxPlayers(); p++)
  149. {
  150. CursorX[p] = 222.000000;
  151. CursorY[p] = 278.000000;
  152. Cursorpt1[p] = TextDrawCreate(222.000000,278.000000,"l");
  153. Cursorpt2[p] = TextDrawCreate(223.000000,279.000000,\"\");
  154. Cursorpt3[p] = TextDrawCreate(223.000000,285.000000,"-");
  155. Cursorpt4[p] = TextDrawCreate(227.000000,290.000000,\"\");
  156. TextDrawAlignment(Cursorpt1[p],0);
  157. TextDrawAlignment(Cursorpt2[p],0);
  158. TextDrawAlignment(Cursorpt3[p],0);
  159. TextDrawAlignment(Cursorpt4[p],0);
  160. TextDrawBackgroundColor(Cursorpt1[p],0x000000ff);
  161. TextDrawBackgroundColor(Cursorpt2[p],0x000000ff);
  162. TextDrawBackgroundColor(Cursorpt3[p],0x000000ff);
  163. TextDrawBackgroundColor(Cursorpt4[p],0x000000ff);
  164. TextDrawFont(Cursorpt1[p],1);
  165. TextDrawLetterSize(Cursorpt1[p],0.199999,1.600000);
  166. TextDrawFont(Cursorpt2[p],2);
  167. TextDrawLetterSize(Cursorpt2[p],0.499998,1.300000);
  168. TextDrawFont(Cursorpt4[p],2);
  169. TextDrawLetterSize(Cursorpt4[p],0.199998,0.599999);
  170. TextDrawColor(Cursorpt1[p],0xffffffff);
  171. TextDrawColor(Cursorpt2[p],0xffffffff);
  172. TextDrawFont(Cursorpt3[p],0);
  173. TextDrawLetterSize(Cursorpt3[p],0.699999,1.100000);
  174. TextDrawColor(Cursorpt3[p],0xffffffff);
  175. TextDrawColor(Cursorpt4[p],0xffffffff);
  176. TextDrawSetOutline(Cursorpt1[p],1);
  177. TextDrawSetOutline(Cursorpt2[p],1);
  178. TextDrawSetOutline(Cursorpt3[p],1);
  179. TextDrawSetOutline(Cursorpt4[p],1);
  180. TextDrawSetProportional(Cursorpt1[p],1);
  181. TextDrawSetProportional(Cursorpt2[p],1);
  182. TextDrawSetProportional(Cursorpt3[p],1);
  183. TextDrawSetProportional(Cursorpt4[p],1);
  184. TextDrawSetShadow(Cursorpt1[p],1);
  185. TextDrawSetShadow(Cursorpt2[p],1);
  186. TextDrawSetShadow(Cursorpt3[p],1);
  187. TextDrawSetShadow(Cursorpt4[p],1);
  188. CursorSpeed[p] = DEFAULT_SPEED;
  189. Cursorx2Speed[p] = DEFAULT_SPEED2;
  190. CursorMode[p] = false;
  191. }
  192. }
  193. public UpdateCursor(playerid, Float:x,Float:y)
  194. {
  195. new i = playerid;
  196. TextDrawDestroy(Cursorpt1[i]);
  197. TextDrawDestroy(Cursorpt2[i]);
  198. TextDrawDestroy(Cursorpt3[i]);
  199. TextDrawDestroy(Cursorpt4[i]);
  200. Cursorpt1[i] = TextDrawCreate(x,y,"l");
  201. Cursorpt2[i] = TextDrawCreate(x+1,y+1,\"\");
  202. Cursorpt3[i] = TextDrawCreate(x+1,y+7,"-");
  203. Cursorpt4[i] = TextDrawCreate(x+5,y+12,\"\");
  204. TextDrawAlignment(Cursorpt1[i],0);
  205. TextDrawAlignment(Cursorpt2[i],0);
  206. TextDrawAlignment(Cursorpt3[i],0);
  207. TextDrawAlignment(Cursorpt4[i],0);
  208. TextDrawBackgroundColor(Cursorpt1[i],0x000000ff);
  209. TextDrawBackgroundColor(Cursorpt2[i],0x000000ff);
  210. TextDrawBackgroundColor(Cursorpt3[i],0x000000ff);
  211. TextDrawBackgroundColor(Cursorpt4[i],0x000000ff);
  212. TextDrawFont(Cursorpt1[i],1);
  213. TextDrawLetterSize(Cursorpt1[i],0.199999,1.600000);
  214. TextDrawFont(Cursorpt2[i],2);
  215. TextDrawLetterSize(Cursorpt2[i],0.499998,1.300000);
  216. TextDrawFont(Cursorpt3[i],0);
  217. TextDrawLetterSize(Cursorpt3[i],0.699999,1.100000);
  218. TextDrawFont(Cursorpt4[i],2);
  219. TextDrawLetterSize(Cursorpt4[i],0.199998,0.599999);
  220. TextDrawColor(Cursorpt1[i],0xffffffff);
  221. TextDrawColor(Cursorpt2[i],0xffffffff);
  222. TextDrawColor(Cursorpt3[i],0xffffffff);
  223. TextDrawColor(Cursorpt4[i],0xffffffff);
  224. TextDrawSetOutline(Cursorpt1[i],1);
  225. TextDrawSetOutline(Cursorpt2[i],1);
  226. TextDrawSetOutline(Cursorpt3[i],1);
  227. TextDrawSetOutline(Cursorpt4[i],1);
  228. TextDrawSetProportional(Cursorpt1[i],1);
  229. TextDrawSetProportional(Cursorpt2[i],1);
  230. TextDrawSetProportional(Cursorpt3[i],1);
  231. TextDrawSetProportional(Cursorpt4[i],1);
  232. TextDrawSetShadow(Cursorpt1[i],1);
  233. TextDrawSetShadow(Cursorpt2[i],1);
  234. TextDrawSetShadow(Cursorpt3[i],1);
  235. TextDrawSetShadow(Cursorpt4[i],1);
  236. ShowCursorForPlayer(playerid);
  237. CursorX[i] = x;
  238. CursorY[i] = y;
  239. }
  240. public GetCursorPos(playerid, &Float:x, &Float:y)
  241. {
  242. x = CursorX[playerid];
  243. y = CursorY[playerid];
  244. }
  245. public IsHoldingKey(playerid)
  246. {
  247. new keys, updown, leftright;
  248. GetPlayerKeys(playerid, keys, updown, leftright);
  249. if (updown == CURSOR_UP)
  250. {
  251. new Float:x,Float:y;
  252. GetCursorPos(playerid,x,y);
  253. UpdateCursor(playerid, x,y-CursorSpeed[playerid]);
  254. }
  255. else if (updown == CURSOR_DOWN)
  256. {
  257. new Float:x,Float:y;
  258. GetCursorPos(playerid,x,y);
  259. UpdateCursor(playerid, x,y+CursorSpeed[playerid]);
  260. }
  261. if (leftright == CURSOR_RIGHT)
  262. {
  263. new Float:x,Float:y;
  264. GetCursorPos(playerid,x,y);
  265. UpdateCursor(playerid, x+CursorSpeed[playerid],y);
  266. }
  267. else if (leftright == CURSOR_LEFT)
  268. {
  269. new Float:x,Float:y;
  270. GetCursorPos(playerid,x,y);
  271. UpdateCursor(playerid, x-CursorSpeed[playerid],y);
  272. }
  273. if (updown == CURSOR_UP && keys & CURSOR_BOOST)
  274. {
  275. new Float:x,Float:y;
  276. GetCursorPos(playerid,x,y);
  277. UpdateCursor(playerid, x,y-Cursorx2Speed[playerid]);
  278. }
  279. else if (updown == CURSOR_DOWN && keys & CURSOR_BOOST)
  280. {
  281. new Float:x,Float:y;
  282. GetCursorPos(playerid,x,y);
  283. UpdateCursor(playerid, x,y+Cursorx2Speed[playerid]);
  284. }
  285. if (leftright == CURSOR_RIGHT && keys & CURSOR_BOOST)
  286. {
  287. new Float:x,Float:y;
  288. GetCursorPos(playerid,x,y);
  289. UpdateCursor(playerid, x+Cursorx2Speed[playerid],y);
  290. }
  291. else if (leftright == CURSOR_LEFT && keys & CURSOR_BOOST)
  292. {
  293. new Float:x,Float:y;
  294. GetCursorPos(playerid,x,y);
  295. UpdateCursor(playerid, x-Cursorx2Speed[playerid],y);
  296. }
  297. }
  298. public Cursor_OnPlayerCommandText(playerid, cmdtext[])
  299. {
  300. #if defined ENABLE_SPEEDCOMMAND_ADJUST
  301. new entry[20],ccmd[20], idx;
  302. ccmd = cursor_strtok(cmdtext,idx);
  303. if (!strcmp(ccmd, "/cursorspeed", true))
  304. {
  305. entry = cursor_strtok(cmdtext, idx);
  306. if (!strlen(entry)) return 1;
  307. new speed = strval(entry);
  308. CursorSpeed[playerid] = speed;
  309. new frm[128];
  310. format(frm, sizeof(frm), "Cursor speed set to: %d. (default:%d)", speed, DEFAULT_SPEED);
  311. SendClientMessage(playerid, 0xF97804FF, frm);
  312. return 1;
  313. }
  314. if (!strcmp(ccmd, "/cursorspeed2", true))
  315. {
  316. entry = cursor_strtok(cmdtext, idx);
  317. if (!strlen(entry)) return 1;
  318. new speed = strval(entry);
  319. Cursorx2Speed[playerid] = speed;
  320. new frm[128];
  321. format(frm, sizeof(frm), "Cursor x2 speed set to: %d. (default:%d)", speed, DEFAULT_SPEED2);
  322. SendClientMessage(playerid, 0xF97804FF, frm);
  323. return 1;
  324. }
  325. #endif
  326. return 0;
  327. }
  328. public CursorActivity(playerid)
  329. {
  330. new Float:x,Float:y;
  331. GetCursorPos(playerid,x,y);
  332. if (cursorposx[playerid] == x && cursorposy[playerid] == y)
  333. {
  334. HideCursorForPlayer(playerid);
  335. SetTimerEx("CursorActivity",3000,0,"d",playerid);
  336. }
  337. else
  338. {
  339. cursorposx[playerid] = x;
  340. cursorposy[playerid] = y;
  341. ShowCursorForPlayer(playerid);
  342. SetTimerEx("CursorActivity",3000,0,"d",playerid);
  343. }
  344. }
  345. public CursorToPoint(playerid, Float:radius, Float:x, Float:y)
  346. {
  347. new Float:cx, Float:cy;
  348. new Float:ox, Float:oy;
  349. GetCursorPos(playerid, ox, oy);
  350. cx = (ox -x);
  351. cy = (oy -y);
  352. if (((cx < radius) && (cx > -radius)) && ((cy < radius) && (cy > -radius))) return 1;
  353. return 0;
  354. }
  355. forward CursorInBox(playerid, boxid);
  356. public CursorInBox(playerid, boxid)
  357. {
  358. new Float:x, Float:y;
  359. new Float:X, Float:Y;
  360. GetCursorPos(playerid, x, y);
  361. GetBoxPos(boxid, X, Y);
  362. if ((x >= X && x <= BoxX2[boxid]) && (y >= Y && y <= Y+5)) return 1;
  363. return 0;
  364. }
  365. public CursorClick(playerid)
  366. {
  367. new Float:X,Float:Y;
  368. GetCursorPos(playerid, X, Y);
  369. UpdateCursor(playerid, X,Y);
  370. }
  371. forward GetBoxPos(boxid, &Float:x, &Float:y);
  372. public GetBoxPos(boxid, &Float:x, &Float:y)
  373. {
  374. x = BoxX[boxid];
  375. y = BoxY[boxid];
  376. }
  377. forward AddButton(Float:x, Float:y, color, name[]);
  378. public AddButton(Float:x, Float:y, color, name[])
  379. {
  380. new times = 10;
  381. boxes++;
  382. CursorBox[boxes] = TextDrawCreate(x, y, name);
  383. TextDrawUseBox(CursorBox[boxes],1);
  384. TextDrawBoxColor(CursorBox[boxes],color);
  385. TextDrawTextSize(CursorBox[boxes],x+(strlen(name)*times),0.000000);
  386. TextDrawAlignment(CursorBox[boxes],0);
  387. TextDrawBackgroundColor(CursorBox[boxes],0x000000ff);
  388. TextDrawFont(CursorBox[boxes],1);
  389. TextDrawLetterSize(CursorBox[boxes],0.500000,0.750000);
  390. TextDrawColor(CursorBox[boxes],0xffffffff);
  391. TextDrawSetOutline(CursorBox[boxes],1);
  392. TextDrawSetProportional(CursorBox[boxes],1);
  393. TextDrawSetShadow(CursorBox[boxes],1);
  394. BoxX[boxes] = x-1.0;
  395. BoxY[boxes] = y-3.0;
  396. BoxX2[boxes] = BoxX[boxes]+(strlen(name)*times);
  397. TextDrawShowForAll(CursorBox[boxes]);
  398. return boxes;
  399. }
  400. forward DeleteButtons();
  401. public DeleteButtons()
  402. {
  403. for(new b = 1; b < MAX_BOXES; b++) TextDrawDestroy(CursorBox[b]);
  404. }
  405. stock cursor_strtok(const string[], &index)
  406. {
  407. new length = strlen(string);
  408. while ((index < length) && (string[index] <= ' '))
  409. {
  410. index++;
  411. }
  412. new offset = index;
  413. new result[20];
  414. while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  415. {
  416. result[index - offset] = string[index];
  417. index++;
  418. }
  419. result[index - offset] = EOS;
  420. return result;
  421. }
  422. /*public OnPlayerClickCursor(playerid, Float:x, Float:y)
  423. {
  424. return 1;
  425. }*/