Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include a_samp
- #include streamer
- #include zcmd
- #define red 0xFF0000AA
- #define gateo 980
- #define MAX_GATES 500
- #define _DB_ "gate.db"
- enum ginfo
- {
- GID,
- Opened,
- Created,
- GMove,
- Float:GX,
- Float:GY,
- Float:GZ,
- Float:GA1,
- GPassword[32],
- Placer[40],
- PlaceDate[40],
- };
- new GateInfo[MAX_GATES][ginfo],cgate = 0,DB:Database;
- public OnFilterScriptInit() {
- Database = db_open(_DB_);
- db_query(Database,
- "CREATE TABLE IF NOT EXISTS `gates` (`ID` NUMBERIC,`Placer` TEXT, `PlaceDate` TEXT, `X` TEXT, `Y` TEXT, `Z` TEXT, `A` TEXT, `Password` TEXT )");
- new Query[250],DBResult:Result,gateid = 0;
- for(new i = 0; i < MAX_GATES; i++) {
- format(Query, sizeof(Query),"SELECT * FROM gates WHERE ID = %d",i);
- Result = db_query(Database, Query);
- if(db_num_rows(Result)) {
- format(Query, sizeof(Query),"UPDATE `gates` SET `ID` = '%d' WHERE `ID` = '%d'",gateid,i);
- db_query(Database, Query);
- gateid ++;
- }
- }
- for(new i = 0; i < MAX_GATES; i++) {
- format(Query, sizeof(Query),"SELECT * FROM gates WHERE ID = %d",i);
- Result = db_query(Database, Query);
- if(db_num_rows(Result)) {
- new Save[4][100],ID1[10];
- db_get_field_assoc(Result, "ID", ID1, 10);
- GateInfo[i][GID] = strval(ID1);
- db_get_field_assoc(Result, "X", Save[0], 100);
- db_get_field_assoc(Result, "Y", Save[1], 100);
- db_get_field_assoc(Result, "Z", Save[2], 100);
- db_get_field_assoc(Result, "A", Save[3], 100);
- db_get_field_assoc(Result, "Password",GateInfo[GateInfo[i][GID]][GPassword], 32);
- db_get_field_assoc(Result, "Placer", GateInfo[GateInfo[i][GID]][Placer], 40);
- db_get_field_assoc(Result, "PlaceDate", GateInfo[GateInfo[i][GID]][PlaceDate], 40);
- GateInfo[GateInfo[i][GID]][Opened] = 0;
- GateInfo[GateInfo[i][GID]][Created] = 1;
- GateInfo[GateInfo[i][GID]][GX] = floatstr(Save[0]);
- GateInfo[GateInfo[i][GID]][GY] = floatstr(Save[1]);
- GateInfo[GateInfo[i][GID]][GZ] = floatstr(Save[2]);
- GateInfo[GateInfo[i][GID]][GA1] = floatstr(Save[3]);
- GateInfo[GateInfo[i][GID]][GMove] = CreateDynamicObject(gateo, GateInfo[GateInfo[i][GID]][GX], GateInfo[GateInfo[i][GID]][GY], GateInfo[GateInfo[i][GID]][GZ], 0, 0, GateInfo[GateInfo[i][GID]][GA1]);
- cgate = strval(ID1)+1;
- }
- }
- db_free_result(Result);
- printf("%d Gates successfully loaded and created!",gateid);
- }
- CMD:gopen(playerid,params[]) {
- new i = NearGate(playerid);
- if(i == -255) return SendClientMessage(playerid, red, "ERROR: You should be near gate to open it");
- if(GateInfo[GateInfo[i][GID]][Opened] == 1) return SendClientMessage(playerid, red, "ERROR: This Gate is Already Opened");
- new gPassword[32];
- if(sscanf(params,"s",gPassword)) return SendClientMessage(playerid, red, "Usage: /gopen [password]");
- if(strcmp(gPassword,GateInfo[GateInfo[i][GID]][GPassword],false) == 0) {
- MoveDynamicObject(GateInfo[GateInfo[i][GID]][GMove], GateInfo[GateInfo[i][GID]][GX], GateInfo[GateInfo[i][GID]][GY], GateInfo[GateInfo[i][GID]][GZ]-5.4, 3);
- SendClientMessage(playerid, -1, "You opened the gate");
- GateInfo[GateInfo[i][GID]][Opened] = 1;
- } else return SendClientMessage(playerid, red, "ERROR: Invalid Password!");
- return 1;
- }
- CMD:gclose(playerid,params[]) {
- new i = NearGate(playerid);
- if(i == -255) return SendClientMessage(playerid, red, "ERROR: You should be near gate to open it");
- if(GateInfo[GateInfo[i][GID]][Opened] == 0) return SendClientMessage(playerid, red, "ERROR: This Gate is Already Closed");
- new gPassword[32];
- if(sscanf(params,"s",gPassword)) return SendClientMessage(playerid, red, "Usage: /gclose [password]");
- if(strcmp(gPassword,GateInfo[GateInfo[i][GID]][GPassword],false) == 0) {
- MoveDynamicObject(GateInfo[GateInfo[i][GID]][GMove], GateInfo[GateInfo[i][GID]][GX], GateInfo[GateInfo[i][GID]][GY], GateInfo[GateInfo[i][GID]][GZ], 3);
- SendClientMessage(playerid, -1, "You closed the gate");
- GateInfo[GateInfo[i][GID]][Opened] = 0;
- } else return SendClientMessage(playerid, red, "ERROR: Invalid Password!");
- return 1;
- }
- CMD:gateinfo(playerid,params[]) {
- if(IsPlayerAdmin(playerid)) {
- new i = NearGate(playerid);
- if(i == -255) return SendClientMessage(playerid, red, "ERROR: You should be near gate to get info");
- new string[128];
- format(string,sizeof string,"Gate Info ( Placed by: %s | Password: %s | Place Date: %s )",GateInfo[GateInfo[i][GID]][Placer],GateInfo[GateInfo[i][GID]][GPassword],
- GateInfo[GateInfo[i][GID]][PlaceDate]);
- SendClientMessage(playerid, -1, string);
- } else return SendClientMessage(playerid, red, "You need to be level 1 and above to use this command");
- return 1;
- }
- CMD:removegate(playerid,params[]) {
- if(IsPlayerAdmin(playerid)) {
- new i = NearGate(playerid);
- if(i == -255) return SendClientMessage(playerid, red, "ERROR: You should be near gate to get info");
- GateInfo[GateInfo[i][GID]][Created] = 0;
- new Query[128],string[128];
- format(Query, sizeof(Query),"DELETE FROM `gates` WHERE `ID` = '%d'", GateInfo[i][GID]);
- db_query(Database, Query);
- DestroyDynamicObject(GateInfo[GateInfo[i][GID]][GMove]);
- format(string,sizeof string,"You have removed this gate [ ID: %d ]",GateInfo[i][GID]);
- return SendClientMessage(playerid, -1, string);
- } else return SendClientMessage(playerid, red, "ERROR: You need to be rcon to use this command");
- }
- CMD:changegpass(playerid,params[]) {
- if(IsPlayerAdmin(playerid)) {
- new i = NearGate(playerid);
- if(i == -255) return SendClientMessage(playerid, red, "ERROR: You should be near gate to change password");
- new gpassword[32];
- if(sscanf(params,"s",gpassword)) return SendClientMessage(playerid, red, "Usage: /changegpass [new password]");
- if(strlen(gpassword) > 32 || strlen(gpassword) < 4) return SendClientMessage(playerid, red, "ERROR: Gate Password should be between 4-32 words");
- new string[128],Query[128];
- GateInfo[GateInfo[i][GID]][GPassword] = gpassword;
- format(Query, sizeof(Query),"UPDATE `gates` SET `password` = '%s' WHERE `ID` = '%d'", GateInfo[GateInfo[i][GID]][GPassword],GateInfo[i][GID]);
- db_query(Database, Query);
- format(string,sizeof string,"You have changed this gate password, New Password is: %s",GateInfo[GateInfo[i][GID]][GPassword]);
- SendClientMessage(playerid, -1, string);
- } else return SendClientMessage(playerid, red, "You need to be level 7 to use this command");
- return 1;
- }
- CMD:placegate(playerid,params[]) {
- if(IsPlayerAdmin(playerid)) {
- new gpassword[32];
- if(sscanf(params,"s",gpassword)) return SendClientMessage(playerid, red, "Usage: /placegate [password]");
- if(strlen(gpassword) > 32 || strlen(gpassword) < 4) return SendClientMessage(playerid, red, "ERROR: Gate Password should be between 4-32 words");
- new Float:X,Float:Y,Float:Z,Float:A;
- GetPlayerPos(playerid, X,Y,Z);
- GetPlayerFacingAngle(playerid,A);
- new Query[400],Year,Month,Day,string[128];
- getdate(Year,Month,Day);
- format(string,sizeof string,"%d-%d-%d",Day,Month,Year);
- format(Query, sizeof(Query),"INSERT INTO `gates`(`ID`,`X`,`Y`,`Z`,`A`,`Password`,`Placer`,`PlaceDate`) VALUES ('%d','%f','%f','%f','%f','%s','%s','%s')",
- cgate,X,Y,Z+1.5,A,gpassword,pName(playerid),string);
- db_query(Database, Query);
- GateInfo[cgate][GX] = X;
- GateInfo[cgate][GY] = Y;
- GateInfo[cgate][GZ] = Z+1.5;
- GateInfo[cgate][GA1] = A;
- GateInfo[cgate][GPassword] = gpassword;
- GateInfo[cgate][GID] = cgate;
- GateInfo[cgate][Opened] = 0;
- GateInfo[cgate][Created] = 1;
- GateInfo[cgate][GMove] = CreateDynamicObject(gateo, X, Y, Z+1.5, 0, 0, A, -1, -1, -1,STREAMER_OBJECT_SD,STREAMER_OBJECT_DD);
- format(GateInfo[cgate][Placer],MAX_PLAYER_NAME+1,"%s",pName(playerid));
- format(GateInfo[cgate][PlaceDate],32,"%s",string);
- SendClientMessage(playerid, -1, "You succesfully created a movable gate. Use /gopen or /gclose." );
- cgate ++;
- return 1;
- } else return SendClientMessage(playerid, red, "ERROR: You need to be rcon to use this command");
- }
- NearGate(playerid) {
- for(new i = 0; i < MAX_GATES; i++) {
- if(GateInfo[i][Created] == 1) {
- if(IsPlayerInRangeOfPoint(playerid, 10.0, GateInfo[GateInfo[i][GID]][GX], GateInfo[GateInfo[i][GID]][GY], GateInfo[GateInfo[i][GID]][GZ])) {
- return GateInfo[i][GID];
- }
- }
- }
- return -255;
- }
- sscanf(string[], format[], {Float,_}:...)
- {
- #if defined isnull
- if (isnull(string))
- #else
- if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
- #endif
- {
- return format[0];
- }
- #pragma tabsize 4
- new
- formatPos = 0,
- stringPos = 0,
- paramPos = 2,
- paramCount = numargs(),
- delim = ' ';
- while (string[stringPos] && string[stringPos] <= ' ')
- {
- stringPos++;
- }
- while (paramPos < paramCount && string[stringPos])
- {
- switch (format[formatPos++])
- {
- case '\0':
- {
- return 0;
- }
- case 'i', 'd':
- {
- new
- neg = 1,
- num = 0,
- ch = string[stringPos];
- if (ch == '-')
- {
- neg = -1;
- ch = string[++stringPos];
- }
- do
- {
- stringPos++;
- if ('0' <= ch <= '9')
- {
- num = (num * 10) + (ch - '0');
- }
- else
- {
- return -1;
- }
- }
- while ((ch = string[stringPos]) > ' ' && ch != delim);
- setarg(paramPos, 0, num * neg);
- }
- case 'h', 'x':
- {
- new
- num = 0,
- ch = string[stringPos];
- do
- {
- stringPos++;
- switch (ch)
- {
- case 'x', 'X':
- {
- num = 0;
- continue;
- }
- case '0' .. '9':
- {
- num = (num << 4) | (ch - '0');
- }
- case 'a' .. 'f':
- {
- num = (num << 4) | (ch - ('a' - 10));
- }
- case 'A' .. 'F':
- {
- num = (num << 4) | (ch - ('A' - 10));
- }
- default:
- {
- return -1;
- }
- }
- }
- while ((ch = string[stringPos]) > ' ' && ch != delim);
- setarg(paramPos, 0, num);
- }
- case 'c':
- {
- setarg(paramPos, 0, string[stringPos++]);
- }
- case 'f':
- {
- new changestr[16], changepos = 0, strpos = stringPos;
- while(changepos < 16 && string[strpos] && string[strpos] != delim)
- {
- changestr[changepos++] = string[strpos++];
- }
- changestr[changepos] = '\0';
- setarg(paramPos,0,_:floatstr(changestr));
- }
- case 'p':
- {
- delim = format[formatPos++];
- continue;
- }
- case '\'':
- {
- new
- end = formatPos - 1,
- ch;
- while ((ch = format[++end]) && ch != '\'') {}
- if (!ch)
- {
- return -1;
- }
- format[end] = '\0';
- if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
- {
- if (format[end + 1])
- {
- return -1;
- }
- return 0;
- }
- format[end] = '\'';
- stringPos = ch + (end - formatPos);
- formatPos = end + 1;
- }
- case 'u':
- {
- new
- end = stringPos - 1,
- id = 0,
- bool:num = true,
- ch;
- while ((ch = string[++end]) && ch != delim)
- {
- if (num)
- {
- if ('0' <= ch <= '9')
- {
- id = (id * 10) + (ch - '0');
- }
- else
- {
- num = false;
- }
- }
- }
- if (num && IsPlayerConnected(id))
- {
- setarg(paramPos, 0, id);
- }
- else
- {
- #if !defined foreach
- #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
- #define __SSCANF_FOREACH__
- #endif
- string[end] = '\0';
- num = false;
- new
- ssname[MAX_PLAYER_NAME];
- id = end - stringPos;
- foreach (Player, playerid)
- {
- GetPlayerName(playerid, ssname, sizeof (ssname));
- if (!strcmp(ssname, string[stringPos], true, id))
- {
- setarg(paramPos, 0, playerid);
- num = true;
- break;
- }
- }
- if (!num)
- {
- setarg(paramPos, 0, INVALID_PLAYER_ID);
- }
- string[end] = ch;
- #if defined __SSCANF_FOREACH__
- #undef foreach
- #undef __SSCANF_FOREACH__
- #endif
- }
- stringPos = end;
- }
- case 's', 'z':
- {
- new
- i = 0,
- ch;
- if (format[formatPos])
- {
- while ((ch = string[stringPos++]) && ch != delim)
- {
- setarg(paramPos, i++, ch);
- }
- if (!i)
- {
- return -1;
- }
- }
- else
- {
- while ((ch = string[stringPos++]))
- {
- setarg(paramPos, i++, ch);
- }
- }
- stringPos--;
- setarg(paramPos, i, '\0');
- }
- default:
- {
- continue;
- }
- }
- while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
- {
- stringPos++;
- }
- while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
- {
- stringPos++;
- }
- paramPos++;
- }
- do
- {
- if ((delim = format[formatPos++]) > ' ')
- {
- if (delim == '\'')
- {
- while ((delim = format[formatPos++]) && delim != '\'') {}
- }
- else if (delim != 'z')
- {
- return delim;
- }
- }
- }
- while (delim > ' ');
- return 0;
- }
- pName(playerid) {
- new pname[MAX_PLAYER_NAME+1];
- GetPlayerName(playerid, pname, sizeof(pname));
- return pname;
- }
Advertisement
Add Comment
Please, Sign In to add comment