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