Advertisement
AwDod

3dmenu.inc

Oct 24th, 2023
688
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 13.45 KB | None | 0 0
  1. an example:
  2. #define FILTERSCRIPT
  3. #include <a_samp>
  4. #include <streamer>
  5. #include <3DMenu>
  6.  
  7. public OnFilterScriptInit()
  8. {
  9.     new Float:p[4];
  10.     GetPlayerPos(0,p[0],p[1],p[2]);
  11.     GetPlayerFacingAngle(0,p[3]);
  12.     if(Create3DMenu(0,p[0],p[1],p[2],p[3],8))
  13.     {
  14.         for(new i = 0; i < 8; i++) SetBoxText(0,i,"I'm a selectable box!",OBJECT_MATERIAL_SIZE_256x64,"Impact",32,false,0xFFFFFFFF,0xFF0000FF,0xFFFF0000,OBJECT_MATERIAL_TEXT_ALIGN_CENTER);
  15.         Select3DMenu(0);
  16.     }
  17.     return 1;
  18. }
  19.  
  20. public OnPlayerSelect3DMenuBox(playerid,boxid)
  21. {
  22.    SetBoxText(playerid,boxid,"You've selected me!\nWheee!",OBJECT_MATERIAL_SIZE_256x64,"Impact",32,false,0xFFFFFFFF,0xFF0000FF,0xFFFF0000,OBJECT_MATERIAL_TEXT_ALIGN_CENTER);
  23.    return 1;
  24. }
  25.  
  26. public OnPlayerChange3DMenuBox(playerid,boxid)
  27. {
  28.     new str[16];
  29.     format(str,64,"Box id is %d",boxid);
  30.     SendClientMessage(playerid,-1,str);
  31.     return 1;
  32. }
  33.  
  34. //
  35.  
  36.  #define MAX_BOXES (16)
  37. #define MENU3D_KEY_DOWN KEY_NO
  38. #define MENU3D_KEY_UP KEY_YES
  39. #define MENU3D_KEY_SELECT KEY_SPRINT
  40.  
  41. /*
  42. native Create3DMenu(playerid,Float:x,Float:y,Float:z,Float:rotation,boxes);
  43. native SetBoxText(playerid,box,text[],materialsize,fontface[],fontsize,bold,fontcolor,selectcolor,unselectcolor,textalignment);
  44. native Select3DMenu(playerid);
  45. native CancelSelect3DMenu(playerid);
  46. native Destroy3DMenu(playerid);
  47. */
  48.  
  49. forward OnPlayerSelect3DMenuBox(playerid,boxid);
  50. forward OnPlayerChange3DMenuBox(playerid,boxid);
  51.  
  52. new SelectedMenu[MAX_PLAYERS];
  53. new SelectedBox[MAX_PLAYERS];
  54. enum MenuParams
  55. {
  56.     Float:Rotation,Boxes,bool:IsExist,
  57.     Objects[MAX_BOXES],Float:OrigPosX[MAX_BOXES],Float:OrigPosY[MAX_BOXES],Float:OrigPosZ[MAX_BOXES],
  58.     Float:AddingX,Float:AddingY,SelectColor[MAX_BOXES],UnselectColor[MAX_BOXES]
  59. };
  60. new MenuData[MAX_PLAYERS][MenuParams];
  61.  
  62. stock Create3DMenu(playerid,Float:x,Float:y,Float:z,Float:rotation,boxes)
  63. {
  64.     if(boxes > MAX_BOXES || boxes <= 0 || playerid < 0 || !IsPlayerConnected(playerid)) return false;
  65.     if(MenuData[playerid][IsExist]) return false;
  66.     new Float:NextLineX,Float:NextLineY;
  67.     new lineindx,binc;
  68.     MenuData[playerid][Rotation] = rotation;
  69.     MenuData[playerid][Boxes] = boxes;
  70.     MenuData[playerid][AddingX] = 0.25*floatsin(rotation,degrees);
  71.     MenuData[playerid][AddingY] = -floatcos(rotation,degrees)*0.25;
  72.     NextLineX = floatcos(rotation,degrees)+0.05*floatcos(rotation,degrees);
  73.     NextLineY = floatsin(rotation,degrees)+0.05*floatsin(rotation,degrees);
  74.     for(new b = 0; b < boxes; b++)
  75.     {
  76.         if(b%4 == 0 && b != 0) lineindx++,binc+=4;
  77.         MenuData[playerid][Objects][b] = CreateDynamicObject(2661,x+NextLineX*lineindx,y+NextLineY*lineindx,z+1.65-0.55*(b-binc),0,0,rotation,-1,-1,playerid,100.0);
  78.         GetDynamicObjectPos(MenuData[playerid][Objects][b],MenuData[playerid][OrigPosX][b],MenuData[playerid][OrigPosY][b],MenuData[playerid][OrigPosZ][b]);
  79.     }
  80.     MenuData[playerid][IsExist] = true;
  81.     Streamer_Update(playerid);
  82.     return true;
  83. }
  84.  
  85. stock SetBoxText(playerid,box,text[],materialsize,fontface[],fontsize,bold,fontcolor,selectcolor,unselectcolor,textalignment)
  86. {
  87.     if(!MenuData[playerid][IsExist]) return false;
  88.     if(box == MenuData[playerid][Boxes] || box < 0) return false;
  89.     if(MenuData[playerid][Objects][box] == INVALID_OBJECT_ID) return false;
  90.     MenuData[playerid][SelectColor][box] = selectcolor;
  91.     MenuData[playerid][UnselectColor][box] = unselectcolor;
  92.     if(SelectedBox[playerid] == box) SetDynamicObjectMaterialText(MenuData[playerid][Objects][box],0,text,materialsize,fontface,fontsize,bold,fontcolor,selectcolor,textalignment);
  93.     else SetDynamicObjectMaterialText(MenuData[playerid][Objects][box],0,text,materialsize,fontface,fontsize,bold,fontcolor,unselectcolor,textalignment);
  94.     return true;
  95. }
  96.  
  97. stock Select3DMenu(playerid)
  98. {
  99.     if(!IsPlayerConnected(playerid)) return false;
  100.     if(!MenuData[playerid][IsExist]) return false;
  101.     if(SelectedMenu[playerid] != -1) CancelSelect3DMenu(playerid);
  102.     SelectedBox[playerid] = 0;
  103.     new text[128],materialsize,fontface[128],fontsize,bold,fontcolor,backcolor,textalignment;
  104.     GetDynamicObjectMaterialText(MenuData[playerid][Objects][0],0,text,materialsize,fontface,fontsize,bold,fontcolor,backcolor,textalignment);
  105.     SelectedMenu[playerid] = playerid;
  106.     MoveDynamicObject(MenuData[playerid][Objects][0],MenuData[playerid][OrigPosX][0]+MenuData[playerid][AddingX],MenuData[playerid][OrigPosY][0]+MenuData[playerid][AddingY],MenuData[playerid][OrigPosZ][0],1.0);
  107.     SetDynamicObjectMaterialText(MenuData[playerid][Objects][0],0,text,materialsize,fontface,fontsize,bold,fontcolor,MenuData[playerid][SelectColor][0],textalignment);
  108.     return true;
  109. }
  110.  
  111. #if defined FILTERSCRIPT
  112. public OnFilterScriptInit()
  113. {
  114.     for(new i = 0; i < MAX_PLAYERS; i++)
  115.     {
  116.         SelectedMenu[i] = -1;
  117.         SelectedBox[i] = -1;
  118.     }
  119.     for(new i = 0; i < MAX_PLAYERS; i++)
  120.     {
  121.         for(new b = 0; b < MAX_BOXES; b++) MenuData[i][Objects][b] = INVALID_OBJECT_ID;
  122.         MenuData[i][Boxes] = 0;
  123.         MenuData[i][IsExist] = false;
  124.         MenuData[i][AddingX] = 0.0;
  125.         MenuData[i][AddingY] = 0.0;
  126.     }
  127.     if(funcidx("menu3d_OnFilterScriptInit") != -1) return CallLocalFunction("menu3d_OnFilterScriptInit", "");
  128.     return 1;
  129. }
  130. #if defined _ALS_OnFilterScriptInit
  131. #undef OnFilterScriptInit
  132. #else
  133. #define _ALS_OnFilterScriptInit
  134. #endif
  135. #define OnFilterScriptInit menu3d_OnFilterScriptInit
  136. forward menu3d_OnFilterScriptInit();
  137.  
  138. public OnFilterScriptExit()
  139. {
  140.     for(new i = 0; i < MAX_PLAYERS; i++)
  141.     {
  142.         if(MenuData[i][IsExist]) Destroy3DMenu(i);
  143.     }
  144.     if(funcidx("menu3d_OnFilterScriptExit") != -1) return CallLocalFunction("menu3d_OnFilterScriptExit", "");
  145.     return 1;
  146. }
  147. #if defined _ALS_OnFilterScriptExit
  148. #undef OnFilterScriptExit
  149. #else
  150. #define _ALS_OnFilterScriptExit
  151. #endif
  152. #define OnFilterScriptExit menu3d_OnFilterScriptExit
  153. forward menu3d_OnFilterScriptExit();
  154.  
  155. #else
  156. public OnGameModeInit()
  157. {
  158.     for(new i = 0; i < MAX_PLAYERS; i++)
  159.     {
  160.         for(new b = 0; b < MAX_BOXES; b++) MenuData[i][Objects][b] = INVALID_OBJECT_ID;
  161.         MenuData[i][Boxes] = 0;
  162.         MenuData[i][IsExist] = false;
  163.         MenuData[i][AddingX] = 0.0;
  164.         MenuData[i][AddingY] = 0.0;
  165.     }
  166.     if(funcidx("menu3d_OnGameModeInit") != -1) return CallLocalFunction("menu3d_OnGameModeInit", "");
  167.     return 1;
  168. }
  169. #if defined _ALS_OnGameModeInit
  170. #undef OnGameModeInit
  171. #else
  172. #define _ALS_OnGameModeInit
  173. #endif
  174. #define OnGameModeInit menu3d_OnGameModeInit
  175. forward menu3d_OnGameModeInit();
  176.  
  177. public OnGameModeExit()
  178. {
  179.     for(new i = 0; i < MAX_PLAYERS; i++)
  180.     {
  181.         if(MenuData[i][IsExist]) Destroy3DMenu(i);
  182.     }
  183.     if(funcidx("menu3d_OnGameModeExit") != -1) return CallLocalFunction("menu3d_OnGameModeExit", "");
  184.     return 1;
  185. }
  186. #if defined _ALS_OnGameModeExit
  187. #undef OnGameModeExit
  188. #else
  189. #define _ALS_OnGameModeExit
  190. #endif
  191. #define OnGameModeExit menu3d_OnGameModeExit
  192. forward menu3d_OnGameModeExit();
  193.  
  194. #endif
  195. public OnPlayerConnect(playerid)
  196. {
  197.     SelectedMenu[playerid] = -1;
  198.     SelectedBox[playerid] = -1;
  199.     if(funcidx("menu3d_OnPlayerConnect") != -1) return CallLocalFunction("menu3d_OnPlayerConnect", "d",playerid);
  200.     return 1;
  201. }
  202. #if defined _ALS_OnPlayerConnect
  203. #undef OnPlayerConnect
  204. #else
  205. #define _ALS_OnPlayerConnect
  206. #endif
  207. #define OnPlayerConnect menu3d_OnPlayerConnect
  208. forward menu3d_OnPlayerConnect(playerid);
  209.  
  210. public OnPlayerDisconnect(playerid,reason)
  211. {
  212.     if(SelectedMenu[playerid] != -1) CancelSelect3DMenu(playerid);
  213.     if(funcidx("menu3d_OnPlayerDisconnect") != -1) return CallLocalFunction("menu3d_OnPlayerDisconnect", "dd",playerid,reason);
  214.     return 1;
  215. }
  216. #if defined _ALS_OnPlayerDisconnect
  217. #undef OnPlayerDisconnect
  218. #else
  219. #define _ALS_OnPlayerDisconnect
  220. #endif
  221. #define OnPlayerDisconnect menu3d_OnPlayerDisconnect
  222. forward menu3d_OnPlayerDisconnect(playerid, reason);
  223.  
  224. public OnPlayerKeyStateChange(playerid,newkeys,oldkeys)
  225. {
  226.     if(SelectedMenu[playerid] != -1)
  227.     {
  228.         if(newkeys == MENU3D_KEY_DOWN)
  229.         {
  230.             new text[128],materialsize,fontface[32],fontsize,bold,fontcolor,backcolor,textalignment;
  231.             GetDynamicObjectMaterialText(MenuData[playerid][Objects][SelectedBox[playerid]],0,text,materialsize,fontface,fontsize,bold,fontcolor,backcolor,textalignment);
  232.             SetDynamicObjectMaterialText(MenuData[playerid][Objects][SelectedBox[playerid]],0,text,materialsize,fontface,fontsize,bold,fontcolor,MenuData[playerid][UnselectColor][SelectedBox[playerid]],textalignment);
  233.             MoveDynamicObject(MenuData[playerid][Objects][SelectedBox[playerid]],MenuData[playerid][OrigPosX][SelectedBox[playerid]],MenuData[playerid][OrigPosY][SelectedBox[playerid]],MenuData[playerid][OrigPosZ][SelectedBox[playerid]],1.0);
  234.             SelectedBox[playerid]++;
  235.             if(SelectedBox[playerid] == MenuData[playerid][Boxes]) SelectedBox[playerid] = 0;
  236.             MoveDynamicObject(MenuData[playerid][Objects][SelectedBox[playerid]],MenuData[playerid][OrigPosX][SelectedBox[playerid]]+MenuData[playerid][AddingX],MenuData[playerid][OrigPosY][SelectedBox[playerid]]+MenuData[playerid][AddingY],MenuData[playerid][OrigPosZ][SelectedBox[playerid]],1.0);
  237.             GetDynamicObjectMaterialText(MenuData[playerid][Objects][SelectedBox[playerid]],0,text,materialsize,fontface,fontsize,bold,fontcolor,backcolor,textalignment);
  238.             SetDynamicObjectMaterialText(MenuData[playerid][Objects][SelectedBox[playerid]],0,text,materialsize,fontface,fontsize,bold,fontcolor,MenuData[playerid][SelectColor][SelectedBox[playerid]],textalignment);
  239.             if(funcidx("OnPlayerChange3DMenuBox") != -1) CallLocalFunction("OnPlayerChange3DMenuBox","dd",playerid,SelectedBox[playerid]);
  240.         }
  241.         else if(newkeys == MENU3D_KEY_UP)
  242.         {
  243.             new text[128],materialsize,fontface[32],fontsize,bold,fontcolor,backcolor,textalignment;
  244.             GetDynamicObjectMaterialText(MenuData[playerid][Objects][SelectedBox[playerid]],0,text,materialsize,fontface,fontsize,bold,fontcolor,backcolor,textalignment);
  245.             SetDynamicObjectMaterialText(MenuData[playerid][Objects][SelectedBox[playerid]],0,text,materialsize,fontface,fontsize,bold,fontcolor,MenuData[playerid][UnselectColor][SelectedBox[playerid]],textalignment);
  246.             MoveDynamicObject(MenuData[playerid][Objects][SelectedBox[playerid]],MenuData[playerid][OrigPosX][SelectedBox[playerid]],MenuData[playerid][OrigPosY][SelectedBox[playerid]],MenuData[playerid][OrigPosZ][SelectedBox[playerid]],1.0);
  247.             SelectedBox[playerid]--;
  248.             if(SelectedBox[playerid] < 0) SelectedBox[playerid] = MenuData[playerid][Boxes]-1;
  249.             MoveDynamicObject(MenuData[playerid][Objects][SelectedBox[playerid]],MenuData[playerid][OrigPosX][SelectedBox[playerid]]+MenuData[playerid][AddingX],MenuData[playerid][OrigPosY][SelectedBox[playerid]]+MenuData[playerid][AddingY],MenuData[playerid][OrigPosZ][SelectedBox[playerid]],1.0);
  250.             GetDynamicObjectMaterialText(MenuData[playerid][Objects][SelectedBox[playerid]],0,text,materialsize,fontface,fontsize,bold,fontcolor,backcolor,textalignment);
  251.             SetDynamicObjectMaterialText(MenuData[playerid][Objects][SelectedBox[playerid]],0,text,materialsize,fontface,fontsize,bold,fontcolor,MenuData[playerid][SelectColor][SelectedBox[playerid]],textalignment);
  252.             if(funcidx("OnPlayerChange3DMenuBox") != -1) CallLocalFunction("OnPlayerChange3DMenuBox","dd",playerid,SelectedBox[playerid]);
  253.         }
  254.         else if(newkeys == MENU3D_KEY_SELECT)
  255.         {
  256.             if(funcidx("OnPlayerSelect3DMenuBox") != -1) CallLocalFunction("OnPlayerSelect3DMenuBox","dd",playerid,SelectedBox[playerid]);
  257.         }
  258.     }
  259.     if(funcidx("menu3d_OnPlayerKeyStateChange") != -1) return CallLocalFunction("menu3d_OnPlayerKeyStateChange", "ddd",playerid,newkeys,oldkeys);
  260.     return 1;
  261. }
  262. #if defined _ALS_OnPlayerKeyStateChange
  263. #undef OnPlayerKeyStateChange
  264. #else
  265. #define _ALS_OnPlayerKeyStateChange
  266. #endif
  267. #define OnPlayerKeyStateChange menu3d_OnPlayerKeyStateChange
  268. forward menu3d_OnPlayerKeyStateChange(playerid, newkeys, oldkeys);
  269.  
  270. stock CancelSelect3DMenu(playerid)
  271. {
  272.     if(!IsPlayerConnected(playerid)) return false;
  273.     if(SelectedMenu[playerid] == -1) return false;
  274.     new text[128],materialsize,fontface[32],fontsize,bold,fontcolor,backcolor,textalignment;
  275.     GetDynamicObjectMaterialText(MenuData[playerid][Objects][SelectedBox[playerid]],0,text,materialsize,fontface,fontsize,bold,fontcolor,backcolor,textalignment);
  276.     SetDynamicObjectMaterialText(MenuData[playerid][Objects][SelectedBox[playerid]],0,text,materialsize,fontface,fontsize,bold,fontcolor,MenuData[playerid][UnselectColor][SelectedBox[playerid]],textalignment);
  277.     MoveDynamicObject(MenuData[playerid][Objects][SelectedBox[playerid]],MenuData[playerid][OrigPosX][SelectedBox[playerid]],MenuData[playerid][OrigPosY][SelectedBox[playerid]],MenuData[playerid][OrigPosZ][SelectedBox[playerid]],1.0);
  278.     SelectedMenu[playerid] = -1;
  279.     SelectedBox[playerid] = -1;
  280.     return true;
  281. }
  282.  
  283. stock Destroy3DMenu(playerid)
  284. {
  285.     if(!MenuData[playerid][IsExist]) return false;
  286.     if(SelectedMenu[playerid] == playerid) CancelSelect3DMenu(playerid);
  287.     for(new i = 0; i < MenuData[playerid][Boxes]; i++)
  288.     {
  289.         DestroyDynamicObject(MenuData[playerid][Objects][i]);
  290.         MenuData[playerid][Objects][i] = INVALID_OBJECT_ID;
  291.     }
  292.     MenuData[playerid][Boxes] = 0;
  293.     MenuData[playerid][IsExist] = false;
  294.     MenuData[playerid][AddingX] = 0.0;
  295.     MenuData[playerid][AddingY] = 0.0;
  296.     return true;
  297. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement