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