· 7 years ago · Nov 08, 2018, 12:20 PM
1/**********************************
2 * *
3 * Scripter: CaptainBoi *
4 * Version: 2.2 *
5 * Released: 07-11-2018 *
6 * *
7 **********************************/
8
9/* Includes */
10#include <a_samp>
11#include <a_mysql>
12#include <streamer>
13#include <sscanf2>
14#include <zcmd>
15
16/* MySQL Entities */
17#define MYSQL_HOST "127.0.0.1"
18#define MYSQL_USER "root"
19#define MYSQL_PASS ""
20#define MYSQL_DB "deathmatch"
21
22/* Dialogs */
23#define DIALOG_CONTROL_GPS 100
24#define DIALOG_ADD_GLOC 101
25#define DIALOG_DEL_GLOC 102
26#define DIALOG_TP_GLOC 103
27#define DIALOG_GPS 104
28#define DIALOG_GPS_LOC 105
29
30/* Database */
31new MySQL: GPSDB;
32
33/* Enumerator */
34enum GPSData
35{
36 LocName[14],
37 Float: Pos[3],
38 Interior
39}
40
41/* Variables */
42new gInfo[MAX_PLAYERS][GPSData];
43new GPSMarker[MAX_PLAYERS];
44
45public OnFilterScriptInit()
46{
47 new MySQLOpt: option_id = mysql_init_options();
48 mysql_global_options(DUPLICATE_CONNECTIONS, true);
49 mysql_set_option(option_id, AUTO_RECONNECT, true);
50 GPSDB = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS, MYSQL_DB, option_id);
51
52 if(GPSDB == MYSQL_INVALID_HANDLE || mysql_errno(GPSDB) != 0)
53 {
54 print("Cannot connect to mysql database");
55
56 SendRconCommand("exit");
57 return 1;
58 }
59 else print("Connected to mysql database.");
60
61 mysql_query(GPSDB, "CREATE TABLE IF NOT EXISTS `gpsdb` (\
62 `S.No` INTEGER PRIMARY KEY AUTO_INCREMENT,\
63 `LocationName` VARCHAR(100) NOT NULL,\
64 `PositionX` FLOAT DEFAULT 0,\
65 `PositionY` FLOAT DEFAULT 0,\
66 `PositionZ` FLOAT DEFAULT 0,\
67 `InteriorID` INT)", false);
68 return 1;
69}
70
71public OnFilterScriptExit()
72{
73 mysql_close(GPSDB);
74 return 1;
75}
76
77public OnPlayerConnect(playerid)
78{
79 GPSMarker[playerid] = 0;
80 return 1;
81}
82
83public OnPlayerDisconnect(playerid, reason)
84{
85 GPSMarker[playerid] = 0;
86 return 1;
87}
88
89/* Commands */
90CMD:agps(playerid, params[])
91{
92 ShowPlayerDialog(playerid, DIALOG_CONTROL_GPS, DIALOG_STYLE_TABLIST_HEADERS, "Please select an option.", "\
93 S.No\tOption\t-\tInformation\n\
94 1.\tAdd GPS Location\t-\tYou can add gps location in /gps command.\n\
95 2.\tDelete GPS Location\t-\tYou can remove/delete the gps locations.\n\
96 3.\tGoto GPS Location\t-\tYou can teleport to the gps location.\n\
97 4.\tShow GPS\t-\tYou can see all the locations created in gps.\n\
98 5.\tTurn GPS Off\t-\tYou can turn gps off if its on.", "Select", "Cancel");
99 return 1;
100}
101
102CMD:gps(playerid,params[])
103{
104 ShowPlayerDialog(playerid, DIALOG_GPS, DIALOG_STYLE_TABLIST_HEADERS, "Please select an option.", "\
105 S.No\tOption\t-\tInformation\n\
106 1.\tShow GPS Locations\t-\tYou can see all the available GPS locations.\n\
107 2.\tTurn GPS Off\t-\tYou can turn gps off if its on.", "Select", "Cancel");
108 return 1;
109}
110
111public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
112{
113 new Query[216], Query2[216], string[216], string2[216];
114 if(dialogid == DIALOG_CONTROL_GPS)
115 {
116 if(response)
117 {
118 if(listitem == 0)
119 {
120 SendClientMessage(playerid, 0xFFFF00FF, "Please enter the location name to add it in /gps.");
121 ShowPlayerDialog(playerid, DIALOG_ADD_GLOC, DIALOG_STYLE_INPUT, "Add GPS Location", "Please enter the location name to add it in /gps.", "Add", "Cancel");
122 }
123 if(listitem == 1)
124 {
125 SendClientMessage(playerid, 0xFFFF00FF, "Please enter the location name to remove/delete the location in /gps.");
126 ShowPlayerDialog(playerid, DIALOG_DEL_GLOC, DIALOG_STYLE_INPUT, "Delete GPS Location", "Please enter the location name to remove/delete the location in /gps.", "Delete", "Cancel");
127 }
128 if(listitem == 2)
129 {
130 SendClientMessage(playerid, 0xFFFF00FF, "Please enter the location name to teleport through /gps location.");
131 ShowPlayerDialog(playerid, DIALOG_TP_GLOC, DIALOG_STYLE_INPUT, "Teleport GPS Location", "Please enter the location name to teleport through /gps location.", "Teleport", "Cancel");
132 }
133 if(listitem == 3)
134 {
135 return cmd_gps(playerid, "");
136 }
137 if(listitem == 4)
138 {
139 if (GPSMarker[playerid] == 0) return SendClientMessage(playerid, 0xFF0000FF, "Error: Your GPS is already turned off!");
140 DestroyDynamicMapIcon(GPSMarker[playerid]);
141 GPSMarker[playerid] = 0;
142 SendClientMessage(playerid, 0xFFFF00FF, "You have turned off your GPS.");
143 }
144 }
145 return 1;
146 }
147 if(dialogid == DIALOG_ADD_GLOC)
148 {
149 if(response)
150 {
151 gInfo[playerid][Interior] = GetPlayerInterior(playerid);
152 GetPlayerPos(playerid, gInfo[playerid][Pos][0], gInfo[playerid][Pos][1], gInfo[playerid][Pos][2]);
153 mysql_format(GPSDB, Query, sizeof(Query), "SELECT * FROM `gpsdb` WHERE `LocationName` = '%s'", inputtext);
154
155 new Cache:result = mysql_query(GPSDB, Query, true);
156 mysql_escape_string(inputtext, gInfo[playerid][LocName]);
157 if(cache_num_rows()) return SendClientMessage(playerid, 0xFF0000FF, "Error: That location name is already added.");
158 mysql_format(GPSDB, Query2, sizeof(Query2), "INSERT INTO `gpsdb` (`LocationName`, `PositionX` , `PositionY` , `PositionZ`, `InteriorID`) VALUES ('%s', '%f', '%f', '%f', '%d')", inputtext, gInfo[playerid][Pos][0], gInfo[playerid][Pos][1], gInfo[playerid][Pos][2], gInfo[playerid][Interior]);
159 mysql_query(GPSDB, Query2, false);
160
161 format(string, sizeof(string), "You have added location: %s in /gps.", inputtext);
162 SendClientMessage(playerid, 0xFFFF00FF, string);
163 cache_delete(result);
164 }
165 return 1;
166 }
167 if(dialogid == DIALOG_DEL_GLOC)
168 {
169 if(response)
170 {
171 mysql_format(GPSDB, Query, sizeof(Query),"DELETE FROM `gpsdb` WHERE `LocationName` = '%s'", inputtext);
172 mysql_query(GPSDB, Query, false);
173
174 format(string, sizeof(string), "You have removed gps location: {F3FF02}%s", inputtext);
175 SendClientMessage(playerid, 0xFFFF00FF, string);
176 }
177 return 1;
178 }
179 if(dialogid == DIALOG_TP_GLOC)
180 {
181 if(response)
182 {
183 mysql_format(GPSDB, Query, sizeof(Query), "SELECT * FROM `gpsdb` WHERE `LocationName` = '%s'", inputtext);
184 new Cache:result = mysql_query(GPSDB, Query, true);
185 if(cache_num_rows())
186 {
187 cache_get_value_name(0, "LocationName", gInfo[playerid][LocName]);
188 cache_get_value_name_float(0, "PositionX", gInfo[playerid][Pos][0]);
189 cache_get_value_name_float(0, "PositionY", gInfo[playerid][Pos][1]);
190 cache_get_value_name_float(0, "PositionZ", gInfo[playerid][Pos][2]);
191 cache_get_value_name_int(0, "InteriorID", gInfo[playerid][Interior]);
192 SetPlayerPos(playerid, gInfo[playerid][Pos][0], gInfo[playerid][Pos][1], gInfo[playerid][Pos][2]);
193 format(string, sizeof(string), "You have been teleported to gps location: {F3FF02}'%s'", gInfo[playerid][LocName]);
194 SendClientMessage(playerid, 0xFFFF00FF, string);
195 }
196 else SendClientMessage(playerid, 0xFF0000FF,"Error: The location you entered does not exist.");
197 cache_delete(result);
198 }
199 return 1;
200 }
201 if(dialogid == DIALOG_GPS)
202 {
203 if(response)
204 {
205 if(listitem == 0)
206 {
207 new Cache:result = mysql_query(GPSDB,"SELECT `LocationName` FROM `gpsdb` GROUP BY `S.No`");
208 if(!cache_num_rows())
209 {
210 cache_delete(result);
211 SendClientMessage(playerid, 0xFF0000FF,"Error: There is no gps locations added yet.");
212 return 1;
213 }
214
215 for(new i; i< cache_num_rows(); i++)
216 {
217 cache_get_value_name(i,"LocationName", gInfo[playerid][LocName]);
218 format(string, sizeof(string), "%s%d\t%s\n", string, i, gInfo[playerid][LocName]);
219 }
220 format(string2, sizeof(string2), "S.No\tLocation Name\n%s", string);
221
222 SendClientMessage(playerid, 0xFFFF00FF, "Please select a location.");
223 ShowPlayerDialog(playerid, DIALOG_GPS_LOC, DIALOG_STYLE_TABLIST_HEADERS, "Please select an option.", string2, "Select", "Cancel");
224 cache_delete(result);
225 }
226 if(listitem == 1)
227 {
228 if (GPSMarker[playerid] == 0) return SendClientMessage(playerid, 0xFF0000FF, "Error: Your GPS is already turned off!");
229 DestroyDynamicMapIcon(GPSMarker[playerid]);
230 GPSMarker[playerid] = 0;
231 SendClientMessage(playerid, 0xFFFF00FF, "You have turned off your GPS.");
232 }
233 }
234 return 1;
235 }
236 if(dialogid == DIALOG_GPS_LOC)
237 {
238 if(response)
239 {
240 if (GPSMarker[playerid] != 0)
241 {
242 DestroyDynamicMapIcon(GPSMarker[playerid]);
243 }
244 GPSMarker[playerid] = CreateDynamicMapIcon(gInfo[listitem][Pos][0], gInfo[listitem][Pos][1], gInfo[listitem][Pos][2], 41, 0, -1, -1, playerid, 100000.0);
245 Streamer_SetIntData(STREAMER_TYPE_MAP_ICON, GPSMarker[playerid], E_STREAMER_STYLE, MAPICON_GLOBAL);
246 Streamer_Update(playerid);
247 format(string, sizeof(string), "The location: %s, has been marked on your mini-map.", inputtext);
248 SendClientMessage(playerid, 0xFFFF00FF, string);
249 }
250 return 1;
251 }
252 return 1;
253}
254
255/* Stocks */
256stock playername(playerid)
257{
258 new pname[24];
259 GetPlayerName(playerid, pname, sizeof(pname));
260 return pname;
261}