· 7 years ago · Nov 08, 2018, 07:22 AM
1/**********************************
2 * *
3 * Scripter: CaptainBoi *
4 * Version: 1.0 *
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[100],
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 if(GPSDB == MYSQL_INVALID_HANDLE || mysql_errno(GPSDB) != 0)
52 {
53 print("Cannot connect to mysql database");
54
55 SendRconCommand("exit");
56 return 1;
57 }
58 else print("Connected to mysql database.");
59
60 mysql_query(GPSDB, "CREATE TABLE IF NOT EXISTS `gpsdb` (\
61 `S.No` INTEGER PRIMARY KEY AUTO_INCREMENT,\
62 `LocationName` VARCHAR(100) NOT NULL,\
63 `PositionX` FLOAT DEFAULT 0,\
64 `PositionY` FLOAT DEFAULT 0,\
65 `PositionZ` FLOAT DEFAULT 0,\
66 `InteriorID` INT)", false);
67 return 1;
68}
69
70public OnFilterScriptExit()
71{
72 mysql_close(GPSDB);
73 return 1;
74}
75
76public OnPlayerConnect(playerid)
77{
78 GPSMarker[playerid] = 0;
79 return 1;
80}
81
82public OnPlayerDisconnect(playerid, reason)
83{
84 GPSMarker[playerid] = 0;
85 return 1;
86}
87
88/* Commands */
89CMD:agps(playerid, params[])
90{
91 ShowPlayerDialog(playerid, DIALOG_CONTROL_GPS, DIALOG_STYLE_TABLIST_HEADERS, "Please select an option.", "\
92 S.No\tOption\t-\tInformation\n\
93 1.\tAdd GPS Location\t-\tYou can add gps location in /gps command.\n\
94 2.\tDelete GPS Location\t-\tYou can remove/delete the gps locations.\n\
95 3.\tGoto GPS Location\t-\tYou can teleport to the gps location.\n\
96 4.\tShow GPS\t-\tYou can see all the locations created in gps.\n\
97 5.\tTurn GPS Off\t-\tYou can turn gps off if its on.", "Select", "Cancel");
98 return 1;
99}
100
101CMD:gps(playerid,params[])
102{
103 ShowPlayerDialog(playerid, DIALOG_GPS, DIALOG_STYLE_TABLIST_HEADERS, "Please select an option.", "\
104 S.No\tOption\t-\tInformation\n\
105 1.\tShow GPS Locations\t-\tYou can see all the available GPS locations.\n\
106 2.\tTurn GPS Off\t-\tYou can turn gps off if its on.", "Select", "Cancel");
107 return 1;
108}
109
110public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
111{
112 new Query[216], Query2[216], string[216], string2[216];
113 if(dialogid == DIALOG_CONTROL_GPS)
114 {
115 if(response)
116 {
117 if(listitem == 0)
118 {
119 SendClientMessage(playerid, 0xFFFF00FF, "Please enter the location name to add it in /gps.");
120 ShowPlayerDialog(playerid, DIALOG_ADD_GLOC, DIALOG_STYLE_INPUT, "Add GPS Location", "Please enter the location name to add it in /gps.", "Add", "Cancel");
121 }
122 if(listitem == 1)
123 {
124 SendClientMessage(playerid, 0xFFFF00FF, "Please enter the location name to remove/delete the location in /gps.");
125 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");
126 }
127 if(listitem == 2)
128 {
129 SendClientMessage(playerid, 0xFFFF00FF, "Please enter the location name to teleport through /gps location.");
130 ShowPlayerDialog(playerid, DIALOG_TP_GLOC, DIALOG_STYLE_INPUT, "Teleport GPS Location", "Please enter the location name to teleport through /gps location.", "Teleport", "Cancel");
131 }
132 if(listitem == 3)
133 {
134 return cmd_gps(playerid, "");
135 }
136 if(listitem == 4)
137 {
138 if (GPSMarker[playerid] == 0) return SendClientMessage(playerid, 0xFF0000FF, "Error: Your GPS is already turned off!");
139 DestroyDynamicMapIcon(GPSMarker[playerid]);
140 GPSMarker[playerid] = 0;
141 SendClientMessage(playerid, 0xFFFF00FF, "You have turned off your GPS.");
142 }
143 }
144 return 1;
145 }
146 if(dialogid == DIALOG_ADD_GLOC)
147 {
148 if(response)
149 {
150 gInfo[playerid][Interior] = GetPlayerInterior(playerid);
151 GetPlayerPos(playerid, gInfo[playerid][Pos][0], gInfo[playerid][Pos][1], gInfo[playerid][Pos][2]);
152 mysql_format(GPSDB, Query, sizeof(Query), "SELECT * FROM `gpsdb` WHERE `LocationName` = '%s'", inputtext);
153 new Cache:result = mysql_query(GPSDB, Query, true);
154
155 if(cache_num_rows()) return SendClientMessage(playerid, 0xFF0000FF, "Error: That location name is already added.");
156 mysql_format(GPSDB, Query2, sizeof(Query2), "INSERT INTO `gpsdb` (`LocationName`, `PositionX` , `PositionY` , `PositionZ`, `InteriorID`) VALUES ('%e', '%f', '%f', '%f', '%d')", inputtext, gInfo[playerid][Pos][0], gInfo[playerid][Pos][1], gInfo[playerid][Pos][2], gInfo[playerid][Interior]);
157 mysql_query(GPSDB, Query2, false);
158
159 format(string, sizeof(string), "You have added location: %s in /gps.", inputtext);
160 SendClientMessage(playerid, 0xFFFF00FF, string);
161 cache_delete(result);
162 }
163 return 1;
164 }
165 if(dialogid == DIALOG_DEL_GLOC)
166 {
167 if(response)
168 {
169 mysql_format(GPSDB, Query, sizeof(Query),"DELETE FROM `gpsdb` WHERE `LocationName` = '%s'", inputtext);
170 mysql_query(GPSDB, Query, false);
171
172 format(string, sizeof(string), "You have removed gps location: {F3FF02}%s", inputtext);
173 SendClientMessage(playerid, 0xFFFF00FF, string);
174 }
175 return 1;
176 }
177 if(dialogid == DIALOG_TP_GLOC)
178 {
179 if(response)
180 {
181 mysql_format(GPSDB, Query, sizeof(Query), "SELECT * FROM `gpsdb` WHERE `LocationName` = '%s'", inputtext);
182 new Cache:result = mysql_query(GPSDB, Query, true);
183 if(cache_num_rows())
184 {
185 cache_get_value_name(0, "LocationName", gInfo[playerid][LocName]);
186 cache_get_value_name_float(0, "PositionX", gInfo[playerid][Pos][0]);
187 cache_get_value_name_float(0, "PositionY", gInfo[playerid][Pos][1]);
188 cache_get_value_name_float(0, "PositionZ", gInfo[playerid][Pos][2]);
189 cache_get_value_name_int(0, "InteriorID", gInfo[playerid][Interior]);
190 SetPlayerPos(playerid, gInfo[playerid][Pos][0], gInfo[playerid][Pos][1], gInfo[playerid][Pos][2]);
191 format(string, sizeof(string), "You have been teleported to gps location: {F3FF02}'%s'", gInfo[playerid][LocName]);
192 SendClientMessage(playerid, 0xFFFF00FF, string);
193 }
194 else SendClientMessage(playerid, 0xFF0000FF,"Error: The location you entered does not exist.");
195 cache_delete(result);
196 }
197 return 1;
198 }
199 if(dialogid == DIALOG_GPS)
200 {
201 if(response)
202 {
203 if(listitem == 0)
204 {
205 new Cache:result = mysql_query(GPSDB,"SELECT `LocationName` FROM `gpsdb` WHERE `S.No` > -1 LIMIT 10");
206 if(!cache_num_rows())
207 {
208 cache_delete(result);
209 SendClientMessage(playerid, 0xFF0000FF,"Error: There is no gps locations added yet.");
210 return 1;
211 }
212
213 for(new i; i< cache_num_rows(); i++)
214 {
215 cache_get_value_name(i,"LocationName", gInfo[playerid][LocName]);
216 cache_get_value_name_float(i, "PositionX", gInfo[playerid][Pos][0]);
217 cache_get_value_name_float(i, "PositionY", gInfo[playerid][Pos][1]);
218 cache_get_value_name_float(i, "PositionZ", gInfo[playerid][Pos][2]);
219 format(string, sizeof(string), "S.No\tLocation Name\n");
220 format(string2, sizeof(string2), "%s\n%d\t%s\n", string, i, gInfo[playerid][LocName]);
221 }
222
223 SendClientMessage(playerid, 0xFFFF00FF, "Please select a location.");
224 ShowPlayerDialog(playerid, DIALOG_GPS_LOC, DIALOG_STYLE_TABLIST_HEADERS, "Please select an option.", string2, "Select", "Cancel");
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}