Advertisement
Guest User

Extra.inc v2.1

a guest
Oct 16th, 2013
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.59 KB | None | 0 0
  1. /**********************************
  2. * *
  3. * @Author: WazzUp *
  4. * @Version: 0.3.1 *
  5. * @Released: 20/09/2013 *
  6. * *
  7. **********************************/
  8.  
  9. #include <a_samp>
  10.  
  11. /*
  12. native Extra_Kick(playerid, reason[]);
  13. native Extra_Ban(playerid, reason[]);
  14. native Extra_UnBan(playername);
  15. native Extra_Mute(playerid, reason[]);
  16. native Extra_UnMute(playerid, reason[]);
  17. native Extra_Freeze(playerid, reason[]);
  18. native Extra_UnFreeze(playerid, reason[]);
  19. */
  20.  
  21. #define MAX_STRING 600
  22.  
  23.  
  24. forward KickPlayer(playerid);
  25.  
  26.  
  27. new Banned[MAX_PLAYERS],
  28. Muted[MAX_PLAYERS],
  29. Freezed[MAX_PLAYERS];
  30.  
  31. public OnPlayerConnect(playerid)
  32. {
  33. new file[200];
  34. format(file,sizeof(file),"Extra/%s.ini",GetName(playerid));
  35.  
  36. if(!fexist(file))
  37. {
  38. new File:bfile;
  39. bfile = fopen(file,io_write);
  40. if(bfile)
  41. {
  42. fclose(bfile);
  43. return 1;
  44. }
  45. }
  46. else
  47. {
  48. Banned[playerid] = Extra_Int(file,"Ban");
  49. if(Banned[playerid] == 1) return Extra_Kick(playerid,"You has been banned from this server");
  50. Muted[playerid] = Extra_Int(file,"Mute");
  51. Freezed[playerid] = Extra_Int(file,"Freeze");
  52.  
  53. if(Freezed[playerid] == 1)
  54. {
  55. TogglePlayerControllable(playerid,0);
  56. }
  57. }
  58. return CallLocalFunction("Extra_OnPlayerConnect","u",playerid);
  59. }
  60.  
  61.  
  62. #if defined _ALS_OnPlayerConnect
  63. #undef OnPlayerConnect
  64. #endif
  65.  
  66. #define _ALS_OnPlayerConnect
  67.  
  68. #define OnPlayerConnect Extra_OnPlayerConnect
  69.  
  70.  
  71. public OnPlayerText(playerid, text[])
  72. {
  73. if(Muted[playerid] == 1)
  74. {
  75. SendClientMessage(playerid,-1,"You have been muted");
  76. return 0;
  77. }
  78. return CallLocalFunction("Extra_OnPlayerText","us",playerid,text);
  79. }
  80.  
  81.  
  82. #if defined _ALS_OnPlayerText
  83. #undef OnPlayerText
  84. #endif
  85.  
  86. #define _ALS_OnPlayerText
  87.  
  88. #define OnPlayerText Extra_OnPlayerText
  89.  
  90. stock Extra_Kick(playerid, reason[])
  91. {
  92. SetTimer("KickPlayer",3000,false);
  93. SendClientMessage(playerid,-1,reason);
  94. return 1;
  95. }
  96.  
  97. stock Extra_Ban(playerid, reason[])
  98. {
  99. SendClientMessage(playerid,-1,reason);
  100. Banned[playerid] = 1;
  101. new file[40];
  102. format(file,sizeof(file),"Extra/%s.ini",GetName(playerid));
  103. Extra_IntSet(file,"Ban",1);
  104. SetTimer("KickPlayer",3000,false);
  105. return 1;
  106. }
  107.  
  108. stock Extra_UnBan(playername[])
  109. {
  110. new file[40];
  111. format(file,sizeof(file),"Extra/%s.ini",playername);
  112. Extra_IntSet(file,"Ban",0);
  113. return 1;
  114. }
  115.  
  116. stock Extra_Mute(playerid, reason[])
  117. {
  118. new file[40];
  119. format(file,sizeof(file),"Extra/%s.ini",GetName(playerid));
  120. Extra_IntSet(file,"Mute",1);
  121. Muted[playerid] = 1;
  122.  
  123. SendClientMessage(playerid,-1,reason);
  124. return 1;
  125. }
  126.  
  127. stock Extra_UnMute(playerid, reason[])
  128. {
  129. new file[40];
  130. format(file,sizeof(file),"Extra/%s.ini",GetName(playerid));
  131. Extra_IntSet(file,"Mute",0);
  132. Muted[playerid] = 0;
  133.  
  134. SendClientMessage(playerid,-1,reason);
  135. return 1;
  136. }
  137.  
  138. stock Extra_Freeze(playerid, reason[])
  139. {
  140. new file[40];
  141. format(file,sizeof(file),"Extra/%s.ini",GetName(playerid));
  142. Extra_IntSet(file,"Freeze",1);
  143. Freezed[playerid] = 1;
  144. TogglePlayerControlLabel(playerid,0);
  145.  
  146. SendClientMessage(playerid,-1,reason);
  147. return 1;
  148. }
  149.  
  150. stock Extra_UnFreeze(playerid, reason[])
  151. {
  152. new file[40];
  153. format(file,sizeof(file),"Extra/%s.ini",GetName(playerid));
  154. Extra_IntSet(file,"Freeze",0);
  155. Freezed[playerid] = 0;
  156. TogglePlayerControlLabel(playerid,1);
  157.  
  158. SendClientMessage(playerid,-1,reason);
  159. return 1;
  160. }
  161.  
  162. stock GetName(playerid)
  163. {
  164. new pname[24];
  165. GetPlayerName(playerid,pname,sizeof(pname));
  166. return pname;
  167. }
  168.  
  169. stock Extra_Set(filename[],key[],value[])
  170. {
  171. new key_length = strlen(key);
  172. new value_length = strlen(value);
  173. if (key_length==0 || key_length+value_length+2>MAX_STRING) return false;
  174.  
  175. new File:fohnd, File:fwhnd;
  176. new tmpres[MAX_STRING];
  177. new bool:wasset=false;
  178.  
  179. // Let's remove the old *.part file if there was one.
  180. format(tmpres,sizeof(tmpres),"%s.part",filename);
  181. fremove(tmpres);
  182.  
  183. // We'll open the source file.
  184. fohnd=fopen(filename,io_read);
  185. if (!fohnd) return false;
  186.  
  187. fwhnd=fopen(tmpres,io_write);
  188. if (!fwhnd) {
  189. // we can't open the second file for writing, so .. let's close the open one and exit.
  190. fclose(fohnd);
  191. return false;
  192. }
  193.  
  194. while (fread(fohnd,tmpres)) {
  195. if (
  196. !wasset
  197. && tmpres[key_length]=='='
  198. && !strcmp(tmpres, key, true, key_length)
  199. ) {
  200. // We've got what needs to be replaced!
  201. format(tmpres,sizeof(tmpres),"%s=%s",key,value);
  202. wasset=true;
  203. } else {
  204. Extra_StripNewLine(tmpres);
  205. }
  206. fwrite(fwhnd,tmpres);
  207. fwrite(fwhnd,"\r\n");
  208. }
  209.  
  210. if (!wasset) {
  211. format(tmpres,sizeof(tmpres),"%s=%s",key,value);
  212. fwrite(fwhnd,tmpres);
  213. fwrite(fwhnd,"\r\n");
  214. }
  215.  
  216. fclose(fohnd);
  217. fclose(fwhnd);
  218.  
  219. format(tmpres,sizeof(tmpres),"%s.part",filename);
  220. if (Extra_fcopytextfile(tmpres,filename)) {
  221. return fremove(tmpres);
  222. }
  223. return false;
  224. }
  225.  
  226. stock Extra_IntSet(filename[],key[],value)
  227. {
  228. new valuestring[MAX_STRING];
  229. format(valuestring,MAX_STRING,"%d",value);
  230. return Extra_Set(filename,key,valuestring);
  231. }
  232.  
  233. stock Extra_StripNewLine(string[])
  234. {
  235. new len = strlen(string);
  236. if (string[0]==0) return ;
  237. if ((string[len - 1] == '\n') || (string[len - 1] == '\r')) {
  238. string[len - 1] = 0;
  239. if (string[0]==0) return ;
  240. if ((string[len - 2] == '\n') || (string[len - 2] == '\r')) string[len - 2] = 0;
  241. }
  242. }
  243.  
  244. stock Extra_fcopytextfile(oldname[],newname[])
  245. {
  246. new File:ohnd,File:nhnd;
  247. if (!fexist(oldname)) return false;
  248. ohnd=fopen(oldname,io_read);
  249. if (!ohnd) return false;
  250. nhnd=fopen(newname,io_write);
  251. if (!nhnd) {
  252. fclose(ohnd);
  253. return false;
  254. }
  255. new tmpres[MAX_STRING];
  256. while (fread(ohnd,tmpres)) {
  257. Extra_StripNewLine(tmpres);
  258. format(tmpres,sizeof(tmpres),"%s\r\n",tmpres);
  259. fwrite(nhnd,tmpres);
  260. }
  261. fclose(ohnd);
  262. fclose(nhnd);
  263. return true;
  264. }
  265.  
  266. stock Extra_Get(filename[],key[])
  267. {
  268. new tmpres[MAX_STRING];
  269.  
  270. new key_length = strlen(key);
  271. if (key_length==0 || key_length+2>MAX_STRING) return tmpres;
  272.  
  273. new File:fohnd;
  274. fohnd=fopen(filename,io_read);
  275. if (!fohnd) return tmpres;
  276.  
  277. while (fread(fohnd,tmpres)) {
  278. if (
  279. tmpres[key_length]=='='
  280. && !strcmp(tmpres, key, true, key_length)
  281. ) {
  282. /* We've got what we need */
  283. Extra_StripNewLine(tmpres);
  284. strmid(tmpres, tmpres, key_length + 1, strlen(tmpres), MAX_STRING);
  285. fclose(fohnd);
  286. return tmpres;
  287. }
  288. }
  289. fclose(fohnd);
  290. return tmpres;
  291. }
  292.  
  293. stock Extra_Int(filename[],key[])
  294. {
  295. return strval(Extra_Get(filename,key));
  296. }
  297.  
  298.  
  299. public KickPlayer(playerid)
  300. {
  301. Kick(playerid);
  302. return 1;
  303. }
  304.  
  305. forward Extra_OnPlayerConnect(playerid);
  306. forward Extra_OnPlayerText(playerid, text[]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement