· 8 years ago · Mar 17, 2018, 12:56 PM
1#include <a_samp>
2#include <streamer>
3#include <foreach>
4new bool:truckcheck[MAX_PLAYERS];
5new deliveringfor[MAX_PLAYERS];
6new nearshop[MAX_PLAYERS];
7new inshop[MAX_PLAYERS];
8enum stuff3
9{
10 inpickup,
11 Text3D: txt,
12 Text3D: ownr,
13 namef[60],
14 ownerf[60]
15};
16new shopproper[MAX_PLAYERS][stuff4];
17public OnGameModeInit()
18{
19 new shops, tmp2[60], str[128];
20 result = db_query(Database, "SELECT * FROM `Shops`");
21 shops = db_num_rows(result);
22 printf("Loading %d shops...", shops);
23 allshops = shops;
24 while (shops > 0)
25 {
26 db_get_field_assoc(result,"shopid",tmp2,sizeof(tmp2));
27 id = strval(tmp2);
28 db_get_field_assoc(result,"name",tmp2,sizeof(tmp2));
29 format(shopproper[id][namef], 51, "%s", tmp2);
30 db_get_field_assoc(result,"owner",tmp2,sizeof(tmp2));
31 format(shopproper[id][ownerf], 52, "%s", tmp2);
32 db_get_field_assoc(result,"x",tmp2,sizeof(tmp2));
33 x = floatstr(tmp2);
34 db_get_field_assoc(result,"y",tmp2,sizeof(tmp2));
35 y = floatstr(tmp2);
36 db_get_field_assoc(result,"z",tmp2,sizeof(tmp2));
37 z = floatstr(tmp2);
38 shopproper[id][inpickup] = CreateDynamicPickup(1275, 1, x, y, z, 0);
39 format(str, sizeof(str), "OWNER: %s", shopproper[id][namef]);
40 shopproper[id][txt] = CreateDynamic3DTextLabel(str, 0xAD3939FF, x, y, z-0.4, 20, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 1, 0);
41 shopproper[id][ownr] = CreateDynamic3DTextLabel(shopproper[id][ownerf], 0xD490CEFF, x, y, z-0.5, 20, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 1, 0);
42 db_next_row(result);
43 shops--;
44 }
45 return 1;
46}
47public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
48{
49 new str[125], Float:x1, Float:y1, Float:z1, interiorid, vw, DBResult:result;
50 new Float:x2, Float:y2, Float:z2, msg2[256];
51 if((newkeys & KEY_YES) && nearshop[playerid] != -1)
52 {
53 format(str, sizeof(str), "SELECT * FROM `Shops` WHERE `shopid` = %d", nearshop[playerid]);
54 result = db_query(Database, str);
55 db_get_field_assoc(result,"x1",str,sizeof(str));
56 x1 = floatstr(str);
57 db_get_field_assoc(result,"y1",str,sizeof(str));
58 y1 = floatstr(str);
59 db_get_field_assoc(result,"z1",str,sizeof(str));
60 z1 = floatstr(str);
61 db_get_field_assoc(result,"interiorid",str,sizeof(str));
62 interiorid = strval(str);
63 db_get_field_assoc(result,"vw",str,sizeof(str));
64 vw = strval(str);
65 SetPlayerInterior(playerid, interiorid);
66 SetPlayerVirtualWorld(playerid, vw);
67 SetPlayerPos(playerid, x1, y1, z1);
68 inshop[playerid] = nearshop[playerid];
69 format(msg2, sizeof(msg2), "You are now inshop id %i", inshop[playerid]);
70 SendClientMessage(playerid, ERRORCOLOR, msg2);
71 SetTimerEx("nearshoprm", 500, false, "i", playerid);
72 }
73 if((newkeys & KEY_YES) && inshop[playerid] != -1)
74 {
75 format(str, sizeof(str), "SELECT * FROM `Shops` WHERE `shopid` = %d", inshop[playerid]);
76 result = db_query(Database, str);
77 db_get_field_assoc(result,"x",str,sizeof(str));
78 x1 = floatstr(str);
79 db_get_field_assoc(result,"y",str,sizeof(str));
80 y1 = floatstr(str);
81 db_get_field_assoc(result,"z",str,sizeof(str));
82 z1 = floatstr(str);
83 db_get_field_assoc(result,"x2",str,sizeof(str));
84 x2 = floatstr(str);
85 db_get_field_assoc(result,"y2",str,sizeof(str));
86 y2 = floatstr(str);
87 db_get_field_assoc(result,"z2",str,sizeof(str));
88 z2 = floatstr(str);
89 if(IsPlayerInRangeOfPoint(playerid, 3, x2, y2, z2) && inshop[playerid] != -1)
90 {
91 SetPlayerInterior(playerid, 0);
92 SetPlayerVirtualWorld(playerid, 0);
93 SetPlayerPos(playerid, x1, y1, z1);
94 nearshop[playerid] = -1;
95 inshop[playerid] = -1;
96 }
97 }
98 return 1;
99}
100//
101db_query(Database, "CREATE TABLE IF NOT EXISTS `Shops` (`shopid`, `x`, `y`, `z`, `name`,`vw`, `interiorid`, `owner`, `x1`, `y1`, `z1`,`x2`, `y2`, `z2`, `facingan`)");
102//
103CMD:removeshop(playerid, params[])
104{
105 new str[147];
106 if (!AdminCheck(playerid, 5)) return 0;
107 if (nearshop[playerid] == -1) return SendClientMessage(playerid, ERRORCOLOR, "You are not close enough to any shop");
108 format(str, sizeof(str), "DELETE FROM `Shops` WHERE `shopid` = %d", nearshop[playerid]);
109 db_query(Database, str);
110 DestroyDynamicPickup(shopproper[nearshop[playerid]][inpickup]);
111 allshops--;
112 format(str, sizeof(str), "%s has deleted shop (ID:%d)", Name[playerid], nearshop[playerid]);
113 SendMessageToAdmins(4, str);
114 return 1;
115}
116CMD:addshop(playerid, params[])
117{
118 new Float:x, Float:y, Float:z, type;
119 new Float:x1, Float:y1, Float:z1, shopid, name[30], str[128];
120 new vw, DBResult:result, query[1000], Float:facingang;
121 if(!AdminCheck(playerid, 4)) return 0;
122// if(sscanf(params, "iiiffffff", vw, interiorid, pric,x1,y1,z1, x2,y2,z2)) return SendClientMessage(playerid, ERRORCOLOR, "Usage: /addshop [vw] [interiorid] [price] [x] [y] [z] [x2] [y2] [z2]");
123 if(sscanf(params, "is[30]", type, name)) return SendClientMessage(playerid, ERRORCOLOR, "Usage: /addshop [type] [name]");
124 GetPlayerPos(playerid, x,y,z);
125 GetPlayerFacingAngle(playerid, facingang);
126 for (new i = 0; i < MAX_SHOPS; i++)
127 {
128 format(query, sizeof(query), "SELECT * FROM `Shops` WHERE `shopid` = %d", i);
129 result = db_query(Database, query);
130 if (db_num_rows(result) == 0)
131 {
132 shopid = i;
133 break;
134 }
135 db_free_result(result);
136 }
137 for (new m = 0; m < MAX_SHOPS; m++)
138 {
139 format(query, sizeof(query), "SELECT * FROM `Shops` WHERE `vw` = %d", m);
140 result = db_query(Database, query);
141 if (db_num_rows(result) == 0)
142 {
143 vw = m;
144 break;
145 }
146 db_free_result(result);
147 }
148 if(type == 1)
149 {
150 format(query, sizeof(query),"INSERT INTO `Shops` (`shopid`, `x`, `y`, `z`, `name`, `vw`, `interiorid`, `owner`, `x1`, `y1`, `z1`, `x2`, `y2`, `z2` ,`facingan`) VALUES (%d, %.2f, %.2f, %.2f, '%s' ,%d, 6, '%s', 296.919982, -108.071998, 1001.515625, 296.919982, -108.071998, 1001.515625, %.2f)", shopid, x, y, z, DB_Escape(name), vw, DB_Escape(Name[playerid]), facingang);
151 db_query(Database, query);
152 format(query, sizeof(query), "%s has created a shop with name %s(ID:%d) type: Ammunation 3, exit points : %.2f ,%.2f ,%.2f", Name[playerid], name, shopid, x1, y1, z1);
153 SendMessageToAdmins(5, query);
154 shopproper[shopid][inpickup] = CreateDynamicPickup(1275, 1,x, y, z);
155 shopproper[shopid][txt] = CreateDynamic3DTextLabel(name, 0xAD3939FF, x, y, z-0.3, 20, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 1, 0);
156 format(str, sizeof(str), "{D490CE}OWNER: %s", Name[playerid]);
157 shopproper[shopid][ownr] = CreateDynamic3DTextLabel(str, 0xD490CEFF, x, y, z-0.5, 20, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 1, 0);
158 }
159 else if(type == 2)
160 {
161 format(query, sizeof(query),"INSERT INTO `Shops` (`shopid`, `x`, `y`, `z`, `name`, `vw`, `interiorid`, `owner`, `x1`, `y1`, `z1`,`x2`, `y2`, `z2`, `facingan`) VALUES (%d, %.2f, %.2f, %.2f,'%s', %d, 7, '%s', 314.820983, -141.431991, 999.601562, 314.820983, -141.431991, 999.601562, %.2f)", shopid, x, y, z, DB_Escape(name), vw, DB_Escape(Name[playerid]), facingang);
162 db_query(Database, query);
163 format(query, sizeof(query), "%s has created a shop with name %s(ID:%d) type: Ammunation 4, exit points : %.2f ,%.2f ,%.2f", Name[playerid], name, shopid, x1, y1, z1);
164 SendMessageToAdmins(5, query);
165 shopproper[shopid][inpickup] = CreateDynamicPickup(1275, 1,x, y, z);
166 shopproper[shopid][txt] = CreateDynamic3DTextLabel(name, 0xAD3939FF, x, y, z-0.3, 20, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 1, 0);
167 format(str, sizeof(str), "{D490CE}OWNER: %s", Name[playerid]);
168 shopproper[shopid][ownr] = CreateDynamic3DTextLabel(str, 0xD490CEFF, x, y, z-0.5, 20, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 1, 0);
169 allshops++;
170 }
171 else if(type == 3)
172 {
173 format(query, sizeof(query),"INSERT INTO `Shops` (`shopid`, `x`, `y`, `z`, `name`, `vw`, `interiorid`, `owner`, `x1`, `y1`, `z1`,`x2`, `y2`, `z2`, `facingan`) VALUES (%d, %.2f, %.2f, %.2f, '%s',%d, 7, '%s', 833.269775, 10.588416, 1004.179687, 833.269775, 10.588416, 1004.179687, %.2f)", shopid, x, y, z, DB_Escape(name), vw, DB_Escape(Name[playerid]), facingang);
174 db_query(Database, query);
175 format(query, sizeof(query), "%s has created a shop with name %s(ID:%d) type: Ammunation 4, exit points : %.2f ,%.2f ,%.2f", Name[playerid], name, shopid, x1, y1, z1);
176 SendMessageToAdmins(5, query);
177 shopproper[shopid][inpickup] = CreateDynamicPickup(1275, 1,x, y, z);
178 shopproper[shopid][txt] = CreateDynamic3DTextLabel(name, 0xAD3939FF, x, y, z-0.3, 20, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 1, 0);
179 format(str, sizeof(str), "{D490CE}OWNER: %s", Name[playerid]);
180 shopproper[shopid][ownr] = CreateDynamic3DTextLabel(str, 0xD490CEFF, x, y, z-0.5, 20, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 1, 0);
181 allshops++;
182 }
183 else if(type == 4)
184 {
185 format(query, sizeof(query),"INSERT INTO `Shops` (`shopid`, `x`, `y`, `z`, `name`, `vw`, `interiorid`, `owner`, `x1`, `y1`, `z1`,`x2`, `y2`, `z2`, `facingan`) VALUES (%d, %.2f, %.2f, %.2f, '%s',%d, 7, '%s', 314.820983, -141.431991, 999.601562,314.820983, -141.431991, 999.601562, %.2f)", shopid, x, y, z, DB_Escape(name), vw, DB_Escape(Name[playerid]), facingang);
186 db_query(Database, query);
187 format(query, sizeof(query), "%s has created a shop with name %s(ID:%d) type: Ammunation 4, exit points : %.2f ,%.2f ,%.2f", Name[playerid], name, shopid, x1, y1, z1);
188 SendMessageToAdmins(5, query);
189 shopproper[shopid][inpickup] = CreateDynamicPickup(1275, 1,x, y, z);
190 shopproper[shopid][txt] = CreateDynamic3DTextLabel(name, 0xAD3939FF, x, y, z-0.3, 20, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 1, 0);
191 format(str, sizeof(str), "{D490CE}OWNER: %s", Name[playerid]);
192 shopproper[shopid][ownr] = CreateDynamic3DTextLabel(str, 0xD490CEFF, x, y, z-0.5, 20, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 1, 0);
193 allshops++;
194 }
195 else if(type == 5)
196 {
197 format(query, sizeof(query),"INSERT INTO `Shops` (`shopid`, `x`, `y`, `z`, `name`, `vw`, `interiorid`, `owner`, `x1`, `y1`, `z1`,`x2`, `y2`, `z2`, `facingan`) VALUES (%d, %.2f, %.2f, %.2f, '%s',%d, 7, '%s', 314.820983, -141.431991, 999.601562,314.820983, -141.431991, 999.601562, %.2f)", shopid, x, y, z, DB_Escape(name), vw, DB_Escape(Name[playerid]), facingang);
198 db_query(Database, query);
199 format(query, sizeof(query), "%s has created a shop with name %s(ID:%d) type: Ammunation 4, exit points : %.2f ,%.2f ,%.2f", Name[playerid], name, shopid, x1, y1, z1);
200 SendMessageToAdmins(5, query);
201 shopproper[shopid][inpickup] = CreateDynamicPickup(1275, 1,x, y, z);
202 shopproper[shopid][txt] = CreateDynamic3DTextLabel(name, 0xAD3939FF, x, y, z-0.3, 20, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 1, 0);
203 format(str, sizeof(str), "{D490CE}OWNER: %s", Name[playerid]);
204 shopproper[shopid][ownr] = CreateDynamic3DTextLabel(str, 0xD490CEFF, x, y, z-0.5, 20, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 1, 0);
205 allshops++;
206 }
207 return 1;
208}
209public OnPlayerExitVehicle(playerid, vehicleid)
210{
211 switch(GetVehicleModel(vehicleid))
212 {
213 case 455, 515:
214 {
215 SendClientMessage(playerid, ERRORCOLOR, "you are no longer on trucker duty");
216 DisablePlayerCheckpoint(playerid);
217 deliveringfor[playerid] = -1;
218 truckcheck[playerid] = false;
219 }
220 }
221}
222public OnPlayerStateChange(playerid, oldstate, newstate)
223{
224 if (newstate == PLAYER_STATE_DRIVER)
225 {
226 if (GetVehicleModel(vehicleid) == 515 || GetVehicleModel(vehicleid) == 455)
227 {
228 new Float:x, Float:y,Float:z;
229 new query[259], DBResult: result;
230 format(query, sizeof(query), "SELECT * FROM `Shops` ORDER by Random() LIMIT 1");
231 result = db_query(Database, query);
232 SendClientMessage(playerid, ERRORCOLOR, "You are now in trucker");
233 db_get_field_assoc(result, "x", query, sizeof(query));
234 x = floatstr(query);
235 db_get_field_assoc(result, "y", query, sizeof(query));
236 y = floatstr(query);
237 db_get_field_assoc(result, "z", query, sizeof(query));
238 z = floatstr(query);
239 db_get_field_assoc(result, "owner", query, sizeof(query));
240 format(deliveringfor[playerid], 50, "%s", query);
241 SetPlayerCheckpoint(playerid, x, y, z, 7.0);
242 truckcheck[playerid] = true;
243 }
244 }
245}
246public OnPlayerEnterCheckpoint(playerid, checkpointid)
247{
248 if (truckcheck[playerid])
249 {
250 new query[128], DBResult:result;
251 new Float:xf, Float:yf,Float:zf;
252 new idf;
253 GivePlayerMoney(playerid, 5000);
254 idf = GetPlayerID(deliveringfor[playerid]);
255 if(IsPlayerConnected(idf))
256 {
257 SendClientMessage(idf, ERRORCOLOR, "You have taken 10000$ for the delivered packs!");
258 GivePlayerMoney(idf, 10000);
259 }
260 else format(query, sizeof(query),"UPDATE `User` SET `bank` = `bank` + 10000 WHERE Name = '%s'", deliveringfor[playerid]);
261 db_query(Database, query);
262 DisablePlayerCheckpoint(playerid);
263 truckcheck[playerid] = false;
264 format(query, sizeof(query), "SELECT * FROM `Shops` ORDER by Random() LIMIT 1");
265 result = db_query(Database, query);
266 db_get_field_assoc(result, "x", query, sizeof(query));
267 xf = floatstr(query);
268 db_get_field_assoc(result, "y", query, sizeof(query));
269 yf = floatstr(query);
270 db_get_field_assoc(result, "z", query, sizeof(query));
271 zf= floatstr(query);
272 SetPlayerCheckpoint(playerid, xf, yf, zf, 7.0);
273 truckcheck[playerid] = true;
274 db_get_field_assoc(result, "owner", query, sizeof(query));
275 format(deliveringfor[playerid], 50, "%s", query);
276 }
277 return 1;
278}
279public OnPlayerPickupDynamicPickup(playerid, pickupid)
280{
281 for (new i = 0; i < MAX_SHOPS; i++)
282 {
283 if (shopproper[i][inpickup] == pickupid)
284 {
285 SendClientMessage(playerid, ERRORCOLOR, "You are in shop Pickup !");
286 nearshop[playerid] = i;
287 SetTimerEx("removingnear", 1000, false, "i", playerid);
288 break;
289 }
290 }
291}
292forward nearshoprm(playerid);
293public nearshoprm(playerid)
294{
295 nearshop[playerid] = -1;
296 return 1;
297}
298forward removingnear(playerid);
299public removingnear(playerid)
300{
301 nearshop[playerid] = -1;
302 return 1;
303}