· 8 years ago · Feb 10, 2018, 07:42 AM
1//Mapping System by Veetiz
2
3/*
4 System Usage
5 /addobjlist : Add an object to object's list
6 /objlist : View object's list
7 /deleteobjlist : delete an object from list
8 /resetobjlist : reset list
9 /deleteobject : delete a mapped object
10 /resetobject : delete all mapped objects
11
12*/
13
14/*
15 Tables (Objects - Objects List)
16
17
18 CREATE TABLE IF NOT EXISTS `objects` (
19 `obj_id` int(10) NOT NULL,
20 `id` int(11) NOT NULL AUTO_INCREMENT,
21 `posx` float NOT NULL,
22 `posy` float NOT NULL,
23 `posz` float NOT NULL,
24 `rotx` float NOT NULL,
25 `roty` float NOT NULL,
26 `rotz` float NOT NULL,
27 PRIMARY KEY (`id`)
28 );
29
30 CREATE TABLE IF NOT EXISTS `object_list` (
31 `id` int(11) NOT NULL AUTO_INCREMENT,
32 `obj_name` varchar(30) NOT NULL,
33 `obj_id` int(11) NOT NULL,
34 PRIMARY KEY (`id`)
35 );
36*/
37
38
39#include <a_samp>
40#include <sscanf>
41#include <a_mysql>
42#include <foreach>
43#include <zcmd>
44
45#define MAX_OBJLIST (100)
46#define MAX_OBJECT (1000)
47
48#define COLOR_RED (0xFF0000FF)
49#define COLOR_YELLOW (0xFFFF00FF)
50#define COLOR_GREEN (0x00FF00FF)
51
52#define Dialog_ObjList (1)
53
54
55enum E_OBJLIST_INFO
56{
57 oblActive,
58 oblID,
59 oblName[30],
60 oblOId,
61};
62new ObjList[MAX_OBJLIST][E_OBJLIST_INFO];
63
64enum E_OBJECT_INFO
65{
66 objActive,
67 objID,
68 objOID,
69 objObject,
70 Float:objX,
71 Float:objY,
72 Float:objZ,
73 Float:objRX,
74 Float:objRY,
75 Float:objRZ,
76 objInterior,
77};
78new Object[MAX_OBJECT][E_OBJECT_INFO];
79
80new Iterator:ObjList<MAX_OBJLIST>;
81new Iterator:Object<MAX_OBJECT>;
82
83new dbHandle;
84
85public OnFilterScriptInit()
86{
87 print("Object system by Veetiz - Started.");
88
89 dbHandle = mysql_connect("localhost", "root", "object_system", ""); // Change this
90 if(mysql_errno(dbHandle)) print("connection failed.");
91
92 mysql_tquery(dbHandle, "SELECT * FROM object_list", "LoadObjectList");
93 mysql_tquery(dbHandle, "SELECT * FROM objects", "LoadObject");
94 return 1;
95}
96
97//Editing object
98public OnPlayerEditObject(playerid, playerobject, objectid, response, Float:fX, Float:fY, Float:fZ, Float:fRotX, Float:fRotY, Float:fRotZ)
99{
100 new query[150], objid = Iter_Free(Object);
101
102 switch(response)
103 {
104 case EDIT_RESPONSE_CANCEL:
105 {
106 DestroyObject(Object[objid][objObject]);
107 SendClientMessage(playerid, COLOR_YELLOW, "Creation canceled.");
108 }
109 case EDIT_RESPONSE_FINAL:
110 {
111 Object[objid][objX] = fX;
112 Object[objid][objY] = fY;
113 Object[objid][objZ] = fZ;
114 Object[objid][objRX] = fRotX;
115 Object[objid][objRY] = fRotY;
116 Object[objid][objRZ] = fRotZ;
117 Object[objid][objActive] = 1;
118
119 mysql_format(dbHandle, query, sizeof(query), "INSERT INTO objects (obj_id, posx, posy, posz, rotx, roty, rotz) VALUES ('%d', '%f', '%f', '%f', '%f', '%f', '%f')",
120 Object[objid][objOID], fX, fY, fZ, fRotX, fRotY, fRotZ);
121
122 mysql_query(dbHandle, query);
123 Object[objid][objID] = cache_insert_id();
124 Iter_Add(Object, objid);
125
126 SendClientMessage(playerid, COLOR_GREEN, "Object created.");
127 }
128 }
129 return 1;
130}
131
132public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
133{
134 switch(dialogid)
135 {
136 case Dialog_ObjList:
137 {
138 if(!response) return 1;
139 else
140 {
141 new
142 object = Iter_Free(Object),
143 Float:x,
144 Float:y,
145 Float:z;
146
147 new pobject = ObjList[listitem][oblOId];
148 Object[object][objOID] = pobject;
149
150 GetPlayerPos(playerid, x, y, z);
151 Object[object][objObject] = CreateObject(pobject, x + 5, y + 5, z, 0.0, 0.0, 0.0);
152 EditObject(playerid, Object[object][objObject]);
153
154 SendClientMessage(playerid, COLOR_GREEN, "You're creating an Object, click FLOPPY button to save, ESC to cancel.");
155 }
156 }
157 }
158 return 1;
159}
160
161LoadObjectList(); public LoadObjectList()
162{
163 static rows, fields;
164
165 cache_get_data(rows, fields, dbHandle);
166
167 for(new i; i < rows; i++)
168 {
169 ObjList[i][oblID] = cache_get_field_content_int(i, "id");
170 cache_get_field_content(i, "obj_name", ObjList[i][oblName], dbHandle, 30);
171 ObjList[i][oblOId] = cache_get_field_content_int(i, "obj_id");
172 ObjList[i][oblActive] = 1;
173
174 Iter_Add(ObjList, i);
175 }
176 return 1;
177}
178
179LoadObject(); public LoadObject()
180{
181 static rows, fields;
182
183 cache_get_data(rows, fields, dbHandle);
184
185 for(new i; i < rows; i++)
186 {
187 Object[i][objID] = cache_get_field_content_int(i, "id");
188 Object[i][objOID] = cache_get_field_content_int(i, "obj_id");
189 Object[i][objX] = cache_get_field_content_float(i, "posx");
190 Object[i][objY] = cache_get_field_content_float(i, "posy");
191 Object[i][objZ] = cache_get_field_content_float(i, "posz");
192 Object[i][objRX] = cache_get_field_content_float(i, "rotx");
193 Object[i][objRY] = cache_get_field_content_float(i, "roty");
194 Object[i][objRZ] = cache_get_field_content_float(i, "rotz");
195 Object[i][objActive] = 1;
196
197 Object[i][objObject] = CreateObject(Object[i][objOID], Object[i][objX], Object[i][objY], Object[i][objZ], Object[i][objRX], Object[i][objRY], Object[i][objRZ]);
198
199 Iter_Add(Object, i);
200 }
201 return 1;
202}
203
204// Commands
205
206CMD:addobjlist(playerid, params[])
207{
208 new
209 obj = Iter_Free(ObjList),
210 objid,
211 objname[30],
212 query[150];
213
214 if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "You're not a RCON admin!");
215 if(sscanf(params, "ds[30]", objid, objname)) return SendClientMessage(playerid, COLOR_YELLOW, "/addobjlist <id><nome object>");
216 if(obj == MAX_OBJLIST) return SendClientMessage(playerid, COLOR_RED, "Limit reached.");
217
218 ObjList[obj][oblName] = objname;
219 ObjList[obj][oblActive] = 1;
220 ObjList[obj][oblOId] = objid;
221
222 mysql_format(dbHandle, query, sizeof(query), "INSERT INTO object_list (obj_name, obj_id) VALUES ('%s', '%d')", objname, objid);
223 mysql_query(dbHandle, query);
224
225 ObjList[obj][oblID] = cache_insert_id();
226
227 Iter_Add(ObjList, obj);
228
229 return SendClientMessage(playerid, COLOR_GREEN, "Object added to list.");
230}
231
232CMD:deleteobjlist(playerid, params[])
233{
234 new objid, query[60];
235
236 if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "You're not a RCON admin!");
237 if(sscanf(params, "d", objid)) return SendClientMessage(playerid, COLOR_YELLOW, "/deleteobjlist <id>");
238 if(objid > MAX_OBJLIST || objid < 0 || !ObjList[objid][oblActive]) return SendClientMessage(playerid, COLOR_RED, "Invalid object ID.");
239
240 mysql_format(dbHandle, query, sizeof(query), "DELETE FROM object_list WHERE id = '%d'", ObjList[objid][oblID]);
241 mysql_query(dbHandle, query);
242
243 ObjList[objid][oblActive] = 0;
244
245 Iter_Remove(ObjList, objid);
246
247 return SendClientMessage(playerid, COLOR_GREEN, "Object removed from list.");
248}
249
250CMD:resetobjlist(playerid, params[])
251{
252 if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "You're not a RCON admin!");
253
254 foreach(new i : ObjList){ ObjList[i][oblActive] = 0; }
255 Iter_Clear(ObjList);
256
257 mysql_query(dbHandle, "DELETE FROM object_list");
258
259 return SendClientMessage(playerid, COLOR_GREEN, "List cleaned.");
260}
261
262CMD:deleteobject(playerid, params[])
263{
264 new objid, query[60];
265
266 if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "You're not a RCON admin!");
267 if(sscanf(params, "d", objid)) return SendClientMessage(playerid, COLOR_YELLOW, "/deleteobjlist <id>");
268 if(objid > MAX_OBJECT || objid < 0 || !Object[objid][objActive]) return SendClientMessage(playerid, COLOR_RED, "Invalid object ID.");
269
270 DestroyObject(Object[objid][objObject]);
271
272 mysql_format(dbHandle, query, sizeof(query), "DELETE FROM objects WHERE id = '%d'", Object[objid][objID]);
273 mysql_query(dbHandle, query);
274
275 Object[objid][objActive] = 0;
276 Iter_Remove(Object, objid);
277
278 return SendClientMessage(playerid, COLOR_GREEN, "Object removed.");
279}
280
281CMD:resetobject(playerid, params[])
282{
283 if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "You're not a RCON admin!");
284
285 foreach(new i : Object)
286 {
287 Object[i][objActive] = 0;
288 DestroyObject(Object[i][objObject]);
289 }
290 Iter_Clear(Object);
291
292 mysql_query(dbHandle, "DELETE FROM objects");
293
294 return SendClientMessage(playerid, COLOR_GREEN, "Objects removed.");
295}
296
297
298CMD:objlist(playerid, params[])
299{
300 new
301 str[600],
302 string[50];
303
304 if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "You're not a RCON admin!");
305 foreach(new i : ObjList)
306 {
307 format(string, sizeof(string), "%d:%s\n", i, ObjList[i][oblName]);
308 if(ObjList[i][oblActive]) strins(str, string, strlen(str));
309 }
310
311 return ShowPlayerDialog(playerid, Dialog_ObjList, DIALOG_STYLE_LIST, "Object List.", str, "Okay", "");
312}