buttons.pwn 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922
  1. /*##############################################################################
  2. #########################################
  3. # #
  4. # BUTTONS - FILTERSCRIPT BY YOM #
  5. # v1.3 BETA #
  6. # Steal my work and die >:D #
  7. # #
  8. #########################################
  9. - Informations about this file:
  10. ===============================
  11. - You must #include <yom_buttons> in the scripts you want to use buttons
  12. - Copyright:
  13. ============
  14. - Yom's Scripts Factory © ®.
  15. - You can use this script and distribute it but,
  16. - You WILL NOT sell it or tell it's your own work.
  17. - Versions changes:
  18. ===================
  19. - 1.0 : Initial release.
  20. - 1.1 : Small tweaks here and there.
  21. - 1.2 : Removed: rX and rY parameters (was useless, for me anyway)
  22. Changed: rZ parameter is now named Angle
  23. Changed: CreateButton now returns the objectid, not the buttonid.
  24. Added: Sets the pos of the player, so he press exactly on the button.
  25. - 1.3 : Changed again: CreateButton returns the buttonid (from 1 to MAX_BUTTONS).
  26. Changed: Player can press the button from any angle
  27. Added: more or less useful functions for use in your scripts
  28. Added: sound
  29. Added: button placer (if debug enabled, type /button)
  30. THIS IS A BETA VERSION, PLEASE DON'T BE A BASTARD, AND REPORT BUGS/PROBLEMS!
  31. ##############################################################################*/
  32. /*################################ CONFIGURATION #############################*/
  33. //max buttons that can be created.
  34. #define MAX_BUTTONS 50
  35. //this is the distance max for detecting buttons. If the player is at this
  36. //distance, or less, of a button, he will press this button.
  37. #define MAX_DISTANCE 1.3
  38. //this is the object modelid used for buttons.
  39. //i'm asking for nice objects, if you know some that can be used as buttons, tell me!
  40. #define OBJECT 2886
  41. //comment this line to disable the sound, or change the number for another sound
  42. //don't forget that you can do whatever you want in OnPlayerPressButton
  43. #define SOUND 1083
  44. //comment this line to disable debug (recommended once you finished using the
  45. //buttons editor, this will make the script more efficient)
  46. //#define DEBUG
  47. /*############################################################################*/
  48. /*----------------------------------------------------------------------------*/
  49. #include <a_samp>
  50. #define INVALID_BUTTON_ID -1
  51. enum BUTTON_INFOS
  52. {
  53. bool:Created,
  54. bool:Moving,
  55. bool:Usable[MAX_PLAYERS],
  56. Float:Pos[4],
  57. ObjectID
  58. }
  59. new ButtonInfo[MAX_BUTTONS+1][BUTTON_INFOS];
  60. #if defined DEBUG
  61. enum PLAYER_INFOS
  62. {
  63. Float:MSpeed,
  64. SelectedButton,
  65. TimerID
  66. }
  67. new PlayerInfo[MAX_PLAYERS][PLAYER_INFOS];
  68. new String[128];
  69. #endif
  70. /*----------------------------------------------------------------------------*/
  71. /*----------------------------------------------------------------------------*/
  72. Float:Distance3D(Float:PointA[], Float:PointB[], bool:sqrt = true)
  73. {
  74. new Float:Dist[4];
  75. for (new i = 0; i < 3; i++)
  76. {
  77. Dist[i] = PointA[i] - PointB[i];
  78. Dist[i] *= Dist[i];
  79. }
  80. Dist[3] = Dist[0] + Dist[1] + Dist[2];
  81. return sqrt ? floatsqroot(Dist[3]) : Dist[3];
  82. }
  83. /*----------------------------------------------------------------------------*/
  84. /*----------------------------------------------------------------------------*/
  85. Float:Angle2D(Float:PointA[], Float:PointB[])
  86. {
  87. new bool:A_LS_B[2], Float:Dist[2], Float:Angle;
  88. for (new i = 0; i < 2; i++)
  89. {
  90. A_LS_B[i] = PointA[i] < PointB[i];
  91. Dist[i] = A_LS_B[i] ? PointB[i] - PointA[i] : PointA[i] - PointB[i];
  92. }
  93. Angle = atan2(Dist[1],Dist[0]);
  94. Angle = A_LS_B[0] ? 270.0 + Angle : 90.0 - Angle;
  95. Angle = A_LS_B[1] ? Angle : 180.0 - Angle;
  96. return Angle;
  97. }
  98. /*----------------------------------------------------------------------------*/
  99. /*----------------------------------------------------------------------------*/
  100. GetClosestButton(Float:Point[], &Float:Distance = 0.0)
  101. {
  102. new Closest = INVALID_BUTTON_ID, Float:Distance2 = 100000.0;
  103. for (new buttonid = 1, highest = FS_GetHighestButtonID(); buttonid <= highest; buttonid ++)
  104. {
  105. if (ButtonInfo[buttonid][Created])
  106. {
  107. Distance = Distance3D(Point, ButtonInfo[buttonid][Pos]);
  108. if (Distance < Distance2)
  109. {
  110. Distance2 = Distance;
  111. Closest = buttonid;
  112. }
  113. }
  114. }
  115. Distance = Distance2;
  116. return Closest;
  117. }
  118. /*----------------------------------------------------------------------------*/
  119. /*----------------------------------------------------------------------------*/
  120. forward FS_CreateButton(Float:X, Float:Y, Float:Z, Float:Angle);
  121. public FS_CreateButton(Float:X, Float:Y, Float:Z, Float:Angle)
  122. {
  123. new buttonid;
  124. for(buttonid = 1; buttonid <= MAX_BUTTONS; buttonid ++)
  125. if (!ButtonInfo[buttonid][Created])
  126. break;
  127. ButtonInfo[buttonid][ObjectID] = CreateObject(OBJECT,X,Y,Z,0.0,0.0,Angle);
  128. ButtonInfo[buttonid][Pos][0] = X;
  129. ButtonInfo[buttonid][Pos][1] = Y;
  130. ButtonInfo[buttonid][Pos][2] = Z;
  131. ButtonInfo[buttonid][Pos][3] = Angle;
  132. ButtonInfo[buttonid][Moving] = false;
  133. ButtonInfo[buttonid][Created] = true;
  134. for (new playerid = 0; playerid < MAX_PLAYERS; playerid ++)
  135. ButtonInfo[buttonid][Usable][playerid] = true;
  136. return buttonid;
  137. }
  138. /*----------------------------------------------------------------------------*/
  139. /*----------------------------------------------------------------------------*/
  140. forward FS_DestroyButton(buttonid);
  141. public FS_DestroyButton(buttonid)
  142. {
  143. if (FS_IsValidButton(buttonid))
  144. {
  145. CallRemoteFunction("OnButtonDestroyed", "i", buttonid);
  146. ButtonInfo[buttonid][Created] = false;
  147. DestroyObject(ButtonInfo[buttonid][ObjectID]);
  148. }
  149. }
  150. /*----------------------------------------------------------------------------*/
  151. /*----------------------------------------------------------------------------*/
  152. forward FS_SetButtonPos(buttonid, Float:X, Float:Y, Float:Z, Float:Angle);
  153. public FS_SetButtonPos(buttonid, Float:X, Float:Y, Float:Z, Float:Angle)
  154. {
  155. if (FS_IsValidButton(buttonid))
  156. {
  157. new objectid = ButtonInfo[buttonid][ObjectID];
  158. SetObjectPos(objectid, X, Y, Z);
  159. SetObjectRot(objectid, 0.0, 0.0, Angle);
  160. ButtonInfo[buttonid][Pos][0] = X;
  161. ButtonInfo[buttonid][Pos][1] = Y;
  162. ButtonInfo[buttonid][Pos][2] = Z;
  163. ButtonInfo[buttonid][Pos][3] = Angle;
  164. }
  165. }
  166. /*----------------------------------------------------------------------------*/
  167. /*----------------------------------------------------------------------------*/
  168. forward FS_MoveButton(buttonid, Float:X, Float:Y, Float:Z, Float:Speed);
  169. public FS_MoveButton(buttonid, Float:X, Float:Y, Float:Z, Float:Speed)
  170. {
  171. if (FS_IsValidButton(buttonid))
  172. {
  173. MoveObject(ButtonInfo[buttonid][ObjectID], X, Y, Z, Speed);
  174. ButtonInfo[buttonid][Moving] = true;
  175. ButtonInfo[buttonid][Pos][0] = 99999.9;
  176. ButtonInfo[buttonid][Pos][1] = 99999.9;
  177. ButtonInfo[buttonid][Pos][2] = 99999.9;
  178. }
  179. }
  180. /*----------------------------------------------------------------------------*/
  181. /*----------------------------------------------------------------------------*/
  182. forward FS_StopButton(buttonid);
  183. public FS_StopButton(buttonid)
  184. {
  185. if (FS_IsValidButton(buttonid))
  186. StopObject(ButtonInfo[buttonid][ObjectID]);
  187. }
  188. /*----------------------------------------------------------------------------*/
  189. /*----------------------------------------------------------------------------*/
  190. forward bool:FS_IsValidButton(buttonid);
  191. public bool:FS_IsValidButton(buttonid)
  192. {
  193. return (buttonid <= MAX_BUTTONS && ButtonInfo[buttonid][Created]);
  194. }
  195. /*----------------------------------------------------------------------------*/
  196. /*----------------------------------------------------------------------------*/
  197. forward FS_GetHighestButtonID();
  198. public FS_GetHighestButtonID()
  199. {
  200. for (new buttonid = MAX_BUTTONS; buttonid > 0; buttonid --)
  201. if (ButtonInfo[buttonid][Created])
  202. return buttonid;
  203. return INVALID_BUTTON_ID;
  204. }
  205. /*----------------------------------------------------------------------------*/
  206. /*----------------------------------------------------------------------------*/
  207. forward FS_GetButtonObjectID(buttonid);
  208. public FS_GetButtonObjectID(buttonid)
  209. {
  210. return FS_IsValidButton(buttonid) ? ButtonInfo[buttonid][ObjectID] : INVALID_OBJECT_ID;
  211. }
  212. /*----------------------------------------------------------------------------*/
  213. /*----------------------------------------------------------------------------*/
  214. forward FS_GetObjectButtonID(objectid);
  215. public FS_GetObjectButtonID(objectid)
  216. {
  217. for (new buttonid = 1, highest = FS_GetHighestButtonID(); buttonid <= highest; buttonid ++)
  218. if (ButtonInfo[buttonid][Created] && ButtonInfo[buttonid][ObjectID] == objectid)
  219. return buttonid;
  220. return INVALID_BUTTON_ID;
  221. }
  222. /*----------------------------------------------------------------------------*/
  223. /*----------------------------------------------------------------------------*/
  224. forward FS_PrintButtonsInfos();
  225. public FS_PrintButtonsInfos()
  226. {
  227. print
  228. (
  229. "\n \
  230. ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿\n \
  231. ³ Buttons Informations ³\n \
  232. ÃÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄ´\n \
  233. ³ButtonID³ObjectID³ X ³ Y ³ Z ³ A ³\n \
  234. ÃÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄ´"
  235. );
  236. for (new buttonid = 1; buttonid <= MAX_BUTTONS; buttonid ++)
  237. {
  238. if (ButtonInfo[buttonid][Created])
  239. {
  240. printf
  241. (
  242. " ³%8d³%8d³%6.2f³%6.2f³%6.2f³%6.2f³",
  243. buttonid,
  244. ButtonInfo[buttonid][ObjectID],
  245. ButtonInfo[buttonid][Pos][0],
  246. ButtonInfo[buttonid][Pos][1],
  247. ButtonInfo[buttonid][Pos][2],
  248. ButtonInfo[buttonid][Pos][3]
  249. );
  250. }
  251. }
  252. print(" ÀÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÙ\n");
  253. }
  254. /*----------------------------------------------------------------------------*/
  255. /*----------------------------------------------------------------------------*/
  256. forward Float:FS_GetDistanceToButton(buttonid, Float:X, Float:Y, Float:Z);
  257. public Float:FS_GetDistanceToButton(buttonid, Float:X, Float:Y, Float:Z)
  258. {
  259. if (FS_IsValidButton(buttonid))
  260. {
  261. new Float:Point[3];
  262. Point[0] = X;
  263. Point[1] = Y;
  264. Point[2] = Z;
  265. return Distance3D(Point, ButtonInfo[buttonid][Pos]);
  266. }
  267. return -1.0;
  268. }
  269. /*----------------------------------------------------------------------------*/
  270. /*----------------------------------------------------------------------------*/
  271. forward FS_TeleportPlayerToButton(playerid, buttonid);
  272. public FS_TeleportPlayerToButton(playerid, buttonid)
  273. {
  274. if (FS_IsValidButton(buttonid) && !ButtonInfo[buttonid][Moving])
  275. {
  276. new Float:Angle = ButtonInfo[buttonid][Pos][3];
  277. SetPlayerPos
  278. (
  279. playerid,
  280. ButtonInfo[buttonid][Pos][0] - (0.65 * floatsin(-Angle,degrees)),
  281. ButtonInfo[buttonid][Pos][1] - (0.65 * floatcos(-Angle,degrees)),
  282. ButtonInfo[buttonid][Pos][2] - 0.63
  283. );
  284. SetPlayerFacingAngle(playerid, -Angle);
  285. SetCameraBehindPlayer(playerid);
  286. }
  287. }
  288. /*----------------------------------------------------------------------------*/
  289. /*----------------------------------------------------------------------------*/
  290. forward FS_ToggleButtonEnabledForPlayer(playerid, buttonid, bool:enabled);
  291. public FS_ToggleButtonEnabledForPlayer(playerid, buttonid, bool:enabled)
  292. {
  293. if (FS_IsValidButton(buttonid))
  294. ButtonInfo[buttonid][Usable][playerid] = enabled;
  295. }
  296. /*----------------------------------------------------------------------------*/
  297. /*----------------------------------------------------------------------------*/
  298. forward FS_ToggleButtonEnabled(buttonid, bool:enabled);
  299. public FS_ToggleButtonEnabled(buttonid, bool:enabled)
  300. {
  301. if (FS_IsValidButton(buttonid))
  302. for (new playerid = 0; playerid < MAX_PLAYERS; playerid ++)
  303. ButtonInfo[buttonid][Usable][playerid] = enabled;
  304. }
  305. /*----------------------------------------------------------------------------*/
  306. /*----------------------------------------------------------------------------*/
  307. forward OnPlayerPressButton_Delay(playerid, buttonid);
  308. public OnPlayerPressButton_Delay(playerid, buttonid)
  309. {
  310. #if defined SOUND
  311. PlayerPlaySound(playerid, SOUND, 0.0, 0.0, 0.0);
  312. #endif
  313. CallRemoteFunction("OnPlayerPressButton", "ii", playerid, buttonid);
  314. }
  315. /*----------------------------------------------------------------------------*/
  316. /*----------------------------------------------------------------------------*/
  317. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  318. {
  319. if (GetPlayerState(playerid) == PLAYER_STATE_ONFOOT)
  320. {
  321. if (newkeys & 16)
  322. {
  323. new Float:Distance, Float:Angle, Float:PlayerPos[3], buttonid;
  324. GetPlayerPos(playerid, PlayerPos[0], PlayerPos[1], PlayerPos[2]);
  325. buttonid = GetClosestButton(PlayerPos, Distance);
  326. if (buttonid != INVALID_BUTTON_ID && ButtonInfo[buttonid][Usable][playerid] && Distance <= MAX_DISTANCE)
  327. {
  328. Angle = Angle2D(PlayerPos, ButtonInfo[buttonid][Pos]);
  329. SetPlayerFacingAngle(playerid, Angle);
  330. SetPlayerPos
  331. (
  332. playerid,
  333. ButtonInfo[buttonid][Pos][0] - (0.65 * floatsin(-Angle,degrees)),
  334. ButtonInfo[buttonid][Pos][1] - (0.65 * floatcos(-Angle,degrees)),
  335. ButtonInfo[buttonid][Pos][2] - 0.63
  336. );
  337. ApplyAnimation(playerid, "HEIST9", "Use_SwipeCard", 10.0, 0, 0, 0, 0, 0);
  338. SetTimerEx("OnPlayerPressButton_Delay", 500, false, "ii", playerid, buttonid);
  339. }
  340. }
  341. #if defined DEBUG
  342. else if (newkeys & KEY_HANDBRAKE)
  343. {
  344. if (PlayerInfo[playerid][SelectedButton] != INVALID_BUTTON_ID)
  345. {
  346. switch (PlayerInfo[playerid][MSpeed])
  347. {
  348. case 1.0 : { PlayerInfo[playerid][MSpeed] = 2.5; String = "Slow"; }
  349. case 2.5 : { PlayerInfo[playerid][MSpeed] = 5.0; String = "Normal"; }
  350. case 5.0 : { PlayerInfo[playerid][MSpeed] = 15.0; String = "Fast"; }
  351. default : { PlayerInfo[playerid][MSpeed] = 1.0; String = "Very Slow"; }
  352. }
  353. format(String, sizeof(String), "~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~w~Movement speed~n~~r~%s~w~!", String);
  354. GameTextForPlayer(playerid, String, 1500, 3);
  355. }
  356. }
  357. else if (newkeys & KEY_WALK)
  358. {
  359. if (PlayerInfo[playerid][SelectedButton] != INVALID_BUTTON_ID)
  360. OnPlayerCommandText(playerid, "/button deselect");
  361. else
  362. OnPlayerCommandText(playerid, "/button select");
  363. }
  364. #endif
  365. }
  366. }
  367. /*----------------------------------------------------------------------------*/
  368. /*----------------------------------------------------------------------------*/
  369. public OnObjectMoved(objectid)
  370. {
  371. new buttonid = FS_GetObjectButtonID(objectid);
  372. if (buttonid != INVALID_BUTTON_ID)
  373. {
  374. new Float:ObjectPos[3];
  375. GetObjectPos(objectid, ObjectPos[0], ObjectPos[1], ObjectPos[2]);
  376. ButtonInfo[buttonid][Pos][0] = ObjectPos[0];
  377. ButtonInfo[buttonid][Pos][1] = ObjectPos[1];
  378. ButtonInfo[buttonid][Pos][2] = ObjectPos[2];
  379. ButtonInfo[buttonid][Moving] = false;
  380. CallRemoteFunction("OnButtonMoved", "i", buttonid);
  381. }
  382. }
  383. /*----------------------------------------------------------------------------*/
  384. /*----------------------------------------------------------------------------*/
  385. public OnPlayerConnect(playerid)
  386. {
  387. #if defined DEBUG
  388. if (PlayerInfo[playerid][SelectedButton] != INVALID_BUTTON_ID)
  389. {
  390. PlayerInfo[playerid][SelectedButton] = INVALID_BUTTON_ID;
  391. PlayerInfo[playerid][MSpeed] = 5.0;
  392. KillTimer(PlayerInfo[playerid][TimerID]);
  393. }
  394. #endif
  395. ApplyAnimation(playerid, "HEIST9", "Use_SwipeCard", 10.0, 0, 0, 0, 0, 0);
  396. }
  397. /*----------------------------------------------------------------------------*/
  398. /*----------------------------------------------------------------------------*/
  399. public OnGameModeInit()
  400. {
  401. #if defined DEBUG
  402. FS_PrintButtonsInfos();
  403. #endif
  404. return true;
  405. }
  406. /*----------------------------------------------------------------------------*/
  407. /*----------------------------------------------------------------------------*/
  408. public OnGameModeExit()
  409. {
  410. #if defined DEBUG
  411. FS_PrintButtonsInfos();
  412. #endif
  413. for (new buttonid = 1; buttonid <= MAX_BUTTONS; buttonid ++)
  414. if (ButtonInfo[buttonid][Created])
  415. FS_DestroyButton(buttonid);
  416. return true;
  417. }
  418. /*----------------------------------------------------------------------------*/
  419. /*----------------------------------------------------------------------------*/
  420. #if defined DEBUG
  421. argpos(const string[], idx = 0, sep = ' ')
  422. {
  423. for(new i = idx, j = strlen(string); i < j; i++)
  424. if (string[i] == sep && string[i+1] != sep)
  425. return i+1;
  426. return -1;
  427. }
  428. public OnPlayerCommandText(playerid, cmdtext[])
  429. {
  430. if (strlen(cmdtext) > 50)
  431. {
  432. SendClientMessage(playerid, 0xFF0000FF, "Invalid command length (exceeding 50 characters)");
  433. return true;
  434. }
  435. if(!strcmp(cmdtext, "/button", .length = 7))
  436. {
  437. if (!IsPlayerAdmin(playerid))
  438. return true;
  439. new arg1 = argpos(cmdtext);
  440. if (!cmdtext[arg1])
  441. {
  442. SendClientMessage(playerid, 0xFF0000FF, "Button Editor's commands:");
  443. SendClientMessage(playerid, 0xFFFFFFFF, "\"/button create\" - Create a button at your position, then type \"/button select\" to move this button.");
  444. SendClientMessage(playerid, 0xFFFFFFFF, "\"/button select <opt:buttonid>\" - If you don't use the optional parameter, it will select the closest button.");
  445. SendClientMessage(playerid, 0xFFFFFFFF, "\"/button save <opt:comment>\" - Save the positions of the selected button, optionally with a short comment.");
  446. SendClientMessage(playerid, 0xFFFFFFFF, "\"/button deselect\" - Deselect the selected button, this stops the editing mode.");
  447. SendClientMessage(playerid, 0xFF0000FF, "Button Editor's keys:");
  448. SendClientMessage(playerid, 0xFFFFFFFF, "Use Directional key to move the selected button forward, backward, to the left and to the right.");
  449. SendClientMessage(playerid, 0xFFFFFFFF, "Use Look Behind + Left or Right to rotate the selected button.");
  450. SendClientMessage(playerid, 0xFFFFFFFF, "Use Secondary Fire to change the movement speed.");
  451. SendClientMessage(playerid, 0xFFFFFFFF, "Use Walk to toggle Deselect/Select closest button.");
  452. return true;
  453. }
  454. else if (!strcmp(cmdtext[arg1], "create", .length = 6))
  455. {
  456. new Float:PlayerPos[4], buttonid;
  457. GetPlayerPos(playerid, PlayerPos[0], PlayerPos[1], PlayerPos[2]);
  458. GetPlayerFacingAngle(playerid, PlayerPos[3]);
  459. buttonid = FS_CreateButton(PlayerPos[0],PlayerPos[1],PlayerPos[2] + 0.63,PlayerPos[3]);
  460. format(String, sizeof(String), "Buttonid %d created! Select it with \"/button select\"", buttonid);
  461. SendClientMessage(playerid, 0x00FF00FF, String);
  462. return true;
  463. }
  464. else if (!strcmp(cmdtext[arg1], "select", .length = 6))
  465. {
  466. new arg2 = argpos(cmdtext, arg1),
  467. buttonid;
  468. if (PlayerInfo[playerid][SelectedButton] != INVALID_BUTTON_ID)
  469. KillTimer(PlayerInfo[playerid][TimerID]);
  470. if (!cmdtext[arg2])
  471. {
  472. new Float:PlayerPos[3];
  473. GetPlayerPos(playerid, PlayerPos[0], PlayerPos[1], PlayerPos[2]);
  474. buttonid = GetClosestButton(PlayerPos);
  475. if (buttonid == INVALID_BUTTON_ID)
  476. SendClientMessage(playerid, 0xFF0000FF, "Can't find a button! You may need to create one!");
  477. else
  478. {
  479. PlayerInfo[playerid][SelectedButton] = buttonid;
  480. PlayerInfo[playerid][TimerID] = SetTimerEx("ButtonEditor_Timer", 50, true, "ii", playerid, PlayerInfo[playerid][SelectedButton]);
  481. TogglePlayerControllable(playerid, false);
  482. format(String, sizeof(String), "Buttonid %d selected! Once you placed it where you want, save it with \"/button save <comment>\"", buttonid);
  483. SendClientMessage(playerid, 0x00FF00FF, String);
  484. }
  485. }
  486. else
  487. {
  488. buttonid = strval(cmdtext[arg2]);
  489. if (FS_IsValidButton(buttonid))
  490. {
  491. PlayerInfo[playerid][SelectedButton] = buttonid;
  492. PlayerInfo[playerid][TimerID] = SetTimerEx("ButtonEditor_Timer", 50, true, "ii", playerid, PlayerInfo[playerid][SelectedButton]);
  493. TogglePlayerControllable(playerid, false);
  494. format(String, sizeof(String), "Buttonid %d selected! Once you placed it where you want, save it with \"/button save\"", buttonid);
  495. SendClientMessage(playerid, 0x00FF00FF, String);
  496. }
  497. else
  498. SendClientMessage(playerid, 0xFF0000FF, "This buttonid is invalid!");
  499. }
  500. return true;
  501. }
  502. else if (!strcmp(cmdtext[arg1], "save", .length = 4))
  503. {
  504. new arg2 = argpos(cmdtext, arg1),
  505. buttonid = PlayerInfo[playerid][SelectedButton];
  506. if (buttonid != INVALID_BUTTON_ID)
  507. {
  508. new File:savedbuttons_file = fopen("savedbuttons.txt", io_append);
  509. if (!cmdtext[arg2])
  510. {
  511. format
  512. (
  513. String,
  514. sizeof(String),
  515. "CreateButton(%.2f, %.2f, %.2f, %.1f);\r\n",
  516. ButtonInfo[buttonid][Pos][0],
  517. ButtonInfo[buttonid][Pos][1],
  518. ButtonInfo[buttonid][Pos][2],
  519. float(floatround(ButtonInfo[buttonid][Pos][3])%360)
  520. );
  521. }
  522. else
  523. {
  524. format
  525. (
  526. String,
  527. sizeof(String),
  528. "CreateButton(%.2f, %.2f, %.2f, %.1f); // %s\r\n",
  529. ButtonInfo[buttonid][Pos][0],
  530. ButtonInfo[buttonid][Pos][1],
  531. ButtonInfo[buttonid][Pos][2],
  532. float(floatround(ButtonInfo[buttonid][Pos][3])%360),
  533. cmdtext[arg2]
  534. );
  535. }
  536. fwrite(savedbuttons_file,String);
  537. fclose(savedbuttons_file);
  538. SendClientMessage(playerid, 0x00FF00FF, "Button's informations saved in \"/scriptfiles/savedbuttons.txt\"!");
  539. }
  540. else
  541. SendClientMessage(playerid, 0xFF0000FF, "Umm..Select a button first?");
  542. return true;
  543. }
  544. else if (!strcmp(cmdtext[arg1], "deselect", .length = 6))
  545. {
  546. if (PlayerInfo[playerid][SelectedButton] != INVALID_BUTTON_ID)
  547. {
  548. format(String, sizeof(String), "Buttonid %d deselected!", PlayerInfo[playerid][SelectedButton]);
  549. SendClientMessage(playerid, 0x00FF00FF, String);
  550. PlayerInfo[playerid][SelectedButton] = INVALID_BUTTON_ID;
  551. TogglePlayerControllable(playerid, true);
  552. KillTimer(PlayerInfo[playerid][TimerID]);
  553. }
  554. else
  555. SendClientMessage(playerid, 0xFF0000FF, "Umm..Select a button first?");
  556. return true;
  557. }
  558. return false;
  559. }
  560. return false;
  561. }
  562. forward ButtonEditor_Timer(playerid, buttonid);
  563. public ButtonEditor_Timer(playerid, buttonid)
  564. {
  565. new PlayerKeys[3],
  566. Float:Move_Sin = PlayerInfo[playerid][MSpeed]/100.0 * floatsin(-ButtonInfo[buttonid][Pos][3], degrees),
  567. Float:Move_Cos = PlayerInfo[playerid][MSpeed]/100.0 * floatcos(-ButtonInfo[buttonid][Pos][3], degrees);
  568. GetPlayerKeys(playerid,PlayerKeys[0],PlayerKeys[1],PlayerKeys[2]);
  569. if (PlayerKeys[0] + PlayerKeys[1] + PlayerKeys[2] != 0 && PlayerKeys[0] != KEY_HANDBRAKE)
  570. {
  571. if (PlayerKeys[0] & 512)
  572. {
  573. if (PlayerKeys[2] == KEY_LEFT)
  574. ButtonInfo[buttonid][Pos][3] += PlayerInfo[playerid][MSpeed]/5.0;
  575. else if (PlayerKeys[2] == KEY_RIGHT)
  576. ButtonInfo[buttonid][Pos][3] -= PlayerInfo[playerid][MSpeed]/5.0;
  577. format
  578. (
  579. String,
  580. sizeof(String),
  581. "~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~w~Rotating buttonid ~r~%d ~n~~w~Angle=~r~%d",
  582. buttonid,
  583. floatround(ButtonInfo[buttonid][Pos][3]) % 360
  584. );
  585. GameTextForPlayer(playerid, String, 1500, 3);
  586. }
  587. else
  588. {
  589. if (PlayerKeys[1] == KEY_UP)
  590. {
  591. ButtonInfo[buttonid][Pos][0] += Move_Sin;
  592. ButtonInfo[buttonid][Pos][1] += Move_Cos;
  593. }
  594. else if (PlayerKeys[1] == KEY_DOWN)
  595. {
  596. ButtonInfo[buttonid][Pos][0] -= Move_Sin;
  597. ButtonInfo[buttonid][Pos][1] -= Move_Cos;
  598. }
  599. if (PlayerKeys[2] == KEY_LEFT)
  600. {
  601. ButtonInfo[buttonid][Pos][0] -= Move_Cos;
  602. ButtonInfo[buttonid][Pos][1] += Move_Sin;
  603. }
  604. else if (PlayerKeys[2] == KEY_RIGHT)
  605. {
  606. ButtonInfo[buttonid][Pos][0] += Move_Cos;
  607. ButtonInfo[buttonid][Pos][1] -= Move_Sin;
  608. }
  609. format
  610. (
  611. String,
  612. sizeof(String),
  613. "~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~w~Moving buttonid ~r~%d ~n~~w~X=~r~%.2f ~w~Y=~r~%.2f",
  614. buttonid,
  615. ButtonInfo[buttonid][Pos][0],
  616. ButtonInfo[buttonid][Pos][1]
  617. );
  618. GameTextForPlayer(playerid, String, 1500, 3);
  619. }
  620. FS_SetButtonPos
  621. (
  622. buttonid,
  623. ButtonInfo[buttonid][Pos][0],
  624. ButtonInfo[buttonid][Pos][1],
  625. ButtonInfo[buttonid][Pos][2],
  626. ButtonInfo[buttonid][Pos][3]
  627. );
  628. }
  629. }
  630. #endif
  631. /*----------------------------------------------------------------------------*/