attachments.pwn 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. #define FILTERSCRIPT
  2. #include <a_samp>
  3. #include <sscanf2>
  4. #include <zcmd>
  5. #include <a_mysql>
  6. #include <mSelection>
  7. //=======CUSTOM SETTINGS=======//
  8. #undef MAX_OBJECTS
  9. #define MAX_OBJECTS 5
  10. #define MINX 0.25
  11. #define MINY 0.25
  12. #define MINZ 0.25
  13. #define MAXX 3.00
  14. #define MAXY 3.00
  15. #define MAXZ 3.00
  16. //=============================//
  17. //===========CHANGES===========//
  18. #define MYSQL_USERS_TABLE "rp_accounts"
  19. #define MYSQL_ID_FIELDNAME "ID"
  20. #define MYSQL_NAME_FIELDNAME "Username"
  21. #define MYSQL_ID_INDEX 0
  22. //=============================//
  23. new objectlist = mS_INVALID_LISTID;
  24. 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 }
  25. new oInfo[MAX_PLAYERS][MAX_OBJECTS][oData];
  26. new inindex[MAX_PLAYERS], inmodel[MAX_PLAYERS], pID[MAX_PLAYERS];
  27. public OnFilterScriptInit()
  28. {
  29. print("\n--------------------------------------");
  30. print(" Advanced Objects System Loaded v2.3");
  31. print(" Editor: Shinja");
  32. print("--------------------------------------\n");
  33. 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)");
  34. objectlist = LoadModelSelectionMenu("objects.txt");
  35. return 1;
  36. }
  37. public OnFilterScriptExit() { mysql_close(); return 1; }
  38. public OnPlayerConnect(playerid)
  39. {
  40. new name[24]; GetPlayerName(playerid, name, 24);
  41. for(new i, j=MAX_OBJECTS; i<j; i++) { oInfo[playerid][i][used1] = false; }
  42. 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);
  43. mysql_tquery(1, query, "LoadPlayerID", "i", playerid);
  44. return 1;
  45. }
  46. forward LoadPlayerID(playerid);
  47. public LoadPlayerID(playerid)
  48. {
  49. if(cache_num_rows())
  50. {
  51. pID[playerid] = cache_get_row_int(0, MYSQL_ID_INDEX);
  52. new query[100];
  53. mysql_format(1, query, sizeof(query), "SELECT * FROM `Objects` WHERE `ID` = %d", pID[playerid]);
  54. mysql_tquery(1, query, "OnObjectLoad", "i", playerid);
  55. }
  56. return 1;
  57. }
  58. forward OnObjectLoad(playerid);
  59. public OnObjectLoad(playerid)
  60. {
  61. for(new i, j=cache_num_rows(); i<j; i++) {
  62. new in = cache_get_row_int(i, 1);
  63. oInfo[playerid][in][index1] = in;
  64. oInfo[playerid][in][modelid1] = cache_get_row_int(i, 2);
  65. oInfo[playerid][in][bone1] = cache_get_row_int(i, 3);
  66. oInfo[playerid][in][fOffsetX1] = cache_get_row_float(i, 4);
  67. oInfo[playerid][in][fOffsetY1] = cache_get_row_float(i, 5);
  68. oInfo[playerid][in][fOffsetZ1] = cache_get_row_float(i, 6);
  69. oInfo[playerid][in][fRotX1] = cache_get_row_float(i, 7);
  70. oInfo[playerid][in][fRotY1] = cache_get_row_float(i, 8);
  71. oInfo[playerid][in][fRotZ1] = cache_get_row_float(i, 9);
  72. oInfo[playerid][in][fScaleX1] = cache_get_row_float(i, 10);
  73. oInfo[playerid][in][fScaleY1] = cache_get_row_float(i, 11);
  74. oInfo[playerid][in][fScaleZ1] = cache_get_row_float(i, 12);
  75. oInfo[playerid][in][used1] = true;
  76. }
  77. }
  78. public OnPlayerSpawn(playerid)
  79. {
  80. 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]); }
  81. return 1;
  82. }
  83. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  84. {
  85. switch(dialogid)
  86. {
  87. case 70:
  88. {
  89. if(!response) return 0;
  90. new string1[10], string2[75]; inindex[playerid] = listitem;
  91. if(oInfo[playerid][listitem][used1] == false) return ShowModelSelectionMenu(playerid, objectlist, "Select An Object");
  92. format(string1, sizeof(string1), "Slot %d", listitem+1);
  93. format(string2, sizeof(string2), "{33FF00}You have {33FF00}Selected slot %d\nDo you wanna remove or edit it?", listitem+1);
  94. ShowPlayerDialog(playerid, 71, DIALOG_STYLE_MSGBOX, string1, string2, "Edit", "Remove");
  95. }
  96. case 71:
  97. {
  98. if(response) return EditAttachedObject(playerid, inindex[playerid]);
  99. RemovePlayerAttachedObject(playerid, inindex[playerid]);
  100. oInfo[playerid][inindex[playerid]][used1] = false;
  101. new string[80], query[100];
  102. format(string, sizeof(string), "You have {FF0000}removed {FFFFFF}this object. Slot %d is now {0DFF00}free!", inindex[playerid]+1);
  103. SendClientMessage(playerid, -1, string);
  104. mysql_format(1, query, sizeof(query), "DELETE FROM `Objects` WHERE `ID` = %d AND `Index` = %d", pID[playerid], inindex[playerid]);
  105. mysql_tquery(1, query);
  106. }
  107. case 72:
  108. {
  109. if(response) {
  110. SetPlayerAttachedObject(playerid, inindex[playerid], inmodel[playerid], listitem+1);
  111. oInfo[playerid][inindex[playerid]][index1] = inindex[playerid];
  112. oInfo[playerid][inindex[playerid]][modelid1] = inmodel[playerid];
  113. oInfo[playerid][inindex[playerid]][bone1] = listitem+1;
  114. oInfo[playerid][inindex[playerid]][used1] = true;
  115. EditAttachedObject(playerid, inindex[playerid]); }
  116. }
  117. }
  118. return 0;
  119. }
  120. public OnPlayerModelSelection(playerid, response, listid, modelid)
  121. {
  122. if(listid == objectlist)
  123. {
  124. if(response)
  125. {
  126. inmodel[playerid] = modelid;
  127. 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");
  128. }
  129. return 1;
  130. }
  131. return 1;
  132. }
  133. CMD:objects(playerid)
  134. {
  135. new string[300], s[40];
  136. format(string, sizeof(string), "{84B4C4}Slot 1\t%s\n", oInfo[playerid][0][used1] == true ? ("{E62E2E}Used") : ("{0DFF00}Empty"));
  137. for(new i=1,j=MAX_OBJECTS; i<j; i++) {
  138. format(s, sizeof(s), "{84B4C4}Slot %d\t%s\n", i+1, oInfo[playerid][i][used1] == true ? ("{E62E2E}Used") : ("{0DFF00}Empty"));
  139. strcat(string, s); }
  140. ShowPlayerDialog(playerid, 70, DIALOG_STYLE_TABLIST, "{33FF00}Objects", string, "Select", "Cancel");
  141. return 1;
  142. }
  143. 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)
  144. {
  145. if(response) {
  146. fScaleX = (fScaleX < MINX) ? (MINX) : ((fScaleX > MAXX) ? (MAXX) : (fScaleX));
  147. fScaleY = (fScaleY < MINY) ? (MINY) : ((fScaleY > MAXY) ? (MAXY) : (fScaleY));
  148. fScaleZ = (fScaleZ < MINZ) ? (MINZ) : ((fScaleZ > MAXZ) ? (MAXZ) : (fScaleZ));
  149. oInfo[playerid][index][fOffsetX1] = fOffsetX;
  150. oInfo[playerid][index][fOffsetY1] = fOffsetY;
  151. oInfo[playerid][index][fOffsetZ1] = fOffsetZ;
  152. oInfo[playerid][index][fRotX1] = fRotX;
  153. oInfo[playerid][index][fRotY1] = fRotY;
  154. oInfo[playerid][index][fRotZ1] = fRotZ;
  155. oInfo[playerid][index][fScaleX1] = fScaleX;
  156. oInfo[playerid][index][fScaleY1] = fScaleY;
  157. oInfo[playerid][index][fScaleZ1] = fScaleZ; }
  158. new query[60];
  159. SendClientMessage(playerid, -1, "Object {0DFF00}Saved!");
  160. 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]);
  161. mysql_format(1, query, sizeof(query), "SELECT * FROM `Objects` WHERE `Index` = %d AND `ID` = %d", index, pID[playerid]);
  162. mysql_tquery(1, query, "OnObjectSave", "iiii", playerid, index, modelid, boneid);
  163. return 1;
  164. }
  165. forward OnObjectSave(playerid, index, modelid, boneid);
  166. public OnObjectSave(playerid, index, modelid, boneid)
  167. {
  168. new query[150];
  169. if(!cache_num_rows()){
  170. 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]);
  171. mysql_tquery(1, query);
  172. 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]);
  173. mysql_tquery(1, query);}
  174. 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]);
  175. mysql_tquery(1, query);
  176. 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]);
  177. mysql_tquery(1, query);
  178. }