yom_buttons.inc 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /*##############################################################################
  2. #########################################
  3. # #
  4. # BUTTONS - INCLUDE FILE BY YOM #
  5. # Steal my work and die >:D #
  6. # #
  7. #########################################
  8. - Informations about this file:
  9. ===============================
  10. - A set of more or less useful functions related to buttons.
  11. - You must run the Button FS or these function will not work.
  12. - See in the filterscript for more informations
  13. ##############################################################################*/
  14. /*----------------------------------------------------------------------------*/
  15. #define INVALID_BUTTON_ID -1
  16. /*----------------------------------------------------------------------------*/
  17. /*----------------------------------------------------------------------------*/
  18. forward OnPlayerPressButton(playerid, buttonid);
  19. forward OnButtonMoved(buttonid);
  20. /*----------------------------------------------------------------------------*/
  21. /*------------------------------------------------------------------------------
  22. native CreateButton(Float:X, Float:Y, Float:Z, Float:Angle = 0.0);
  23. native DestroyButton(buttonid);
  24. native GetButtonPos(buttonid, &Float:X, &Float:Y, &Float:Z, &Float:Angle = 0.0);
  25. native SetButtonPos(buttonid, Float:X, Float:Y, Float:Z, Float:Angle = 0.0);
  26. native MoveButton(buttonid, Float:X, Float:Y, Float:Z, Float:Speed);
  27. native StopButton(buttonid);
  28. native PrintButtonsInfos();
  29. native bool:IsValidButton(buttonid);
  30. native GetHighestButtonID();
  31. native GetButtonObjectID(buttonid);
  32. native GetObjectButtonID(objectid);
  33. native Float:GetDistanceToButton(buttonid, Float:X, Float:Y, Float:Z);
  34. native Float:GetPlayerDistanceToButton(playerid, buttonid);
  35. native GetClosestButton(Float:X, Float:Y, Float:Z, &Float:Distance = 0.0);
  36. native GetPlayerClosestButton(playerid, &Float:Distance = 0.0);
  37. native ToggleButtonEnabled(buttonid, bool:enabled);
  38. native ToggleButtonEnabledForPlayer(playerid, buttonid, bool:enabled);
  39. native TeleportPlayerToButton(playerid, buttonid);
  40. ------------------------------------------------------------------------------*/
  41. /*----------------------------------------------------------------------------*/
  42. stock CreateButton(Float:X, Float:Y, Float:Z, Float:Angle = 0.0)
  43. return CallRemoteFunction("FS_CreateButton", "ffff", X, Y, Z, Angle);
  44. stock DestroyButton(buttonid)
  45. return CallRemoteFunction("FS_DestroyButton", "i", buttonid);
  46. /*----------------------------------------------------------------------------*/
  47. /*----------------------------------------------------------------------------*/
  48. stock GetButtonPos(buttonid, &Float:X, &Float:Y, &Float:Z, &Float:Angle = 0.0)
  49. {
  50. new objectid = GetButtonObjectID(buttonid);
  51. GetObjectPos(objectid, X, Y, Z);
  52. GetObjectRot(objectid, Angle, Angle, Angle);
  53. }
  54. stock SetButtonPos(buttonid, Float:X, Float:Y, Float:Z, Float:Angle = 0.0)
  55. return CallRemoteFunction("FS_SetButtonPos", "iffff", buttonid, X, Y, Z, Angle);
  56. /*----------------------------------------------------------------------------*/
  57. /*----------------------------------------------------------------------------*/
  58. stock MoveButton(buttonid, Float:X, Float:Y, Float:Z, Float:Speed)
  59. return CallRemoteFunction("FS_MoveButton", "iffff", buttonid, X, Y, Z, Speed);
  60. stock StopButton(buttonid)
  61. return CallRemoteFunction("FS_StopButton", "i", buttonid);
  62. /*----------------------------------------------------------------------------*/
  63. /*----------------------------------------------------------------------------*/
  64. stock PrintButtonsInfos()
  65. return CallRemoteFunction("FS_PrintButtonsInfos", "");
  66. stock bool:IsValidButton(buttonid)
  67. return bool:CallRemoteFunction("FS_IsValidButton", "i", buttonid);
  68. stock GetHighestButtonID()
  69. return CallRemoteFunction("FS_GetHighestButtonID", "");
  70. stock GetButtonObjectID(buttonid)
  71. return CallRemoteFunction("FS_GetButtonObjectID", "i", buttonid);
  72. stock GetObjectButtonID(objectid)
  73. return CallRemoteFunction("FS_GetObjectButtonID", "i", objectid);
  74. /*----------------------------------------------------------------------------*/
  75. /*----------------------------------------------------------------------------*/
  76. stock Float:GetDistanceToButton(buttonid, Float:X, Float:Y, Float:Z)
  77. return Float:CallRemoteFunction("FS_GetDistanceToButton", "ifff", buttonid, X, Y, Z);
  78. stock GetClosestButton(Float:X, Float:Y, Float:Z, &Float:Distance = 0.0)
  79. {
  80. new Closest = INVALID_BUTTON_ID, Float:Distance2 = 100000.0;
  81. for (new buttonid = 1, highest = GetHighestButtonID(); buttonid <= highest; buttonid ++)
  82. {
  83. if (IsValidButton(buttonid))
  84. {
  85. Distance = GetDistanceToButton(buttonid, X, Y, Z);
  86. if (Distance < Distance2)
  87. {
  88. Distance2 = Distance;
  89. Closest = buttonid;
  90. }
  91. }
  92. }
  93. Distance = Distance2;
  94. return Closest;
  95. }
  96. stock ToggleButtonEnabled(buttonid, bool:enabled)
  97. return CallRemoteFunction("FS_ToggleButtonEnabled", "ii", buttonid, enabled);
  98. /*----------------------------------------------------------------------------*/
  99. /*----------------------------------------------------------------------------*/
  100. stock Float:GetPlayerDistanceToButton(playerid, buttonid)
  101. {
  102. new Float:PlayerPos[3];
  103. GetPlayerPos(playerid, PlayerPos[0], PlayerPos[1], PlayerPos[2]);
  104. return GetDistanceToButton(buttonid, PlayerPos[0], PlayerPos[1], PlayerPos[2]);
  105. }
  106. stock GetPlayerClosestButton(playerid, &Float:Distance = 0.0)
  107. {
  108. new Float:PlayerPos[3];
  109. GetPlayerPos(playerid, PlayerPos[0], PlayerPos[1], PlayerPos[2]);
  110. return GetClosestButton(PlayerPos[0], PlayerPos[1], PlayerPos[2], Distance);
  111. }
  112. stock TeleportPlayerToButton(playerid, buttonid)
  113. return CallRemoteFunction("FS_TeleportPlayerToButton", "ii", playerid, buttonid);
  114. stock ToggleButtonEnabledForPlayer(playerid, buttonid, bool:enabled)
  115. return CallRemoteFunction("FS_ToggleButtonEnabledForPlayer", "iii", playerid, buttonid, enabled);
  116. /*----------------------------------------------------------------------------*/