OsamaKurdi200

Untitled

Apr 19th, 2018
1,366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.76 KB | None | 0 0
  1.  
  2. #define FILTERSCRIPT
  3. #include <a_samp>
  4. #include <dini>
  5. #include <sscanf2>
  6. #include <zcmd>
  7. #define GATE_PATH "Gates/gate_%i.ini"
  8. #define MAX_GATES 50
  9. #define GATE_OBJECT 980
  10. #define CLOSED 0
  11. #define OPENED 1
  12. new killtimer1;
  13. enum GInf{
  14. Created,
  15. Password[256],
  16. Float:px,
  17. Float:py,
  18. Float:pz,
  19. Autogate,
  20. Status,
  21. Object,
  22. Float:Speed
  23.  
  24. };
  25. new GInfo[MAX_GATES][GInf];
  26.  
  27. public OnFilterScriptInit()
  28. {
  29. printf("Dynamic Gate System runned");
  30. new file[256];
  31. for(new i = 1, j = MAX_GATES; i<=j; i++)
  32. {
  33. format(file, sizeof(file), GATE_PATH, i);
  34. if(fexist(file))
  35. {
  36. new objectid;
  37. objectid = CreateObject( GATE_OBJECT, dini_Float(file, "X"), dini_Float(file, "Y"), dini_Float(file, "Z")+1.5, 0, 0, 0 );
  38. GInfo[i][Created] = 1;
  39. GInfo[i][Status] = CLOSED;
  40. GInfo[i][px] = dini_Float(file, "X");
  41. GInfo[i][py] = dini_Float(file, "Y");
  42. GInfo[i][pz] = dini_Float(file, "Z");
  43. GInfo[i][Autogate] = dini_Int(file, "Autogate");
  44. GInfo[i][Speed] = dini_Int(file, "Speed");
  45. GInfo[i][Object] = objectid;
  46. new pass[256];
  47. pass = dini_Get(file, "Password");
  48. GInfo[i][Password] = pass;
  49. }
  50. }
  51. return 1;
  52. }
  53.  
  54. public OnFilterScriptExit()
  55. {
  56. printf("Dynamic Gate System has stopped");
  57. return 1;
  58. }
  59.  
  60.  
  61. public OnPlayerDisconnect(playerid, reason)
  62. {
  63. KillTimer(killtimer1);
  64. return 1;
  65. }
  66.  
  67. public OnPlayerSpawn(playerid)
  68. {
  69. killtimer1 = SetTimerEx("auto", 500, 1, "i", playerid);
  70. return 1;
  71. }
  72. forward auto(playerid);
  73.  
  74. public auto(playerid)
  75. {
  76. for(new i = 0; i<1000; i++)
  77. {
  78. new file[256];
  79. format(file, sizeof(file), GATE_PATH, i);
  80. if(fexist(file))
  81. {
  82. if(GInfo[i][Autogate] == 1)
  83. {
  84. new pass[256];
  85. pass = dini_Get(file, "Password");
  86. if(!strcmp(pass, "None", true, 4))
  87. {
  88. if(GInfo[i][Status] == CLOSED)
  89. {
  90. if(IsPlayerInRangeOfPoint(playerid, 3.4, dini_Float(file, "X"), dini_Float(file, "Y"), dini_Float(file, "Z")))
  91. {
  92. MoveObject( GInfo[i][Object], GInfo[i][px], GInfo[i][py], GInfo[i][pz]-5.3, GInfo[i][Speed]);
  93. GInfo[i][Status] = OPENED;
  94. return 1;
  95. }
  96. }
  97. else if(GInfo[i][Status] == OPENED)
  98. {
  99. if(IsPlayerInRangeOfPoint(playerid, 3.4, dini_Float(file, "X"), dini_Float(file, "Y"), dini_Float(file, "Z"))) return 1;
  100. MoveObject( GInfo[i][Object], GInfo[i][px], GInfo[i][py], GInfo[i][pz]+1.6, GInfo[i][Speed] );
  101. GInfo[i][Status] = CLOSED;
  102. return 1;
  103. }
  104. }
  105. }
  106. }
  107. }
  108. return 1;
  109. }
  110.  
  111. CMD:creategate(playerid, params[])
  112. {
  113. new password[256], containspass, speed;
  114. new Float:x, Float:y, Float:z;
  115. GetPlayerPos(playerid, Float:x, Float:y, Float:z);
  116. if(sscanf(params, "i", containspass)) return SendClientMessage(playerid, -1, "USAGE:/creategate <1-Has password || 0-Has not password>");
  117. if(containspass == 0)
  118. {
  119. new autog;
  120. if(sscanf(params, "s[128]ii", params, speed, autog)) return SendClientMessage(playerid, -1, "USAGE:/creategate 0 <speed> <autogate: 1-ON || 0-OFF>");
  121. CreateGate("None", x, y, z, 0, autog, speed);
  122. }
  123. if(containspass == 1)
  124. {
  125. if(sscanf(params, "s[128]is[256]", params, speed, password)) return SendClientMessage(playerid, -1, "USAGE:/creategate 1 <speed> <password>");
  126. CreateGate(password, x, y, z, 0, 0, speed);
  127. }
  128.  
  129. SetPlayerPos(playerid, Float:x+1, Float:y+1, Float:z+1);
  130.  
  131. return true;
  132. }
  133. CMD:gate(playerid, params[])
  134. {
  135. new gatesnear = 0;
  136. for(new i = 1; i!=MAX_GATES; i++)
  137. {
  138. if(GInfo[i][Created] == 1)
  139. {
  140. new file[256];
  141. format(file, sizeof(file), GATE_PATH, i);
  142. if(IsPlayerInRangeOfPoint(playerid, 3.2, dini_Float(file, "X"), dini_Float(file, "Y"), dini_Float(file, "Z")))
  143. {
  144. gatesnear++;
  145. if(!strcmp(GInfo[i][Password], "None"))
  146. {
  147. OpenOrCloseGate(i);
  148. break;
  149. }else
  150. {
  151. new password[80];
  152. if(sscanf(params, "s[80]", password)) return SendClientMessage(playerid, -1, "USAGE:/gate <password>");
  153. if(!strcmp(password, GInfo[i][Password]))
  154. {
  155. OpenOrCloseGate(i);
  156. break;
  157. }else return SendClientMessage(playerid, -1, "Wrong password");
  158. }
  159. }
  160. }
  161. }
  162. if(gatesnear < 1) return SendClientMessage(playerid, -1, "You are not near any gate.");
  163. return 1;
  164. }
  165. CMD:removegate(playerid, params[])
  166. {
  167. new file[256], gatesnear = 0;
  168. for(new i = 0; i!=MAX_GATES; i++)
  169. {
  170. format(file, sizeof(file), GATE_PATH, i);
  171. if(fexist(file))
  172. {
  173. if(IsPlayerInRangeOfPoint(playerid, 2.0, dini_Float(file, "X"), dini_Float(file, "Y"), dini_Float(file, "Z")))
  174. {
  175. gatesnear++;
  176. DestroyObject(GInfo[i][Object]);
  177. dini_Remove(file);
  178. GInfo[i][Created] = 0;
  179. GInfo[i][px] = 0.0;
  180. GInfo[i][py] = 0.0;
  181. GInfo[i][pz] = 0.0;
  182. GInfo[i][Password] = 0;
  183. GInfo[i][Status] = CLOSED;
  184. SendClientMessage(playerid, -1, "You have removed the gate.");
  185. }
  186. }
  187. }
  188. if(gatesnear < 1) return SendClientMessage(playerid, -1, "You are not near any gate.");
  189. return 1;
  190. }
  191. CMD:editgate(playerid, params[])
  192. {
  193. new i, file[256], pass[256];
  194. i = WhichGateIsNearPlayer(playerid);
  195. format(file, sizeof(file), GATE_PATH, i);
  196. pass = dini_Get(file, "Password");
  197. new Float:speed = 0, password[256];
  198. if(sscanf(params, "s[128]", params)) return SendClientMessage(playerid, -1, "/editgate <speed || password || autogate>");
  199. if(!strcmp(params, "speed", true, 5))
  200. {
  201. if(sscanf(params, "s[128]f", params, speed)) return SendClientMessage(playerid, -1, "/editgate speed <speed>");
  202. GInfo[i][Speed] = speed;
  203. dini_FloatSet(file, "Speed", speed);
  204. SendClientMessage(playerid, -1, "Gate's speed changed.");
  205. }
  206. if(!strcmp(params, "password", true, 8))
  207. {
  208. new pas[256];
  209. if(sscanf(params, "s[128]s[256]", params, pas)) return SendClientMessage(playerid, -1, "USAGE:/editgate password <password>");
  210. GInfo[i][Password] = password;
  211. dini_Set(file, "Password", password);
  212. SendClientMessage(playerid, -1, "Gate's password changed");
  213. }
  214. if(!strcmp(params, "autogate", true, 8))
  215. {
  216. new option;
  217. if(sscanf(params, "s[128]i", params, option)) return SendClientMessage(playerid, -1, "USAGE:/editgate autogate <1=ON || 0= OFF>");
  218. if(!strcmp(GInfo[i][Password], "None", true, 4))
  219. {
  220. GInfo[i][Autogate] = option;
  221. dini_IntSet(file, "Autogate", option);
  222. SendClientMessage(playerid, -1, "Gate's autogate has been changed.");
  223. }else{
  224. return SendClientMessage(playerid, -1, "You can't set autogate for a gate that have password.");
  225. }
  226. }
  227.  
  228. return 1;
  229. }
  230.  
  231. CreateGate(password[256], Float:x, Float:y, Float:z, Float:a, Auto, Float:speed)
  232. {
  233. new file[256];
  234. for(new i = 1, j = MAX_GATES; i<=j; i++)
  235. {
  236. format(file, sizeof(file), GATE_PATH, i);
  237. if(GInfo[i][Created] == 0)
  238. {
  239. new objectid;
  240. objectid = CreateObject( GATE_OBJECT, x, y, z+1.5, 0, 0, a );
  241. dini_Create(file);
  242. dini_Set(file, "Password", password);
  243. dini_FloatSet(file, "X", x);
  244. dini_FloatSet(file, "Y", y);
  245. dini_FloatSet(file, "Z", z);
  246. dini_IntSet(file, "Autogate", Auto);
  247. dini_FloatSet(file, "Speed", speed);
  248. GInfo[i][Created] = 1;
  249. GInfo[i][Status] = CLOSED;
  250. GInfo[i][px] = x;
  251. GInfo[i][py] = y;
  252. GInfo[i][pz] = z;
  253. GInfo[i][Autogate] = Auto;
  254. GInfo[i][Object] = objectid;
  255. GInfo[i][Password] = password;
  256. GInfo[i][Speed] = speed;
  257. break;
  258. }
  259. }
  260. return 1;
  261. }
  262. OpenOrCloseGate(i)
  263. {
  264. if(GInfo[i][Status] == CLOSED)
  265. {
  266. MoveObject( GInfo[i][Object], GInfo[i][px], GInfo[i][py], GInfo[i][pz]-5.3, GInfo[i][Speed]);
  267. GInfo[i][Status] = OPENED;
  268.  
  269. return 1;
  270. }
  271. if(GInfo[i][Status] == OPENED)
  272. {
  273. MoveObject( GInfo[i][Object], GInfo[i][px], GInfo[i][py], GInfo[i][pz]+1.6, GInfo[i][Speed] );
  274. GInfo[i][Status] = CLOSED;
  275.  
  276. return 1;
  277. }
  278. return 1;
  279. }
  280. WhichGateIsNearPlayer(playerid)
  281. {
  282. new gate = 0, gatesnear = 0;
  283. for(new i = 0; i!=MAX_GATES; i++)
  284. {
  285. if(GInfo[i][Created] == 1)
  286. {
  287. new file[256];
  288. format(file, sizeof(file), GATE_PATH, i);
  289. if(fexist(file))
  290. {
  291. if(IsPlayerInRangeOfPoint(playerid, 2.0, dini_Float(file, "X"), dini_Float(file, "Y"), dini_Float(file, "Z")))
  292. {
  293. gate = i;
  294. gatesnear++;
  295. break;
  296. }
  297. }
  298. }
  299. }
  300. if(gatesnear < 1) return SendClientMessage(playerid, -1, "You are not near any gate");
  301. return gate;
  302. }
  303. /*SaveChanges(i, password[256], Float:speed, Auto, status, Float:posx, Float:posy, Float:posz, object, created)
  304. {
  305. new file[256];
  306. format(file, sizeof(file), GATE_PATH, i);
  307. GInfo[i][Password] = password;
  308. GInfo[i][Speed] = speed;
  309. GInfo[i][Autogate] = Auto;
  310. GInfo[i][Status] = status;
  311. GInfo[i][px] = posx;
  312. GInfo[i][py] = posy;
  313. GInfo[i][pz] = posz;
  314. GInfo[i][Object] = object;
  315. GInfo[i][Created] = created;
  316. dini_Set(file, "Password", password);
  317. dini_FloatSet(file, "X", posx);
  318. dini_FloatSet(file, "Y", posy);
  319. dini_FloatSet(file, "Z", posz);
  320. dini_IntSet(file, "Autogate", Auto);
  321. dini_FloatSet(file, "Speed", GInfo[i][Speed]);
  322. }*/
Advertisement
Add Comment
Please, Sign In to add comment