· 6 years ago · Apr 21, 2019, 11:42 PM
1#include <a_samp>
2#include <a_mysql>
3#include <zcmd>
4#include <streamer>
5#include <sscanf2>
6
7//Definicje
8#define INFO_STRING "{FFFFFF}[{00FFFF}InGame-ObjectEditor{FFFFFF}]: "
9
10
11//zmienne
12new MySQL:SQL_ID;
13new query[358];
14public OnFilterScriptInit()
15{
16 if(MySQLInit())
17 {
18 mysql_tquery(SQL_ID, "CREATE TABLE IF NOT EXISTS `objects` ( \
19 `ouid` INT(11) NOT NULL AUTO_INCREMENT,\
20 `modelid` INT(11) NOT NULL,\
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 `isstatic` TINYINT(4) NOT NULL DEFAULT '0',\
28 `mat_0` TEXT NOT NULL COLLATE 'utf8_polish_ci',\
29 `mat_1` TEXT NOT NULL COLLATE 'utf8_polish_ci',\
30 `mat_2` TEXT NOT NULL COLLATE 'utf8_polish_ci',\
31 `mat_3` TEXT NOT NULL COLLATE 'utf8_polish_ci',\
32 `mat_4` TEXT NOT NULL COLLATE 'utf8_polish_ci',\
33 `mat_5` TEXT NOT NULL COLLATE 'utf8_polish_ci',\
34 `mat_6` TEXT NOT NULL COLLATE 'utf8_polish_ci',\
35 `mat_7` TEXT NOT NULL COLLATE 'utf8_polish_ci',\
36 `mat_8` TEXT NOT NULL COLLATE 'utf8_polish_ci',\
37 `mat_9` TEXT NOT NULL COLLATE 'utf8_polish_ci',\
38 `mat_10` TEXT NOT NULL COLLATE 'utf8_polish_ci',\
39 `mat_11` TEXT NOT NULL COLLATE 'utf8_polish_ci',\
40 `mat_12` TEXT NOT NULL COLLATE 'utf8_polish_ci',\
41 `mat_13` TEXT NOT NULL COLLATE 'utf8_polish_ci',\
42 `mat_14` TEXT NOT NULL COLLATE 'utf8_polish_ci',\
43 `mat_15` TEXT NOT NULL COLLATE 'utf8_polish_ci',\
44 PRIMARY KEY (`ouid`))");
45 }
46 return 1;
47}
48
49public OnFilterScriptExit()
50{
51 mysql_close(SQL_ID);
52 return 1;
53}
54
55//KOMENDY
56
57CMD:stworzobjekt(playerid, params[])
58{
59 if(IsPlayerAdmin(playerid))
60 {
61 new modelid;
62 if(sscanf(params, "i", modelid)) SendClientMessage(playerid, -1, INFO_STRING"UŻYJ: /stworzobjekt [ID MODELU]");
63 else if(!IsIDEValid(modelid)) SendClientMessage(playerid, -1, INFO_STRING"Podałeś złe ID objektu.. Sprawdź i wpisz ponownie!!");
64 else
65 {
66 new Float:x, Float:y, Float:z;
67 GetPlayerPos(playerid, x, y, z);
68 GetFrontXYFromPlayer(playerid, 3.0, x, y);
69 CreateNewObject(playerid, modelid, x, y, z, 0.0, 0.0, 0.0);
70 }
71 }
72 return 1;
73}
74
75//Callbacki MySQL
76
77forward OnObjectLoad(playerid);
78public OnObjectLoad(playerid)
79{
80 new obj_mid, obj_ouid, Float:obj_pos[6], string[328];
81 cache_get_value_int(0, "ouid", obj_ouid);
82 cache_get_value_int(0, "modelid", obj_ouid);
83 cache_get_value_float(0, "posx", obj_pos[0]);
84 cache_get_value_float(0, "posy", obj_pos[1]);
85 cache_get_value_float(0, "posz", obj_ouid);
86 return 1;
87}
88
89
90forward OnObjectCreated(playerid);
91public OnObjectCreated(playerid)
92{
93 if(cache_insert_id() < 1) return 1;
94 mysql_format(SQL_ID, query, sizeof query, "SELECT * FROM objects WHERE ouid = '%i' LIMIT 1", cache_insert_id());
95 mysql_tquery(SQL_ID, query, "OnObjectLoad", "i", playerid);
96 return 1;
97}
98
99
100//stocki
101stock MySQLInit()
102{
103 print("[EdytorInGame-Inicjacja] ÅÄ…czenie z bazÄ… MySQL...");
104 mysql_log(ALL);
105 SQL_ID = mysql_connect_file("mysql.ini");
106 if(SQL_ID == MYSQL_INVALID_HANDLE || mysql_errno(SQL_ID) !=0)
107 {
108 print("[EdytorInGame-Inicjacja - Błąd] Nie można było połączyć się z bazą MySQL! Wyłączanie Skryptu...");
109 SendRconCommand("unloadfs EdytorInGame");
110 return 0;
111 }
112 print("[EdytorInGame-Inicjacja - MYSQL] Udało połączyć się z bazą MySQL! Skrypt uruchomiony");
113 return 1;
114}
115
116stock CreateNewObject(playerid, modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz)
117{
118 mysql_format(SQL_ID, query, sizeof query, "INSERT INTO Objects SET modelid = '%i', posx = '%f', posy = '%f', posz = '%f', rotx = '%f', roty = '%f', rotz = '%f'", modelid, x, y, z, rx, ry, rz);
119 mysql_tquery(SQL_ID, query, "OnObjectCreated", "i", playerid);
120 return 1;
121}
122
123stock StreamerUpdateAll() //By Nickk888
124{
125 for(new i, j = GetPlayerPoolSize(); i <= j; i++)
126 if(IsPlayerConnected(i))
127 Streamer_Update(i);
128 return 1;
129}
130
131stock IsIDEValid(input) //By JernejL, edit by Nickk888
132{
133 switch(input)
134 {
135 case 615..661: return true;
136 case 664: return true;
137 case 669..698: return true;
138 case 700..792:return true;
139 case 800..906: return true;
140 case 910..964: return true;
141 case 966..998: return true;
142 case 1000..1193: return true;
143 case 1207..1325: return true;
144 case 1327..1572: return true;
145 case 1574..1698: return true;
146 case 1700..2882: return true;
147 case 2885..3135: return true;
148 case 3167..3175: return true;
149 case 3178: return true;
150 case 3187: return true;
151 case 3193: return true;
152 case 3214: return true;
153 case 3221: return true;
154 case 3241..3244: return true;
155 case 3246:return true;
156 case 3249..3250: return true;
157 case 3252..3253: return true;
158 case 3255..3265: return true;
159 case 3267..3347: return true;
160 case 3350..3415: return true;
161 case 3417..3428: return true;
162 case 3430..3609: return true;
163 case 3612..3783: return true;
164 case 3785..3869: return true;
165 case 3872..3882: return true;
166 case 3884..3888: return true;
167 case 3890..3973: return true;
168 case 3975..4541: return true;
169 case 4550..4762: return true;
170 case 4806..5084: return true;
171 case 5086..5089: return true;
172 case 5105..5375: return true;
173 case 5390..5682:return true;
174 case 5703..6010: return true;
175 case 6035..6253: return true;
176 case 6255..6257: return true;
177 case 6280..6347: return true;
178 case 6349..6525: return true;
179 case 6863..7392: return true;
180 case 7415..7973: return true;
181 case 7978..9193: return true;
182 case 9205..9267: return true;
183 case 9269..9478: return true;
184 case 9482..10310: return true;
185 case 10315..10744: return true;
186 case 10750..11417: return true;
187 case 11420..11753: return true;
188 case 12800..13563: return true;
189 case 13590..13667: return true;
190 case 13672..13890: return true;
191 case 14383..14528: return true;
192 case 14530..14554: return true;
193 case 14556: return true;
194 case 14558..14643: return true;
195 case 14650..14657: return true;
196 case 14660..14695: return true;
197 case 14699..14728: return true;
198 case 14735..14765: return true;
199 case 14770..14856: return true;
200 case 14858..14883: return true;
201 case 14885..14898: return true;
202 case 14900..14903:return true;
203 case 15025..15064: return true;
204 case 16000..16790: return true;
205 case 17000..17474: return true;
206 case 17500..17974: return true;
207 case 17976: return true;
208 case 17978: return true;
209 case 18000..18036: return true;
210 case 18038..18102: return true;
211 case 18104..18105: return true;
212 case 18109: return true;
213 case 18112: return true;
214 case 18200..18859: return true;
215 case 18862..19198: return true;
216 case 19200..19274: return true;
217 case 19277..19595: return true;
218 case 19597..19999: return true;
219 }
220 return false;
221}
222
223stock GetFrontXYFromPlayer(playerid, Float:range, & Float:X2, & Float:Y2) //By Nickk888
224{
225 new Float:R;
226 GetPlayerFacingAngle(playerid, R);
227 X2 += (range * floatsin(-R, degrees));
228 Y2 += (range * floatcos(-R, degrees));
229 return 1;
230}
231
232stock FixDialogInputText(text[]) //By Nickk888
233{
234 new tempstring[158];
235 format(tempstring, 158, text);
236 for(;;)
237 {
238 new linijka = strfind(tempstring, "/n");
239 if(linijka == -1) break;
240 else
241 {
242 strdel(tempstring, linijka, linijka + 2);
243 strins(tempstring, "\n", linijka);
244 }
245 }
246 return tempstring;
247}