Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define FILTERSCRIPT
- #include <a_samp>
- #include <dini>
- #include <sscanf2>
- #include <zcmd>
- #define GATE_PATH "Gates/gate_%i.ini"
- #define MAX_GATES 50
- #define GATE_OBJECT 980
- #define CLOSED 0
- #define OPENED 1
- new killtimer1;
- enum GInf{
- Created,
- Password[256],
- Float:px,
- Float:py,
- Float:pz,
- Autogate,
- Status,
- Object,
- Float:Speed
- };
- new GInfo[MAX_GATES][GInf];
- public OnFilterScriptInit()
- {
- printf("Dynamic Gate System runned");
- new file[256];
- for(new i = 1, j = MAX_GATES; i<=j; i++)
- {
- format(file, sizeof(file), GATE_PATH, i);
- if(fexist(file))
- {
- new objectid;
- objectid = CreateObject( GATE_OBJECT, dini_Float(file, "X"), dini_Float(file, "Y"), dini_Float(file, "Z")+1.5, 0, 0, 0 );
- GInfo[i][Created] = 1;
- GInfo[i][Status] = CLOSED;
- GInfo[i][px] = dini_Float(file, "X");
- GInfo[i][py] = dini_Float(file, "Y");
- GInfo[i][pz] = dini_Float(file, "Z");
- GInfo[i][Autogate] = dini_Int(file, "Autogate");
- GInfo[i][Speed] = dini_Int(file, "Speed");
- GInfo[i][Object] = objectid;
- new pass[256];
- pass = dini_Get(file, "Password");
- GInfo[i][Password] = pass;
- }
- }
- return 1;
- }
- public OnFilterScriptExit()
- {
- printf("Dynamic Gate System has stopped");
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- KillTimer(killtimer1);
- return 1;
- }
- public OnPlayerSpawn(playerid)
- {
- killtimer1 = SetTimerEx("auto", 500, 1, "i", playerid);
- return 1;
- }
- forward auto(playerid);
- public auto(playerid)
- {
- for(new i = 0; i<1000; i++)
- {
- new file[256];
- format(file, sizeof(file), GATE_PATH, i);
- if(fexist(file))
- {
- if(GInfo[i][Autogate] == 1)
- {
- new pass[256];
- pass = dini_Get(file, "Password");
- if(!strcmp(pass, "None", true, 4))
- {
- if(GInfo[i][Status] == CLOSED)
- {
- if(IsPlayerInRangeOfPoint(playerid, 3.4, dini_Float(file, "X"), dini_Float(file, "Y"), dini_Float(file, "Z")))
- {
- MoveObject( GInfo[i][Object], GInfo[i][px], GInfo[i][py], GInfo[i][pz]-5.3, GInfo[i][Speed]);
- GInfo[i][Status] = OPENED;
- return 1;
- }
- }
- else if(GInfo[i][Status] == OPENED)
- {
- if(IsPlayerInRangeOfPoint(playerid, 3.4, dini_Float(file, "X"), dini_Float(file, "Y"), dini_Float(file, "Z"))) return 1;
- MoveObject( GInfo[i][Object], GInfo[i][px], GInfo[i][py], GInfo[i][pz]+1.6, GInfo[i][Speed] );
- GInfo[i][Status] = CLOSED;
- return 1;
- }
- }
- }
- }
- }
- return 1;
- }
- CMD:creategate(playerid, params[])
- {
- new password[256], containspass, speed;
- new Float:x, Float:y, Float:z;
- GetPlayerPos(playerid, Float:x, Float:y, Float:z);
- if(sscanf(params, "i", containspass)) return SendClientMessage(playerid, -1, "USAGE:/creategate <1-Has password || 0-Has not password>");
- if(containspass == 0)
- {
- new autog;
- if(sscanf(params, "s[128]ii", params, speed, autog)) return SendClientMessage(playerid, -1, "USAGE:/creategate 0 <speed> <autogate: 1-ON || 0-OFF>");
- CreateGate("None", x, y, z, 0, autog, speed);
- }
- if(containspass == 1)
- {
- if(sscanf(params, "s[128]is[256]", params, speed, password)) return SendClientMessage(playerid, -1, "USAGE:/creategate 1 <speed> <password>");
- CreateGate(password, x, y, z, 0, 0, speed);
- }
- SetPlayerPos(playerid, Float:x+1, Float:y+1, Float:z+1);
- return true;
- }
- CMD:gate(playerid, params[])
- {
- new gatesnear = 0;
- for(new i = 1; i!=MAX_GATES; i++)
- {
- if(GInfo[i][Created] == 1)
- {
- new file[256];
- format(file, sizeof(file), GATE_PATH, i);
- if(IsPlayerInRangeOfPoint(playerid, 3.2, dini_Float(file, "X"), dini_Float(file, "Y"), dini_Float(file, "Z")))
- {
- gatesnear++;
- if(!strcmp(GInfo[i][Password], "None"))
- {
- OpenOrCloseGate(i);
- break;
- }else
- {
- new password[80];
- if(sscanf(params, "s[80]", password)) return SendClientMessage(playerid, -1, "USAGE:/gate <password>");
- if(!strcmp(password, GInfo[i][Password]))
- {
- OpenOrCloseGate(i);
- break;
- }else return SendClientMessage(playerid, -1, "Wrong password");
- }
- }
- }
- }
- if(gatesnear < 1) return SendClientMessage(playerid, -1, "You are not near any gate.");
- return 1;
- }
- CMD:removegate(playerid, params[])
- {
- new file[256], gatesnear = 0;
- for(new i = 0; i!=MAX_GATES; i++)
- {
- format(file, sizeof(file), GATE_PATH, i);
- if(fexist(file))
- {
- if(IsPlayerInRangeOfPoint(playerid, 2.0, dini_Float(file, "X"), dini_Float(file, "Y"), dini_Float(file, "Z")))
- {
- gatesnear++;
- DestroyObject(GInfo[i][Object]);
- dini_Remove(file);
- GInfo[i][Created] = 0;
- GInfo[i][px] = 0.0;
- GInfo[i][py] = 0.0;
- GInfo[i][pz] = 0.0;
- GInfo[i][Password] = 0;
- GInfo[i][Status] = CLOSED;
- SendClientMessage(playerid, -1, "You have removed the gate.");
- }
- }
- }
- if(gatesnear < 1) return SendClientMessage(playerid, -1, "You are not near any gate.");
- return 1;
- }
- CMD:editgate(playerid, params[])
- {
- new i, file[256], pass[256];
- i = WhichGateIsNearPlayer(playerid);
- format(file, sizeof(file), GATE_PATH, i);
- pass = dini_Get(file, "Password");
- new Float:speed = 0, password[256];
- if(sscanf(params, "s[128]", params)) return SendClientMessage(playerid, -1, "/editgate <speed || password || autogate>");
- if(!strcmp(params, "speed", true, 5))
- {
- if(sscanf(params, "s[128]f", params, speed)) return SendClientMessage(playerid, -1, "/editgate speed <speed>");
- GInfo[i][Speed] = speed;
- dini_FloatSet(file, "Speed", speed);
- SendClientMessage(playerid, -1, "Gate's speed changed.");
- }
- if(!strcmp(params, "password", true, 8))
- {
- new pas[256];
- if(sscanf(params, "s[128]s[256]", params, pas)) return SendClientMessage(playerid, -1, "USAGE:/editgate password <password>");
- GInfo[i][Password] = password;
- dini_Set(file, "Password", password);
- SendClientMessage(playerid, -1, "Gate's password changed");
- }
- if(!strcmp(params, "autogate", true, 8))
- {
- new option;
- if(sscanf(params, "s[128]i", params, option)) return SendClientMessage(playerid, -1, "USAGE:/editgate autogate <1=ON || 0= OFF>");
- if(!strcmp(GInfo[i][Password], "None", true, 4))
- {
- GInfo[i][Autogate] = option;
- dini_IntSet(file, "Autogate", option);
- SendClientMessage(playerid, -1, "Gate's autogate has been changed.");
- }else{
- return SendClientMessage(playerid, -1, "You can't set autogate for a gate that have password.");
- }
- }
- return 1;
- }
- CreateGate(password[256], Float:x, Float:y, Float:z, Float:a, Auto, Float:speed)
- {
- new file[256];
- for(new i = 1, j = MAX_GATES; i<=j; i++)
- {
- format(file, sizeof(file), GATE_PATH, i);
- if(GInfo[i][Created] == 0)
- {
- new objectid;
- objectid = CreateObject( GATE_OBJECT, x, y, z+1.5, 0, 0, a );
- dini_Create(file);
- dini_Set(file, "Password", password);
- dini_FloatSet(file, "X", x);
- dini_FloatSet(file, "Y", y);
- dini_FloatSet(file, "Z", z);
- dini_IntSet(file, "Autogate", Auto);
- dini_FloatSet(file, "Speed", speed);
- GInfo[i][Created] = 1;
- GInfo[i][Status] = CLOSED;
- GInfo[i][px] = x;
- GInfo[i][py] = y;
- GInfo[i][pz] = z;
- GInfo[i][Autogate] = Auto;
- GInfo[i][Object] = objectid;
- GInfo[i][Password] = password;
- GInfo[i][Speed] = speed;
- break;
- }
- }
- return 1;
- }
- OpenOrCloseGate(i)
- {
- if(GInfo[i][Status] == CLOSED)
- {
- MoveObject( GInfo[i][Object], GInfo[i][px], GInfo[i][py], GInfo[i][pz]-5.3, GInfo[i][Speed]);
- GInfo[i][Status] = OPENED;
- return 1;
- }
- if(GInfo[i][Status] == OPENED)
- {
- MoveObject( GInfo[i][Object], GInfo[i][px], GInfo[i][py], GInfo[i][pz]+1.6, GInfo[i][Speed] );
- GInfo[i][Status] = CLOSED;
- return 1;
- }
- return 1;
- }
- WhichGateIsNearPlayer(playerid)
- {
- new gate = 0, gatesnear = 0;
- for(new i = 0; i!=MAX_GATES; i++)
- {
- if(GInfo[i][Created] == 1)
- {
- new file[256];
- format(file, sizeof(file), GATE_PATH, i);
- if(fexist(file))
- {
- if(IsPlayerInRangeOfPoint(playerid, 2.0, dini_Float(file, "X"), dini_Float(file, "Y"), dini_Float(file, "Z")))
- {
- gate = i;
- gatesnear++;
- break;
- }
- }
- }
- }
- if(gatesnear < 1) return SendClientMessage(playerid, -1, "You are not near any gate");
- return gate;
- }
- /*SaveChanges(i, password[256], Float:speed, Auto, status, Float:posx, Float:posy, Float:posz, object, created)
- {
- new file[256];
- format(file, sizeof(file), GATE_PATH, i);
- GInfo[i][Password] = password;
- GInfo[i][Speed] = speed;
- GInfo[i][Autogate] = Auto;
- GInfo[i][Status] = status;
- GInfo[i][px] = posx;
- GInfo[i][py] = posy;
- GInfo[i][pz] = posz;
- GInfo[i][Object] = object;
- GInfo[i][Created] = created;
- dini_Set(file, "Password", password);
- dini_FloatSet(file, "X", posx);
- dini_FloatSet(file, "Y", posy);
- dini_FloatSet(file, "Z", posz);
- dini_IntSet(file, "Autogate", Auto);
- dini_FloatSet(file, "Speed", GInfo[i][Speed]);
- }*/
Advertisement
Add Comment
Please, Sign In to add comment