Advertisement
MacMailler

EAO

Oct 3rd, 2012
2,025
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 26.97 KB | None | 0 0
  1. /*
  2. *       SA-MP Editor Attached Objets v1.0 beta
  3. *      
  4. *       За основу был взят стандартный FS attachments.
  5. *
  6. *       Описание:
  7. *           Это редактор пириатаченых объектов. За основу был взят стандартный FS attachments.
  8. *
  9. *       Особенности:
  10. *           Можно крипить объекты к игроку
  11. *           Можно выбрать объект из списка или указать свой ID.
  12. *           Можно крепить объекты на разные части тела.
  13. *           Можно удалять объекты с игрока
  14. *           Можно сохранять данные в sql-таблицу.
  15. *           Автоматическое создание таблицы (если ее нет)
  16. *           Скрипт использует MySQL R6
  17. *           Если выбрали объект который уже есть в базе, то его координаты будут загружены и вы сможете продолжить редактирование.
  18. *
  19. *       Copyright © 2012 MacMiller. All Rights Reserved.
  20. */
  21.  
  22. // Инклуды
  23. #include <a_samp>
  24. #include <a_mysql>
  25. #include <sscanf2>
  26.  
  27.  
  28. // Данные БД
  29. #define bd_HOST                     "localhost"
  30. #define bd_USER                     "root"
  31. #define bd_NAME                     "reality"
  32. #define bd_PASS                     ""
  33.  
  34. #define bd::                        mysql_
  35.  
  36. #define CMD(%0)                     if(strcmp(%0) == 0)
  37.  
  38. // Диалоги
  39. #define D_INDEX                     13500
  40. #define D_ATTACH_SLOT               D_INDEX+100
  41. #define D_ATTACH_EDIT               D_INDEX+200
  42. #define D_ATTACH_BONE               D_INDEX+300
  43. #define D_ATTACH_EXIT               D_INDEX+400
  44. #define D_ATTACH_SAVE               D_INDEX+500
  45. #define D_ATTACH_MODEL              D_INDEX+600
  46.  
  47. #define Send                        SendClientMessage
  48. #define SPD                         ShowPlayerDialog
  49.  
  50. new
  51.     tmp     [512],
  52.     dlgstr  [2048]
  53. ;
  54.  
  55. new
  56.     Text:TD_EAO,
  57.     Text:TD_EAO2
  58. ;
  59.  
  60. enum aEnum
  61. {
  62.     aModel,
  63.     aName[24 char]
  64. }
  65. new AttachObjects[][aEnum] = {
  66.     {18632, !"Удочка"},
  67.     {18633, !"GTASAWrench1"},
  68.     {18634, !"GTASACrowbar1"},
  69.     {18635, !"GTASAHammer1"},
  70.     {18636, !"Кепка мента"},
  71.     {18637, !"PoliceShield"},
  72.     {18638, !"HardHat1"},
  73.     {18639, !"BlackHat1"},
  74.     {18640, !"Hair1"},
  75.     {18975, !"Hair2"},
  76.     {19136, !"Hair4"},
  77.     {19274, !"Hair5"},
  78.     {18641, !"Фонарик"},
  79.     {18642, !"Тазер"},
  80.    
  81.     {18643, !"LaserPointer1"},
  82.     {19080, !"LaserPointer2"},
  83.     {19081, !"LaserPointer3"},
  84.     {19082, !"LaserPointer4"},
  85.     {19083, !"LaserPointer5"},
  86.     {19084, !"LaserPointer6"},
  87.     {18644, !"Screwdriver1"},
  88.     {18645, !"MotorcycleHelmet1"},
  89.    
  90.     {18865, !"MobilePhone1"},
  91.     {18866, !"MobilePhone2"},
  92.     {18867, !"MobilePhone3"},
  93.     {18868, !"MobilePhone4"},
  94.     {18869, !"MobilePhone5"},
  95.     {18870, !"MobilePhone6"},
  96.     {18871, !"MobilePhone7"},
  97.     {18872, !"MobilePhone8"},
  98.     {18873, !"MobilePhone9"},
  99.     {18874, !"MobilePhone10"},
  100.     {18875, !"Pager1"},
  101.     {18890, !"Rake1"},
  102.    
  103.     {18891, !"Бандана1"},
  104.     {18892, !"Бандана2"},
  105.     {18893, !"Бандана3"},
  106.     {18894, !"Бандана4"},
  107.     {18895, !"Бандана5"},
  108.     {18896, !"Бандана6"},
  109.     {18897, !"Бандана7"},
  110.     {18898, !"Бандана8"},
  111.     {18899, !"Бандана9"},
  112.     {18900, !"Бандана10"},
  113.     {18901, !"Bandana11"},
  114.     {18902, !"Бандана12"},
  115.     {18903, !"Бандана13"},
  116.     {18904, !"Бандана14"},
  117.     {18905, !"Бандана15"},
  118.     {18906, !"Бандана16"},
  119.     {18907, !"Бандана17"},
  120.     {18908, !"Бандана18"},
  121.     {18909, !"Бандана19"},
  122.     {18910, !"Бандана20"},
  123.    
  124.     {18911, !"Mask1"},
  125.     {18912, !"Mask2"},
  126.     {18913, !"Mask3"},
  127.     {18914, !"Mask4"},
  128.     {18915, !"Mask5"},
  129.     {18916, !"Mask6"},
  130.     {18917, !"Mask7"},
  131.     {18918, !"Mask8"},
  132.     {18919, !"Mask9"},
  133.     {18920, !"Mask10"},
  134.    
  135.     {18921, !"Beret1"},
  136.     {18922, !"Beret2"},
  137.     {18923, !"Beret3"},
  138.     {18924, !"Beret4"},
  139.     {18925, !"Beret5"},
  140.    
  141.     {18926, !"Hat1"},
  142.     {18927, !"Hat2"},
  143.     {18928, !"Hat3"},
  144.     {18929, !"Hat4"},
  145.     {18930, !"Hat5"},
  146.     {18931, !"Hat6"},
  147.     {18932, !"Hat7"},
  148.     {18933, !"Hat8"},
  149.     {18934, !"Hat9"},
  150.     {18935, !"Hat10"},
  151.    
  152.     {18936, !"Helmet1"},
  153.     {18937, !"Helmet2"},
  154.     {18938, !"Helmet3"},
  155.    
  156.     {18939, !"CapBack1"},
  157.     {18940, !"CapBack2"},
  158.     {18941, !"CapBack3"},
  159.     {18942, !"CapBack4"},
  160.     {18943, !"CapBack5"},
  161.    
  162.     {18944, !"HatBoater1"},
  163.     {18945, !"HatBoater2"},
  164.     {18946, !"HatBoater3"},
  165.     {18947, !"HatBowler1"},
  166.     {18948, !"HatBowler2"},
  167.     {18949, !"HatBowler3"},
  168.     {18950, !"HatBowler4"},
  169.     {18951, !"HatBowler5"},
  170.    
  171.     {18952, !"BoxingHelmet1"},
  172.     {18953, !"CapKnit1"},
  173.     {18954, !"CapKnit2"},
  174.    
  175.     {18955, !"CapOverEye1"},
  176.     {18956, !"CapOverEye2"},
  177.     {18957, !"CapOverEye3"},
  178.     {18958, !"CapOverEye4"},
  179.     {18959, !"CapOverEye5"},
  180.    
  181.     {18960, !"CapRimUp1"},
  182.     {18961, !"CapTrucker1"},
  183.     {18962, !"CowboyHat2"},
  184.     {18963, !"CJElvisHead"},
  185.    
  186.     {18964, !"SkullyCap1"},
  187.     {18965, !"SkullyCap2"},
  188.     {18966, !"SkullyCap3"},
  189.    
  190.     {18967, !"HatMan1"},
  191.     {18968, !"HatMan2"},
  192.     {18969, !"HatMan3"},
  193.    
  194.     {18970, !"HatTiger1"},
  195.    
  196.     {18971, !"HatCool1"},
  197.     {18972, !"HatCool2"},
  198.     {18973, !"HatCool3"},
  199.     {18974, !"MaskZorro1"},
  200.    
  201.     {18976, !"MotorcycleHelmet2"},
  202.     {18977, !"MotorcycleHelmet3"},
  203.     {18978, !"MotorcycleHelmet4"},
  204.     {18979, !"MotorcycleHelmet5"},
  205.    
  206.     {19006, !"Очки 1"},
  207.     {19007, !"Очки 2"},
  208.     {19008, !"Очки 3"},
  209.     {19009, !"Очки 4"},
  210.     {19010, !"Очки 5"},
  211.     {19011, !"Очки 6"},
  212.     {19012, !"Очки 7"},
  213.     {19013, !"Очки 8"},
  214.     {19014, !"Очки 9"},
  215.     {19015, !"Очки 10"},
  216.     {19016, !"Очки 11"},
  217.     {19017, !"Очки 12"},
  218.     {19018, !"Очки 13"},
  219.     {19019, !"Очки 14"},
  220.     {19020, !"Очки 15"},
  221.     {19021, !"Очки 16"},
  222.     {19022, !"Очки 17"},
  223.     {19023, !"Очки 18"},
  224.     {19024, !"Очки 19"},
  225.     {19025, !"Очки 20"},
  226.     {19026, !"Очки 21"},
  227.     {19027, !"Очки 22"},
  228.     {19028, !"Очки 23"},
  229.     {19029, !"Очки 24"},
  230.     {19030, !"Очки 25"},
  231.     {19031, !"Очки 26"},
  232.     {19032, !"Очки 27"},
  233.     {19033, !"Очки 28"},
  234.     {19034, !"Очки 29"},
  235.     {19035, !"Очки 30"},
  236.    
  237.     {19036, !"HockeyMask1"},
  238.     {19037, !"HockeyMask2"},
  239.     {19038, !"HockeyMask3"},
  240.    
  241.     {19039, !"WatchType1"},
  242.     {19040, !"WatchType2"},
  243.     {19041, !"WatchType3"},
  244.     {19042, !"WatchType4"},
  245.     {19043, !"WatchType5"},
  246.     {19044, !"WatchType6"},
  247.     {19045, !"WatchType7"},
  248.     {19046, !"WatchType8"},
  249.     {19047, !"WatchType9"},
  250.     {19048, !"WatchType10"},
  251.     {19049, !"WatchType11"},
  252.     {19050, !"WatchType12"},
  253.     {19051, !"WatchType13"},
  254.     {19052, !"WatchType14"},
  255.     {19053, !"WatchType15"},
  256.    
  257.     {19085, !"EyePatch1"},
  258.     {19086, !"ChainsawDildo1"},
  259.     {19090, !"PomPomBlue"},
  260.     {19091, !"PomPomRed"},
  261.     {19092, !"PomPomGreen"},
  262.     {19093, !"HardHat2"},
  263.     {19094, !"BurgerShotHat1"},
  264.     {19095, !"CowboyHat1"},
  265.     {19096, !"CowboyHat3"},
  266.     {19097, !"CowboyHat4"},
  267.     {19098, !"CowboyHat5"},
  268.     {19099, !"PoliceCap2"},
  269.     {19100, !"PoliceCap3"},
  270.     {19101, !"ArmyHelmet1"},
  271.     {19102, !"ArmyHelmet2"},
  272.     {19103, !"ArmyHelmet3"},
  273.     {19104, !"ArmyHelmet4"},
  274.     {19105, !"ArmyHelmet5"},
  275.     {19106, !"ArmyHelmet6"},
  276.     {19107, !"ArmyHelmet7"},
  277.     {19108, !"ArmyHelmet8"},
  278.     {19109, !"ArmyHelmet9"},
  279.     {19110, !"ArmyHelmet10"},
  280.     {19111, !"ArmyHelmet11"},
  281.     {19112, !"ArmyHelmet12"},
  282.     {19113, !"SillyHelmet1"},
  283.     {19114, !"SillyHelmet2"},
  284.     {19115, !"SillyHelmet3"},
  285.     {19116, !"PlainHelmet1"},
  286.     {19117, !"PlainHelmet2"},
  287.     {19118, !"PlainHelmet3"},
  288.     {19119, !"PlainHelmet4"},
  289.     {19120, !"PlainHelmet5"},
  290.     {19137, !"CluckinBellHat1"},
  291.     {19138, !"PoliceGlasses1"},
  292.     {19139, !"PoliceGlasses2"},
  293.     {19140, !"PoliceGlasses3"},
  294.     {19141, !"SWATHelmet1"},
  295.     {19142, !"SWATArmour1"},
  296.     {19160, !"HardHat3"},
  297.     {19161, !"PoliceHat1"},
  298.     {19162, !"PoliceHat2"},
  299.     {19163, !"GimpMask1"},
  300.     {19317, !"bassguitar01"},
  301.     {19318, !"flyingv01"},
  302.     {19319, !"warlock01"},
  303.     {19330, !"fire_hat01"},
  304.     {19331, !"fire_hat02"},
  305.     {19346, !"hotdog01"},
  306.     {19347, !"badge01"},
  307.     {19348, !"cane01"},
  308.     {19349, !"monocle01"},
  309.     {19350, !"moustache01"},
  310.     {19351, !"moustache02"},
  311.     {19352, !"tophat01"},
  312.     {19487, !"tophat02"},
  313.     {19488, !"HatBowler6"},
  314.     {19513, !"whitephone"}
  315. };
  316.  
  317. enum boneInfo
  318. {
  319.     bID,
  320.     bName[24 char]
  321. }
  322. new Bones[][boneInfo] = {
  323.     {1,  !"Торс"},
  324.     {2,  !"Голова"},
  325.     {3,  !"Левое плечо"},
  326.     {4,  !"Правое плечо"},
  327.     {5,  !"Левая рука"},
  328.     {6,  !"Правая рука"},
  329.     {7,  !"Левое бедро"},
  330.     {8,  !"Правое бедро"},
  331.     {9,  !"Левая нога"},
  332.     {10, !"Правая нога"},
  333.     {11, !"Правая голень"},
  334.     {12, !"Левая голень"},
  335.     {13, !"Левое предплечье"},
  336.     {14, !"Правое предплечье"},
  337.     {15, !"Левая ключица"},
  338.     {16, !"Правая ключица"},
  339.     {17, !"Шея"},
  340.     {18, !"Челюсть"}
  341. };
  342.  
  343. new Table[][64 char] = {
  344.     {!"CREATE TABLE IF NOT EXISTS `AttachObj` ("},
  345.     {!"  `Skin` int(11) NOT NULL DEFAULT '1',"},
  346.     {!"  `Slot` int(11) NOT NULL DEFAULT '0',"},
  347.     {!"  `Model` int(11) NOT NULL DEFAULT '18632',"},
  348.     {!"  `Bone` int(11) NOT NULL DEFAULT '1',"},
  349.     {!"  `objOffset` varchar(256) NOT NULL DEFAULT '0.0,0.0,0.0',"},
  350.     {!"  `objRot` varchar(256) NOT NULL DEFAULT '0.0,0.0,0.0',"},
  351.     {!"  `objScale` varchar(256) NOT NULL DEFAULT '0.0,0.0,0.0'"},
  352.     {!") ENGINE=MyISAM DEFAULT CHARSET=utf8;"}
  353. };
  354.  
  355.  
  356. public OnFilterScriptInit()
  357. {
  358.     if(!IsDBConnection()) sqlConnect();
  359.    
  360.     for(new i; i < sizeof(Table); i++)
  361.     {
  362.         strunpack(tmp, Table[i], sizeof(tmp));
  363.         strcat(dlgstr, tmp);
  364.     }
  365.    
  366.     bd::query(dlgstr); bd::free_result();
  367.    
  368.     TD_EAO = TextDrawCreate(320.000, 410.000, "~b~Editor Attached Objects");
  369.     TextDrawAlignment(TD_EAO, 2);
  370.     TextDrawBackgroundColor(TD_EAO, 0x000000ff);
  371.     TextDrawFont(TD_EAO, 0);
  372.     TextDrawLetterSize(TD_EAO, 0.6, 1.8);
  373.     TextDrawColor(TD_EAO, 0xffffffff);
  374.     TextDrawSetShadow(TD_EAO, 1);
  375.     TextDrawSetOutline(TD_EAO, 1);
  376.     TextDrawSetProportional(TD_EAO,1);
  377.    
  378.     TD_EAO2 = TextDrawCreate(320.000, 428, "~r~Use command  /attach");
  379.     TextDrawAlignment(TD_EAO2, 2);
  380.     TextDrawBackgroundColor(TD_EAO2, 0x000000ff);
  381.     TextDrawFont(TD_EAO2, 1);
  382.     TextDrawLetterSize(TD_EAO2, 0.3, 1.2);
  383.     TextDrawColor(TD_EAO2, 0xffffffff);
  384.     TextDrawSetShadow(TD_EAO2, 1);
  385.     TextDrawSetOutline(TD_EAO2, 1);
  386.     TextDrawSetProportional(TD_EAO2,1);
  387.    
  388.     TextDrawHideForAll( TD_EAO ); TextDrawShowForAll( TD_EAO );
  389.     TextDrawHideForAll( TD_EAO2 ); TextDrawShowForAll( TD_EAO2 );
  390.    
  391.     ///**************************************************************************
  392.     print("\t_________________________________________________________________");
  393.     print("\t ");
  394.     print("\t|                   Editor Attached Objects                     |");
  395.     print("\t|                     successfully loaded!                      |");
  396.     print("\t|                                                               |");
  397.     print("\t|                        Version: v1.1                          |");
  398.     print("\t|                 Copyright [c] 2012 MacMailler                 |");
  399.     print("\t_________________________________________________________________");
  400.     ///*************************************************************************
  401.    
  402.     return 1;
  403. }
  404.  
  405. public OnFilterScriptExit()
  406. {
  407.     TextDrawDestroy( TD_EAO ); TextDrawDestroy( TD_EAO2 );
  408.     return 1;
  409. }
  410.  
  411. public OnPlayerSpawn(playerid)
  412. {
  413.     TextDrawShowForPlayer(playerid, TD_EAO);
  414.     TextDrawShowForPlayer(playerid, TD_EAO2);
  415.     return 1;
  416. }
  417.  
  418. public OnPlayerCommandText(playerid, cmdtext[])
  419. {
  420.     new cmd[32], params[128];
  421.    
  422.     sscanf(cmdtext, "s[24]s[128]", cmd, params);
  423.    
  424.     CMD(cmd, "/attach", true)
  425.     {
  426.         format(dlgstr, sizeof(dlgstr), "");
  427.         for(new x; x < MAX_PLAYER_ATTACHED_OBJECTS; x++)
  428.         {
  429.             if(IsPlayerAttachedObjectSlotUsed(playerid, x)) format(tmp, sizeof(tmp), "%d\t[ {AA3333}Used{ffffff} ]\n", x);
  430.             else format(tmp, sizeof(tmp), "%d\t[ {33AA33}Free{ffffff} ]\n", x);
  431.             strcat(dlgstr, tmp);
  432.         }
  433.         SPD(playerid, D_ATTACH_SLOT, DIALOG_STYLE_LIST,
  434.         "{FF0000}Выбирете слот для объекта", dlgstr, "Выбор", "Отмена");
  435.         return 1;
  436.     }
  437.    
  438.     CMD(cmd, "/setanim", true)
  439.     {
  440.         if(IsAdmin(playerid, 1338))
  441.         {
  442.             new animlib[24], animname[24];
  443.             if(sscanf(params, "s[24]s[24]", animlib, animname)) return Send(playerid, -1, "Введите: /setanim [animlib] [animname]");
  444.             ApplyAnimation(playerid, animlib, animname, 4.1,0,1,1,1,1); return 1;
  445.         }
  446.         return 1;
  447.     }
  448.    
  449.     return 0;
  450. }
  451.  
  452. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  453. {
  454.     switch(dialogid)
  455.     {
  456.         case D_ATTACH_SLOT:
  457.         {
  458.             if(response)
  459.             {
  460.                 SetPVarInt(playerid, "AttachSlot", listitem);
  461.                 if(IsPlayerAttachedObjectSlotUsed(playerid, listitem))
  462.                 {
  463.                     SPD(playerid, D_ATTACH_EDIT, 0,
  464.                     "{FF0000}Редактирование объекта",
  465.                     "Вы можете изменить объект в этом слоте или удалить!",
  466.                     "Изменить", "Удалить");
  467.                 }
  468.                 else
  469.                 {
  470.                     SPD(playerid, D_ATTACH_SLOT+1, DIALOG_STYLE_LIST,
  471.                     "{FF0000}Объекты",
  472.                     "Ввести свой ID\n\
  473.                     Выбрать из списка", "Выбор", "Отмена");
  474.                 }
  475.             }
  476.         }
  477.         case D_ATTACH_SLOT+1:
  478.         {
  479.             if(response)
  480.             {
  481.                 switch(listitem)
  482.                 {
  483.                     case 0:
  484.                     {
  485.                         SPD(playerid, D_ATTACH_MODEL+1, DIALOG_STYLE_INPUT,
  486.                         "{FF0000}Свой объект",
  487.                         "Введите ID объета который хотите прекрипить к игроку", "Ввод", "Назад");
  488.                     }
  489.                     case 1:
  490.                     {
  491.                         new aname[36]; format(dlgstr, sizeof(dlgstr), "");
  492.                         for(new x; x < sizeof(AttachObjects); x++)
  493.                         {
  494.                             strunpack(aname, AttachObjects[x][aName], sizeof(aname));
  495.                             format(tmp, sizeof(tmp), "%s\n", aname); strcat(dlgstr, tmp);
  496.                         }
  497.                         SPD(playerid, D_ATTACH_MODEL, DIALOG_STYLE_LIST,
  498.                         "{FF0000}Выберете объект", dlgstr, "Выбор", "Назад");
  499.                     }
  500.                 }
  501.             }
  502.             else
  503.             {
  504.                 format(dlgstr, sizeof(dlgstr), "");
  505.                 for(new x; x < MAX_PLAYER_ATTACHED_OBJECTS; x++)
  506.                 {
  507.                     if(IsPlayerAttachedObjectSlotUsed(playerid, x)) format(tmp, sizeof(tmp), "%d\t[ {AA3333}Used{ffffff} ]\n", x);
  508.                     else format(tmp, sizeof(tmp), "%d\t[ {33AA33}Free{ffffff} ]\n", x);
  509.                     strcat(dlgstr, tmp);
  510.                 }
  511.                 SPD(playerid, D_ATTACH_SLOT, DIALOG_STYLE_LIST,
  512.                 "{FF0000}Выбирете слот для объекта", dlgstr, "Выбор", "Отмена");
  513.             }
  514.         }
  515.         case D_ATTACH_EDIT:
  516.         {
  517.             if(response)
  518.             {
  519.                 EditAttachedObject(playerid, GetPVarInt(playerid, "AttachSlot"));
  520.             }
  521.             else
  522.             {
  523.                 SPD(playerid, D_ATTACH_EXIT, DIALOG_STYLE_LIST,
  524.                 "{FF0000}Удалить объект?",
  525.                 "Нет\n\
  526.                 Удалить объект\n\
  527.                 Удалить объект + запись в БД\n\
  528.                 Удалить запись в БД", "Выбор", "Отмена");
  529.             }
  530.         }
  531.         case D_ATTACH_MODEL:
  532.         {
  533.             if(response)
  534.             {
  535.                 new bones[36]; format(dlgstr, sizeof(dlgstr), "");
  536.                 SetPVarInt(playerid, "AttachModel", AttachObjects[listitem][aModel]);
  537.                 for(new x; x < sizeof(Bones); x++)
  538.                 {
  539.                     strunpack(bones, Bones[x][bName], sizeof(bones));
  540.                     format(tmp, sizeof(tmp), "%s\n", bones); strcat(dlgstr, tmp);
  541.                 }
  542.                 SPD(playerid, D_ATTACH_BONE, DIALOG_STYLE_LIST,
  543.                 "{FF0000}Куда прикрепить объект?", dlgstr, "Выбор", "Назад");
  544.             }
  545.             else
  546.             {
  547.                 SPD(playerid, D_ATTACH_SLOT+1, DIALOG_STYLE_LIST,
  548.                 "{FF0000}Объекты",
  549.                 "Ввести свой ID\n\
  550.                 Выбрать из списка", "Выбор", "Отмена");
  551.             }
  552.         }
  553.         case D_ATTACH_MODEL+1:
  554.         {
  555.             if(response)
  556.             {
  557.                 if(!sscanf(inputtext, "i", inputtext[0]))
  558.                 {
  559.                     new bones[36]; format(dlgstr, sizeof(dlgstr), "");
  560.                     SetPVarInt(playerid, "AttachModel", inputtext[0]);
  561.                     for(new x; x < sizeof(Bones); x++)
  562.                     {
  563.                         strunpack(bones, Bones[x][bName], sizeof(bones));
  564.                         format(tmp, sizeof(tmp), "%s\n", bones); strcat(dlgstr, tmp);
  565.                     }
  566.                     SPD(playerid, D_ATTACH_BONE, DIALOG_STYLE_LIST,
  567.                     "{FF0000}Куда прикрепить объект?", dlgstr, "Выбор", "Назад");
  568.                 }
  569.                 else
  570.                 {
  571.                     SPD(playerid, 0, 0,
  572.                     "{FF0000}ERROR", "Произошла ошибка!\nПовторите ввод.", "OK", "");
  573.                 }
  574.             }
  575.             else
  576.             {
  577.                 SPD(playerid, D_ATTACH_SLOT+1, DIALOG_STYLE_LIST,
  578.                 "{FF0000}Объекты",
  579.                 "Ввести свой ID\n\
  580.                 Выбрать из списка", "Выбор", "Отмена");
  581.             }
  582.         }
  583.         case D_ATTACH_BONE:
  584.         {
  585.             if(response)
  586.             {
  587.                 SetPVarInt(playerid, "AttachBone", listitem+1);
  588.                 if(ObjExists(playerid)) LoadObj(playerid);
  589.                 else
  590.                 {
  591.                     SetPlayerAttachedObject
  592.                     (
  593.                         playerid,
  594.                         GetPVarInt(playerid, "AttachSlot"),
  595.                         GetPVarInt(playerid, "AttachModel"),
  596.                         GetPVarInt(playerid, "AttachBone")
  597.                     );
  598.                     EditAttachedObject(playerid, GetPVarInt(playerid, "AttachSlot"));
  599.                 }
  600.             }
  601.             else
  602.             {
  603.                 format(dlgstr, sizeof(dlgstr), "");
  604.                 for(new x; x < MAX_PLAYER_ATTACHED_OBJECTS; x++)
  605.                 {
  606.                     if(IsPlayerAttachedObjectSlotUsed(playerid, x)) format(tmp, sizeof(tmp), "%d\t[ {AA3333}Used{ffffff} ]\n", x);
  607.                     else format(tmp, sizeof(tmp), "%d\t[ {33AA33}Free{ffffff} ]\n", x);
  608.                     strcat(dlgstr, tmp);
  609.                 }
  610.                 SPD(playerid, D_ATTACH_SLOT, DIALOG_STYLE_LIST,
  611.                 "{FF0000}Выбирете слот для объекта", dlgstr, "Выбор", "Отмена");
  612.             }
  613.         }
  614.         case D_ATTACH_EXIT:
  615.         {
  616.             if(response)
  617.             {
  618.                 switch(listitem)
  619.                 {
  620.                     case 0: return 1;
  621.                     case 1:
  622.                     {
  623.                         RemovePlayerAttachedObject(playerid, GetPVarInt(playerid, "AttachSlot"));
  624.                         DeletePVar(playerid, "AttachSlot"); DeletePVar(playerid, "AttachModel");
  625.                         SPD(playerid, 0, 0, "Удаление", "Вы удалили объект!", "OK", "");
  626.                     }
  627.                     case 2:
  628.                     {
  629.                         DeleteObj(playerid);
  630.                         RemovePlayerAttachedObject(playerid, GetPVarInt(playerid, "AttachSlot"));
  631.                         DeletePVar(playerid, "AttachSlot"); DeletePVar(playerid, "AttachModel");
  632.                         SPD(playerid, 0, 0, "Удаление", "Вы полностью удалили объект!", "OK", "");
  633.                     }
  634.                     case 3:
  635.                     {
  636.                         DeleteObj(playerid);
  637.                         SPD(playerid, 0, 0, "Удаление", "Вы удалили запись в БД!", "OK", "");
  638.                     }
  639.                 }
  640.             }
  641.             else
  642.             {
  643.                 EditAttachedObject(playerid, GetPVarInt(playerid, "AttachSlot"));
  644.             }
  645.         }
  646.         case D_ATTACH_SAVE:
  647.         {
  648.             if(response)
  649.             {
  650.                 switch(listitem)
  651.                 {
  652.                     case 0:
  653.                     {
  654.                         SetPlayerAttachedObject
  655.                         (
  656.                             playerid,
  657.                             GetPVarInt(playerid, "AttachSlot"),
  658.                             GetPVarInt(playerid, "AttachModel"),
  659.                             GetPVarInt(playerid, "AttachBone"),
  660.                            
  661.                             GetPVarFloat(playerid, "fOffsetX"),
  662.                             GetPVarFloat(playerid, "fOffsetY"),
  663.                             GetPVarFloat(playerid, "fOffsetZ"),
  664.                            
  665.                             GetPVarFloat(playerid, "fRotX"),
  666.                             GetPVarFloat(playerid, "fRotY"),
  667.                             GetPVarFloat(playerid, "fRotZ"),
  668.                            
  669.                             GetPVarFloat(playerid, "fScaleX"),
  670.                             GetPVarFloat(playerid, "fScaleY"),
  671.                             GetPVarFloat(playerid, "fScaleZ")
  672.                         );
  673.                         SPD(playerid, 0, 0, "{FF0000}Сохранение", "Объект сохранен!", "OK", "");
  674.                     }
  675.                     case 1:
  676.                     {
  677.                         if(ObjExists(playerid)) UpdateObj(playerid); else SaveObj(playerid);
  678.                         SetPlayerAttachedObject
  679.                         (
  680.                             playerid,
  681.                             GetPVarInt(playerid, "AttachSlot"),
  682.                             GetPVarInt(playerid, "AttachModel"),
  683.                             GetPVarInt(playerid, "AttachBone"),
  684.                            
  685.                             GetPVarFloat(playerid, "fOffsetX"),
  686.                             GetPVarFloat(playerid, "fOffsetY"),
  687.                             GetPVarFloat(playerid, "fOffsetZ"),
  688.                            
  689.                             GetPVarFloat(playerid, "fRotX"),
  690.                             GetPVarFloat(playerid, "fRotY"),
  691.                             GetPVarFloat(playerid, "fRotZ"),
  692.                            
  693.                             GetPVarFloat(playerid, "fScaleX"),
  694.                             GetPVarFloat(playerid, "fScaleY"),
  695.                             GetPVarFloat(playerid, "fScaleZ")
  696.                         );
  697.                         SPD(playerid, 0, 0, "{FF0000}Сохранение", "Объект сохранен!", "OK", "");
  698.                     }
  699.                     case 2:
  700.                     {
  701.                         RemovePlayerAttachedObject(playerid, GetPVarInt(playerid, "AttachSlot"));
  702.                         DeletePVar(playerid, "AttachSlot"); DeletePVar(playerid, "AttachModel");
  703.                     }
  704.                 }
  705.             }
  706.             else
  707.             {
  708.                 SetPlayerAttachedObject
  709.                 (
  710.                     playerid,
  711.                     GetPVarInt(playerid, "AttachSlot"),
  712.                     GetPVarInt(playerid, "AttachModel"),
  713.                     GetPVarInt(playerid, "AttachBone"),
  714.                    
  715.                     GetPVarFloat(playerid, "fOffsetX"),
  716.                     GetPVarFloat(playerid, "fOffsetY"),
  717.                     GetPVarFloat(playerid, "fOffsetZ"),
  718.                    
  719.                     GetPVarFloat(playerid, "fRotX"),
  720.                     GetPVarFloat(playerid, "fRotY"),
  721.                     GetPVarFloat(playerid, "fRotZ"),
  722.                    
  723.                     GetPVarFloat(playerid, "fScaleX"),
  724.                     GetPVarFloat(playerid, "fScaleY"),
  725.                     GetPVarFloat(playerid, "fScaleZ")
  726.                 );
  727.                 EditAttachedObject(playerid, GetPVarInt(playerid, "AttachSlot"));
  728.             }
  729.         }
  730.     }
  731.     return 1;
  732. }
  733.  
  734. public OnPlayerEditAttachedObject( playerid, response, index, modelid, boneid,
  735.                                     Float:fOffsetX, Float:fOffsetY, Float:fOffsetZ,
  736.                                     Float:fRotX, Float:fRotY, Float:fRotZ,
  737.                                     Float:fScaleX, Float:fScaleY, Float:fScaleZ )
  738. {
  739.     if(response)
  740.     {
  741.         SetPVarInt(playerid, "AttachSlot", index);
  742.         SetPVarInt(playerid, "AttachModel", modelid);
  743.         SetPVarInt(playerid, "AttachBone", boneid);
  744.        
  745.         SetPVarFloat(playerid, "fOffsetX", fOffsetX);
  746.         SetPVarFloat(playerid, "fOffsetY", fOffsetY);
  747.         SetPVarFloat(playerid, "fOffsetZ", fOffsetZ);
  748.        
  749.         SetPVarFloat(playerid, "fRotX", fRotX);
  750.         SetPVarFloat(playerid, "fRotY", fRotY);
  751.         SetPVarFloat(playerid, "fRotZ", fRotZ);
  752.        
  753.         SetPVarFloat(playerid, "fScaleX", fScaleX);
  754.         SetPVarFloat(playerid, "fScaleY", fScaleY);
  755.         SetPVarFloat(playerid, "fScaleZ", fScaleZ);
  756.        
  757.         SPD(playerid, D_ATTACH_SAVE, DIALOG_STYLE_LIST,
  758.         "{FF0000}Сохранить объект?",
  759.         "Cохранить\n\
  760.         Cохранить + запись в БД\n\
  761.         Нет", "Выбор", "Отмена");
  762.     }
  763.     else
  764.     {
  765.         SetPVarInt(playerid, "AttachSlot", index);
  766.         SetPVarInt(playerid, "AttachModel", modelid);
  767.         SetPVarInt(playerid, "AttachBone", boneid);
  768.         SPD(playerid, D_ATTACH_EXIT, DIALOG_STYLE_LIST,
  769.         "{FF0000}Удалить объект?",
  770.         "Нет\n\
  771.         Удалить объект\n\
  772.         Удалить объект + запись в БД\n\
  773.         Удалить запись в БД", "Выбор", "Отмена");
  774.     }
  775.    
  776.     return 1;
  777. }
  778.  
  779. stock DeleteObj(playerid)
  780. {
  781.     format(tmp, sizeof(tmp), "DELETE FROM `AttachObj` WHERE `Skin`='%i' AND `Model`='%i' AND `Bone`='%i'",
  782.     GetPlayerSkin(playerid), GetPVarInt(playerid, "AttachModel"), GetPVarInt(playerid, "AttachBone"));
  783.     bd::query(tmp); bd::store_result(); return;
  784. }
  785.  
  786. stock UpdateObj(playerid)
  787. {
  788.     new offset[128], rot[128], scale[128];
  789.    
  790.     format(offset, sizeof(offset), "%f,%f,%f", GetPVarFloat(playerid, "fOffsetX"), GetPVarFloat(playerid, "fOffsetY"), GetPVarFloat(playerid, "fOffsetZ"));
  791.     format(rot, sizeof(rot), "%f,%f,%f", GetPVarFloat(playerid, "fRotX"), GetPVarFloat(playerid, "fRotY"), GetPVarFloat(playerid, "fRotZ"));
  792.     format(scale, sizeof(scale), "%f,%f,%f", GetPVarFloat(playerid, "fScaleX"), GetPVarFloat(playerid, "fScaleY"), GetPVarFloat(playerid, "fScaleZ"));
  793.    
  794.     format(tmp, sizeof(tmp), "UPDATE `AttachObj` SET `objOffset`='%s',`objRot`='%s',`objScale`='%s' WHERE `Skin`='%i' AND `Model`='%i' AND `Bone`='%i'",
  795.     offset, rot, scale, GetPlayerSkin(playerid), GetPVarInt(playerid, "AttachModel"), GetPVarInt(playerid, "AttachBone"));
  796.    
  797.     bd::query(tmp); bd::free_result();
  798.    
  799.     return;
  800. }
  801.  
  802. stock SaveObj(playerid)
  803. {
  804.     new offset[128], rot[128], scale[128];
  805.    
  806.     format(offset, sizeof(offset), "%f,%f,%f", GetPVarFloat(playerid, "fOffsetX"), GetPVarFloat(playerid, "fOffsetY"), GetPVarFloat(playerid, "fOffsetZ"));
  807.     format(rot, sizeof(rot), "%f,%f,%f", GetPVarFloat(playerid, "fRotX"), GetPVarFloat(playerid, "fRotY"), GetPVarFloat(playerid, "fRotZ"));
  808.     format(scale, sizeof(scale), "%f,%f,%f", GetPVarFloat(playerid, "fScaleX"), GetPVarFloat(playerid, "fScaleY"), GetPVarFloat(playerid, "fScaleZ"));
  809.    
  810.     format(tmp, sizeof(tmp), "INSERT INTO `AttachObj` (`Skin`,`Slot`,`Model`,`Bone`,`objOffset`,`objRot`,`objScale`)");
  811.     strcat(tmp, " VALUES ('%i','%i','%i','%i','%s','%s','%s')");
  812.    
  813.     format(dlgstr, sizeof(dlgstr), tmp,
  814.     GetPlayerSkin(playerid), GetPVarInt(playerid, "AttachSlot"), GetPVarInt(playerid, "AttachModel"), GetPVarInt(playerid, "AttachBone"),
  815.     offset, rot, scale);
  816.    
  817.     bd::query(dlgstr); bd::free_result();
  818.    
  819.     return;
  820. }
  821.  
  822. stock LoadObj(playerid)
  823. {
  824.     new
  825.         index, modelid, boneid,
  826.         Float:fOffsetX, Float:fOffsetY, Float:fOffsetZ,
  827.         Float:fRotX, Float:fRotY, Float:fRotZ,
  828.         Float:fScaleX, Float:fScaleY, Float:fScaleZ,
  829.         offset[128], rot[128], scale[128]
  830.     ;
  831.    
  832.     format(tmp, sizeof(tmp), "SELECT * FROM `AttachObj` WHERE `Skin`='%i' AND `Model`='%i' AND `Bone`='%i'",
  833.     GetPlayerSkin(playerid), GetPVarInt(playerid, "AttachModel"), GetPVarInt(playerid, "AttachBone"));
  834.     if(bd::query(tmp) && bd::store_result())
  835.     {
  836.         if(bd::num_rows())
  837.         {
  838.             bd::fetch_row_format(dlgstr);
  839.             sscanf
  840.             (
  841.                 dlgstr,
  842.                 "p<|>iiiis[128]s[128]s[128]",
  843.                 dlgstr[0], index, modelid, boneid,
  844.                 offset, rot, scale
  845.             );
  846.            
  847.             sscanf
  848.             (
  849.                 offset,
  850.                 "p<,>fff",
  851.                 fOffsetX, fOffsetY, fOffsetZ
  852.             );
  853.  
  854.             sscanf
  855.             (
  856.                 rot,
  857.                 "p<,>fff",
  858.                 fRotX, fRotY, fRotZ
  859.             );
  860.            
  861.             sscanf
  862.             (
  863.                 scale,
  864.                 "p<,>fff",
  865.                 fScaleX, fScaleY, fScaleZ
  866.             );
  867.            
  868.             SetPlayerAttachedObject
  869.             (
  870.                 playerid,
  871.                 GetPVarInt(playerid, "AttachSlot"), modelid, boneid,
  872.                 fOffsetX, fOffsetY, fOffsetZ,
  873.                 fRotX, fRotY, fRotZ,
  874.                 fScaleX, fScaleY, fScaleZ
  875.             );
  876.            
  877.             EditAttachedObject(playerid, GetPVarInt(playerid, "AttachSlot"));
  878.         }
  879.     }
  880.    
  881.     return;
  882. }
  883.  
  884. stock ObjExists(playerid)
  885. {
  886.     format(tmp, sizeof(tmp), "SELECT * FROM `AttachObj` WHERE `Skin`='%i' AND `Model`='%i' AND `Bone`='%i'",
  887.     GetPlayerSkin(playerid), GetPVarInt(playerid, "AttachModel"), GetPVarInt(playerid, "AttachBone"));
  888.     if(bd::query(tmp) && bd::store_result()) if(bd::num_rows()) return true;
  889.     return false;
  890. }
  891.  
  892. stock sqlConnect()
  893. {
  894.     bd::debug(1);
  895.     bd::connect(bd_HOST, bd_USER, bd_NAME, bd_PASS);
  896.     if(bd::ping() == 1) printf("Подключение к MySQL прошло успешно!");
  897.     else print("Соединение с MySQL не установленно!");
  898.    
  899.     return;
  900. }
  901.  
  902. stock sqlDisconnect()
  903. {
  904.     bd::close();
  905.     if(bd::ping()) print("MySQL не была отключина!");
  906.     else print("MySQL успешно отключина!");
  907.    
  908.     return;
  909. }
  910.  
  911. stock IsDBConnection()
  912. {
  913.     if(bd::ping() == 1) return true;
  914.     return false;
  915. }
  916.  
  917. stock GetObjectName( objectid, array[], len = sizeof array )
  918. {
  919.     for( new i; i < sizeof( AttachObjects ) i++ )
  920.     {
  921.         if( AttachObjects[ i ][ aModel ] == objectid )
  922.         return strunpack( array, AttachObjects[ i ][ aName ], len );
  923.     }
  924.    
  925.     return strunpack( array, !"unknown", len );
  926. }
  927.  
  928. stock GetBoneName( boneid, array[], len = sizeof array )
  929. {
  930.     for( new i; i < sizeof( Bones ); i++ )
  931.     {
  932.         if( Bones[ i ][ bID ] == boneid)
  933.         return strunpack( array, Bones[ i ][ bName ], len );
  934.     }
  935.    
  936.     return strunpack( array, !"unknown", len );
  937. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement