Advertisement
Guest User

Untitled

a guest
Aug 26th, 2016
1,449
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.68 KB | None | 0 0
  1. #define FILTERSCRIPT
  2.  
  3. #include <a_samp>
  4. #include <sscanf2>
  5. #include <zcmd>
  6. #include <a_mysql>
  7. #include <mSelection>
  8.  
  9. //=======CUSTOM SETTINGS=======//
  10. #undef MAX_OBJECTS
  11. #define MAX_OBJECTS 5
  12. #define MINX 0.25
  13. #define MINY 0.25
  14. #define MINZ 0.25
  15. #define MAXX 3.00
  16. #define MAXY 3.00
  17. #define MAXZ 3.00
  18. //=============================//
  19.  
  20.  
  21. //===========CHANGES===========//
  22. #define MYSQL_USERS_TABLE "Users"
  23. #define MYSQL_ID_FIELDNAME "ID"
  24. #define MYSQL_NAME_FIELDNAME "Name"
  25. #define MYSQL_ID_INDEX 0
  26. //=============================//
  27.  
  28. new objectlist = mS_INVALID_LISTID;
  29. enum oData { bool:used1, index1, modelid1, bone1, Float:fOffsetX1, Float:fOffsetY1, Float:fOffsetZ1, Float:fRotX1, Float:fRotY1, Float:fRotZ1, Float:fScaleX1, Float:fScaleY1, Float:fScaleZ1 }
  30. new oInfo[MAX_PLAYERS][MAX_OBJECTS][oData];
  31. new inindex[MAX_PLAYERS], inmodel[MAX_PLAYERS], pID[MAX_PLAYERS];
  32.  
  33. public OnFilterScriptInit()
  34. {
  35.     print("\n--------------------------------------");
  36.     print(" Advanced Objects System Loaded v2.3");
  37.     print(" Editor: Shinja");
  38.     print("--------------------------------------\n");
  39.     mysql_tquery(1, "CREATE TABLE IF NOT EXISTS `Objects` (`ID` int(5) NOT NULL,`Index` int(2) NOT NULL,`Model` int(7) NOT NULL,`Bone` int(2) NOT NULL,`OffsetX` float NOT NULL,`OffsetY` float NOT NULL,`OffsetZ` float NOT NULL,`RotX` float NOT NULL,`RotY` float NOT NULL,`RotZ` float NOT NULL,`ScaleX` float NOT NULL,`ScaleY` float NOT NULL,`ScaleZ` float NOT NULL)");
  40.     objectlist = LoadModelSelectionMenu("objects.txt");
  41.     return 1;
  42. }
  43.  
  44. public OnFilterScriptExit() { mysql_close(); return 1; }
  45.  
  46. public OnPlayerConnect(playerid)
  47. {
  48.     new name[24]; GetPlayerName(playerid, name, 24);
  49.     for(new i, j=MAX_OBJECTS; i<j; i++) { oInfo[playerid][i][used1] = false; }
  50.     new query[100]; mysql_format(1, query, sizeof(query), "SELECT `%e` FROM `%e` WHERE `%e` = '%e' LIMIT 1", MYSQL_ID_FIELDNAME, MYSQL_USERS_TABLE, MYSQL_NAME_FIELDNAME, name);
  51.     mysql_tquery(1, query, "LoadPlayerID", "i", playerid);
  52.     return 1;
  53. }
  54.  
  55. forward LoadPlayerID(playerid);
  56. public LoadPlayerID(playerid)
  57. {
  58.     if(cache_num_rows())
  59.     {
  60.         pID[playerid] = cache_get_row_int(0, MYSQL_ID_INDEX);
  61.         new query[100];
  62.         mysql_format(1, query, sizeof(query), "SELECT * FROM `Objects` WHERE `ID` = %d", pID[playerid]);
  63.         mysql_tquery(1, query, "OnObjectLoad", "i", playerid);
  64.     }
  65.     return 1;
  66. }
  67.  
  68. forward OnObjectLoad(playerid);
  69. public OnObjectLoad(playerid)
  70. {
  71.     for(new i, j=cache_num_rows(); i<j; i++) {
  72.         new in = cache_get_row_int(i, 1);
  73.         oInfo[playerid][in][index1] = in;
  74.         oInfo[playerid][in][modelid1] = cache_get_row_int(i, 2);
  75.         oInfo[playerid][in][bone1] = cache_get_row_int(i, 3);
  76.         oInfo[playerid][in][fOffsetX1] = cache_get_row_float(i, 4);
  77.         oInfo[playerid][in][fOffsetY1] = cache_get_row_float(i, 5);
  78.         oInfo[playerid][in][fOffsetZ1] = cache_get_row_float(i, 6);
  79.         oInfo[playerid][in][fRotX1] = cache_get_row_float(i, 7);
  80.         oInfo[playerid][in][fRotY1] = cache_get_row_float(i, 8);
  81.         oInfo[playerid][in][fRotZ1] = cache_get_row_float(i, 9);
  82.         oInfo[playerid][in][fScaleX1] = cache_get_row_float(i, 10);
  83.         oInfo[playerid][in][fScaleY1] = cache_get_row_float(i, 11);
  84.         oInfo[playerid][in][fScaleZ1] = cache_get_row_float(i, 12);
  85.         oInfo[playerid][in][used1] = true;
  86.     }
  87. }
  88.  
  89. public OnPlayerSpawn(playerid)
  90. {
  91.     for(new i,j=MAX_OBJECTS; i<j; i++) { if(oInfo[playerid][i][used1] == true) SetPlayerAttachedObject(playerid, oInfo[playerid][i][index1], oInfo[playerid][i][modelid1], oInfo[playerid][i][bone1], oInfo[playerid][i][fOffsetX1], oInfo[playerid][i][fOffsetY1], oInfo[playerid][i][fOffsetZ1], oInfo[playerid][i][fRotX1], oInfo[playerid][i][fRotY1], oInfo[playerid][i][fRotZ1], oInfo[playerid][i][fScaleX1], oInfo[playerid][i][fScaleY1], oInfo[playerid][i][fScaleZ1]); }
  92.     return 1;
  93. }
  94.  
  95. public  OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  96. {
  97.     switch(dialogid)
  98.     {
  99.         case 70:
  100.         {
  101.             if(!response) return 0;
  102.             new string1[10], string2[75]; inindex[playerid] = listitem;
  103.             if(oInfo[playerid][listitem][used1] == false) return ShowModelSelectionMenu(playerid, objectlist, "Select An Object");
  104.             format(string1, sizeof(string1), "Slot %d", listitem+1);
  105.             format(string2, sizeof(string2), "{33FF00}You have {33FF00}Selected slot %d\nDo you wanna remove or edit it?", listitem+1);
  106.             ShowPlayerDialog(playerid, 71, DIALOG_STYLE_MSGBOX, string1, string2, "Edit", "Remove");
  107.         }
  108.         case 71:
  109.         {
  110.             if(response) return EditAttachedObject(playerid, inindex[playerid]);
  111.             RemovePlayerAttachedObject(playerid, inindex[playerid]);
  112.             oInfo[playerid][inindex[playerid]][used1] = false;
  113.             new string[80], query[100];
  114.             format(string, sizeof(string), "You have {FF0000}removed {FFFFFF}this object. Slot %d is now {0DFF00}free!", inindex[playerid]+1);
  115.             SendClientMessage(playerid, -1, string);
  116.             mysql_format(1, query, sizeof(query), "DELETE FROM `Objects` WHERE `ID` = %d AND `Index` = %d", pID[playerid], inindex[playerid]);
  117.             mysql_tquery(1, query);
  118.         }
  119.         case 72:
  120.         {
  121.             if(response) {
  122.             SetPlayerAttachedObject(playerid, inindex[playerid], inmodel[playerid], listitem+1);
  123.             oInfo[playerid][inindex[playerid]][index1] = inindex[playerid];
  124.             oInfo[playerid][inindex[playerid]][modelid1] = inmodel[playerid];
  125.             oInfo[playerid][inindex[playerid]][bone1] = listitem+1;
  126.             oInfo[playerid][inindex[playerid]][used1] = true;
  127.             EditAttachedObject(playerid, inindex[playerid]); }
  128.         }
  129.     }
  130.     return 0;
  131. }
  132.  
  133. public OnPlayerModelSelection(playerid, response, listid, modelid)
  134. {
  135.     if(listid == objectlist)
  136.     {
  137.         if(response)
  138.         {
  139.             inmodel[playerid] = modelid;
  140.             ShowPlayerDialog(playerid, 72, DIALOG_STYLE_LIST, "{0DFF00}Bone", "Spine\nHead\nLeft Upper Arm\nRight Upper Arm\nLeft Hand\nRight Hand\nLeft Tight\nRight Tight\nLeft Foot\nRight Foot\nRight Calf\nLeft Calf\nLeft Forearm\nRight Forearm\nLeft Shoulder\nRight Shoulder\nNeck\nJaw", "Select", "Cancel");
  141.         }
  142.         return 1;
  143.     }
  144.     return 1;
  145. }
  146.  
  147. CMD:objects(playerid)
  148. {
  149.     new string[300], s[40];
  150.     format(string, sizeof(string), "{84B4C4}Slot 1\t%s\n", oInfo[playerid][0][used1] == true ? ("{E62E2E}Used") : ("{0DFF00}Empty"));
  151.     for(new i=1,j=MAX_OBJECTS; i<j; i++) {
  152.         format(s, sizeof(s), "{84B4C4}Slot %d\t%s\n", i+1, oInfo[playerid][i][used1] == true ? ("{E62E2E}Used") : ("{0DFF00}Empty"));
  153.         strcat(string, s); }
  154.     ShowPlayerDialog(playerid, 70, DIALOG_STYLE_TABLIST, "{33FF00}Objects", string, "Select", "Cancel");
  155.     return 1;
  156. }
  157.  
  158. public OnPlayerEditAttachedObject(playerid, response, index, modelid, boneid, Float:fOffsetX, Float:fOffsetY, Float:fOffsetZ, Float:fRotX, Float:fRotY, Float:fRotZ, Float:fScaleX, Float:fScaleY, Float:fScaleZ)
  159. {
  160.     if(response) {
  161.         fScaleX = (fScaleX < MINX) ? (MINX) : ((fScaleX > MAXX) ? (MAXX) : (fScaleX));
  162.         fScaleY = (fScaleY < MINY) ? (MINY) : ((fScaleY > MAXY) ? (MAXY) : (fScaleY));
  163.         fScaleZ = (fScaleZ < MINZ) ? (MINZ) : ((fScaleZ > MAXZ) ? (MAXZ) : (fScaleZ));
  164.         oInfo[playerid][index][fOffsetX1] = fOffsetX;
  165.         oInfo[playerid][index][fOffsetY1] = fOffsetY;
  166.         oInfo[playerid][index][fOffsetZ1] = fOffsetZ;
  167.         oInfo[playerid][index][fRotX1] = fRotX;
  168.         oInfo[playerid][index][fRotY1] = fRotY;
  169.         oInfo[playerid][index][fRotZ1] = fRotZ;
  170.         oInfo[playerid][index][fScaleX1] = fScaleX;
  171.         oInfo[playerid][index][fScaleY1] = fScaleY;
  172.         oInfo[playerid][index][fScaleZ1] = fScaleZ; }
  173.     new query[60];
  174.     SendClientMessage(playerid, -1, "Object {0DFF00}Saved!");
  175.     SetPlayerAttachedObject(playerid, index, modelid, boneid, oInfo[playerid][index][fOffsetX1], oInfo[playerid][index][fOffsetY1], oInfo[playerid][index][fOffsetZ1], oInfo[playerid][index][fRotX1], oInfo[playerid][index][fRotY1], oInfo[playerid][index][fRotZ1], oInfo[playerid][index][fScaleX1], oInfo[playerid][index][fScaleY1], oInfo[playerid][index][fScaleZ1]);
  176.     mysql_format(1, query, sizeof(query), "SELECT * FROM `Objects` WHERE `Index` = %d AND `ID` = %d", index, pID[playerid]);
  177.     mysql_tquery(1, query, "OnObjectSave", "iiii", playerid, index, modelid, boneid);
  178.     return 1;
  179. }
  180.  
  181. forward OnObjectSave(playerid, index, modelid, boneid);
  182. public OnObjectSave(playerid, index, modelid, boneid)
  183. {
  184.     new query[150];
  185.     if(!cache_num_rows()){
  186.         mysql_format(1, query, sizeof(query), "INSERT INTO `Objects` (`ID`,`Index`,`Model`,`Bone`,`OffsetX`,`OffsetY`,`OffsetZ`) VALUES (%d,%d,%d,%d,%f,%f,%f)",pID[playerid], index, modelid, boneid, oInfo[playerid][index][fOffsetX1], oInfo[playerid][index][fOffsetY1], oInfo[playerid][index][fOffsetZ1]);
  187.         mysql_tquery(1, query);
  188.         mysql_format(1, query, sizeof(query), "UPDATE `Objects` SET `RotX` = %f, `RotY` = %f, `RotZ` = %f, `ScaleX` = %f, `ScaleY` = %f, `ScaleZ` = %f WHERE `ID` = %d AND `Index` = %d",oInfo[playerid][index][fRotX1], oInfo[playerid][index][fRotY1], oInfo[playerid][index][fRotZ1], oInfo[playerid][index][fScaleX1], oInfo[playerid][index][fScaleY1], oInfo[playerid][index][fScaleZ1], pID[playerid], oInfo[playerid][index][index1]);
  189.         mysql_tquery(1, query);}
  190.     mysql_format(1, query, sizeof(query), "UPDATE `Objects` SET `Model` = %d,`Bone` = %d,`OffsetX` = %f,`OffsetY` = %f,`OffsetZ` = %f WHERE `ID` = %d AND `Index` = %d",modelid, boneid, oInfo[playerid][index][fOffsetX1], oInfo[playerid][index][fOffsetY1], oInfo[playerid][index][fOffsetZ1], pID[playerid], oInfo[playerid][index][index1]);
  191.     mysql_tquery(1, query);
  192.     mysql_format(1, query, sizeof(query), "UPDATE `Objects` SET `RotX` = %f, `RotY` = %f, `RotZ` = %f, `ScaleX` = %f, `ScaleY` = %f, `ScaleZ` = %f WHERE `ID` = %d AND `Index` = %d",oInfo[playerid][index][fRotX1], oInfo[playerid][index][fRotY1], oInfo[playerid][index][fRotZ1], oInfo[playerid][index][fScaleX1], oInfo[playerid][index][fScaleY1], oInfo[playerid][index][fScaleZ1], pID[playerid], oInfo[playerid][index][index1]);
  193.     mysql_tquery(1, query);
  194. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement