notes.pwn 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. //-------------------------------------------
  2. // NFS Filter Script v1.1
  3. // Designed for SA-MP v3.0b
  4. //-------------------------------------------
  5. #include <a_samp>
  6. #include <YSI\y_ini>
  7. #define MAX_NOTES 50
  8. #define MAX_MODERATORS 10
  9. #define INVALID_NOTE_ID 1337
  10. #define COLOR_REPORT 0xFFFF91FF
  11. #define COLOR_YELLOW 0xFFFF00AA
  12. #define COLOR_GRAD2 0xBFC0C2FF
  13. #define COLOR_GREEN 0x33AA33AA
  14. forward SendNoteToQue(notefrom, note[]);
  15. forward ClearNotes();
  16. forward LoadNotes();
  17. forward SaveNotes();
  18. forward split(const strsrc[], strdest[][], delimiter);
  19. enum notesinfo
  20. {
  21. HasBeenUsed,
  22. Note[128],
  23. NoteFrom[MAX_PLAYER_NAME],
  24. }
  25. new Notes[MAX_NOTES][notesinfo];
  26. enum moderatorsinfo
  27. {
  28. HasBeenUsed,
  29. ModeratorTitle[68],
  30. ModeratorName[MAX_PLAYER_NAME],
  31. }
  32. new Mods[MAX_MODERATORS][moderatorsinfo];
  33. new modcount = 0;
  34. INI:moderators[](name[], value[])
  35. {
  36. strmid(Mods[modcount][ModeratorName], name, 0, strlen(name), 128);
  37. strmid(Mods[modcount][ModeratorTitle], value, 0, strlen(value), 128);
  38. printf("%s = %s (modcount = %d)", name, value, modcount);
  39. modcount++;
  40. }
  41. public OnFilterScriptInit()
  42. {
  43. print("\n Notes v1.1 Loading...");
  44. INI_Load("moderators.ini");
  45. LoadNotes();
  46. }
  47. public OnFilterScriptExit()
  48. {
  49. print("\n Notes Script UnLoaded");
  50. return 1;
  51. }
  52. public SendNoteToQue(notefrom, note[])
  53. {
  54. new bool:breakingloop = false, newid = INVALID_NOTE_ID;
  55. for(new i=0;i<MAX_NOTES;i++)
  56. {
  57. if(!breakingloop)
  58. {
  59. if(Notes[i][HasBeenUsed] == 0) // Checking for next available ID.
  60. {
  61. breakingloop = true;
  62. newid = i;
  63. }
  64. }
  65. }
  66. if(newid != INVALID_NOTE_ID)
  67. {
  68. strmid(Notes[newid][Note], note, 0, strlen(note), 128);
  69. strmid(Notes[newid][NoteFrom], GetPlayerNameEx(notefrom), 0, strlen(GetPlayerNameEx(notefrom)), 128);
  70. Notes[newid][HasBeenUsed] = 1;
  71. new string[128];
  72. format(string, sizeof(string), "Note from [%i]%s (NID: %i): %s", notefrom, GetPlayerNameEx(notefrom), newid, (note));
  73. SendClientMessageToAll(COLOR_REPORT,string);
  74. SaveNotes();
  75. }
  76. else
  77. {
  78. ClearNotes();
  79. SendNoteToQue(notefrom, note);
  80. }
  81. }
  82. public ClearNotes()
  83. {
  84. for(new i=0;i<MAX_NOTES;i++)
  85. {
  86. strmid(Notes[i][Note], "None", 0, 4, 4);
  87. strmid(Notes[i][NoteFrom], "No-one", 0, 6, 6);
  88. Notes[i][HasBeenUsed] = 0;
  89. }
  90. SaveNotes();
  91. return 1;
  92. }
  93. public SaveNotes()
  94. {
  95. new idx;
  96. new File: file2;
  97. while (idx < sizeof(Notes))
  98. {
  99. new coordsstring[256];
  100. format(coordsstring, sizeof(coordsstring), "%s|%s|%d\n",
  101. Notes[idx][Note],
  102. Notes[idx][NoteFrom],
  103. Notes[idx][HasBeenUsed]);
  104. if(idx == 0)
  105. {
  106. file2 = fopen("notes.cfg", io_write);
  107. }
  108. else
  109. {
  110. file2 = fopen("notes.cfg", io_append);
  111. }
  112. fwrite(file2, coordsstring);
  113. idx++;
  114. fclose(file2);
  115. }
  116. return 1;
  117. }
  118. public LoadNotes()
  119. {
  120. new arrCoords[3][128];
  121. new strFromFile2[256];
  122. new File: file = fopen("notes.cfg", io_read);
  123. if (file)
  124. {
  125. new idx;
  126. while (idx < sizeof(Notes))
  127. {
  128. fread(file, strFromFile2);
  129. split(strFromFile2, arrCoords, '|');
  130. strmid(Notes[idx][Note], arrCoords[0], 0, strlen(arrCoords[0]), 255);
  131. strmid(Notes[idx][NoteFrom], arrCoords[1], 0, strlen(arrCoords[1]), 255);
  132. Notes[idx][HasBeenUsed] = strval(arrCoords[2]);
  133. idx++;
  134. }
  135. fclose(file);
  136. }
  137. return 1;
  138. }
  139. public OnPlayerCommandText(playerid, cmdtext[])
  140. {
  141. new string[256];
  142. //printf( "[cmd] [%s]: %s", GetPlayerNameEx( playerid ), cmdtext );
  143. new cmd[256], idx;
  144. new tmp[256];
  145. cmd = strtok(cmdtext, idx);
  146. if(strcmp(cmd, "/addnote", true) == 0)
  147. {
  148. if(IsPlayerModerator(playerid))
  149. {
  150. new length = strlen(cmdtext);
  151. while ((idx < length) && (cmdtext[idx] <= ' '))
  152. {
  153. idx++;
  154. }
  155. new offset = idx;
  156. new result[128];
  157. while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
  158. {
  159. result[idx - offset] = cmdtext[idx];
  160. idx++;
  161. }
  162. result[idx - offset] = EOS;
  163. if(!strlen(result))
  164. {
  165. SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /addnote [text]");
  166. return 1;
  167. }
  168. format(string, sizeof(string), "%s", (result));
  169. SendNoteToQue(playerid, string);
  170. SendClientMessage(playerid, COLOR_YELLOW, "Your note message was stored.");
  171. }
  172. return 1;
  173. }
  174. if(strcmp(cmd, "/delnote", true) == 0)
  175. {
  176. if(IsPlayerModerator(playerid))
  177. {
  178. tmp = strtok(cmdtext, idx);
  179. if(!strlen(tmp))
  180. {
  181. SendClientMessage(playerid, COLOR_GRAD2,"USAGE: /delnote [noteid]");
  182. return 1;
  183. }
  184. new noteid = strval(tmp);
  185. format(string, sizeof(string), "Note ID: %d was deleted.", noteid);
  186. strmid(Notes[noteid][Note], "None", 0, 4, 4);
  187. strmid(Notes[noteid][NoteFrom], "No-one", 0, 6, 6);
  188. Notes[noteid][HasBeenUsed] = 0;
  189. SaveNotes();
  190. SendClientMessage(playerid, COLOR_YELLOW, string);
  191. }
  192. return 1;
  193. }
  194. if(strcmp(cmd, "/addmoderator", true) == 0)
  195. {
  196. if(IsPlayerAdmin(playerid))
  197. {
  198. if(modcount == MAX_MODERATORS) return 1;
  199. tmp = strtok(cmdtext, idx);
  200. if(!strlen(tmp))
  201. {
  202. SendClientMessage(playerid, COLOR_GRAD2,"USAGE: /addmoderator [player] [title]");
  203. return 1;
  204. }
  205. new playername[MAX_PLAYER_NAME];
  206. strmid(playername, tmp, 0, strlen(tmp), MAX_PLAYER_NAME);
  207. new length = strlen(cmdtext);
  208. while ((idx < length) && (cmdtext[idx] <= ' '))
  209. {
  210. idx++;
  211. }
  212. new offset = idx;
  213. new result[128];
  214. while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
  215. {
  216. result[idx - offset] = cmdtext[idx];
  217. idx++;
  218. }
  219. result[idx - offset] = EOS;
  220. if(!strlen(result))
  221. {
  222. SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /addmoderator [player] [title]");
  223. return 1;
  224. }
  225. new INI:file = INI_Open("moderators.ini");
  226. for(new i=0;i<MAX_MODERATORS;i++)
  227. {
  228. if(strlen(Mods[i][ModeratorName]))
  229. {
  230. INI_WriteString(file, Mods[i][ModeratorName], Mods[i][ModeratorTitle]);
  231. }
  232. }
  233. INI_WriteString(file, playername, result);
  234. INI_Close(file);
  235. strmid(Mods[modcount][ModeratorName], playername, 0, strlen(playername), MAX_PLAYER_NAME);
  236. strmid(Mods[modcount][ModeratorTitle], result, 0, strlen(result), 68);
  237. modcount++;
  238. }
  239. return 1;
  240. }
  241. if(strcmp(cmd, "/clearnotes", true) == 0)
  242. {
  243. if (IsPlayerModerator(playerid))
  244. {
  245. ClearNotes();
  246. new title[68];
  247. GetModeratorTitle(playerid, title);
  248. SendClientMessage(playerid,COLOR_GRAD2, "You have cleared all the active notes.");
  249. format( string, sizeof( string ), "AdmCmd: %s %s has cleared all the active notes.", title, GetPlayerNameEx(playerid) );
  250. SendClientMessageToAll( COLOR_GREEN, string );
  251. }
  252. else
  253. {
  254. SendClientMessage(playerid, COLOR_GRAD2, "You are not authorized to use that command!");
  255. }
  256. return 1;
  257. }
  258. if(strcmp(cmd, "/nmods", true) == 0)
  259. {
  260. SendClientMessage(playerid,COLOR_GREEN, "Notes Moderators:");
  261. for(new i=0;i<MAX_MODERATORS;i++)
  262. {
  263. if(strlen(Mods[i][ModeratorName]) > 0)
  264. {
  265. format( string, sizeof( string ), "Title: %s Name: %s.", Mods[i][ModeratorTitle], Mods[i][ModeratorName] );
  266. SendClientMessage( playerid , COLOR_GRAD2 , string );
  267. }
  268. }
  269. }
  270. if(strcmp(cmd, "/notes", true) == 0)
  271. {
  272. SendClientMessage(playerid, COLOR_GREEN, "____________________ NOTES _____________________");
  273. for(new i = 0; i < MAX_NOTES; i++)
  274. {
  275. if(Notes[i][HasBeenUsed] == 1)
  276. {
  277. format(string, sizeof(string), "NID %d | From:%s | Note: %s.", i, (Notes[i][NoteFrom]), (Notes[i][Note]));
  278. SendClientMessage(playerid, COLOR_REPORT, string);
  279. }
  280. }
  281. SendClientMessage(playerid, COLOR_GREEN, "___________________________________________________");
  282. return 1;
  283. }
  284. return 0;
  285. }
  286. stock GetPlayerNameEx(playerid)
  287. {
  288. new string[MAX_PLAYER_NAME];
  289. GetPlayerName(playerid, string, sizeof(string));
  290. for(new i; i < MAX_PLAYER_NAME; i++) if (string[i] == '_') string[i] = ' ';
  291. return string;
  292. }
  293. stock IsPlayerModerator(playerid)
  294. {
  295. new name[MAX_PLAYER_NAME];
  296. GetPlayerName(playerid, name, sizeof(name));
  297. for(new i=0;i<MAX_MODERATORS;i++)
  298. {
  299. if(strcmp(name, Mods[i][ModeratorName])==0 && strlen(Mods[i][ModeratorName]))
  300. {
  301. printf("%s is a notes mod(modcount = %d)", name, i);
  302. return true;
  303. }
  304. }
  305. return false;
  306. }
  307. stock GetModeratorTitle(playerid, title[])
  308. {
  309. new name[MAX_PLAYER_NAME];
  310. GetPlayerName(playerid, name, sizeof(name));
  311. for(new i=0;i<MAX_MODERATORS;i++)
  312. {
  313. if(strcmp(name, Mods[i][ModeratorName])==0 && strlen(Mods[i][ModeratorName]))
  314. {
  315. printf("%s is a notes mod(title = %s modcount = %d)", name, Mods[i][ModeratorTitle], i);
  316. strmid(title, Mods[i][ModeratorTitle], 0, strlen(Mods[i][ModeratorTitle]), 128);
  317. }
  318. }
  319. }
  320. strtok(const string[], &index)
  321. {
  322. new length = strlen(string);
  323. while ((index < length) && (string[index] <= ' '))
  324. {
  325. index++;
  326. }
  327. new offset = index;
  328. new result[20];
  329. while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  330. {
  331. result[index - offset] = string[index];
  332. index++;
  333. }
  334. result[index - offset] = EOS;
  335. return result;
  336. }
  337. public split(const strsrc[], strdest[][], delimiter)
  338. {
  339. new i, li;
  340. new aNum;
  341. new len;
  342. while(i <= strlen(strsrc)){
  343. if(strsrc[i]==delimiter || i==strlen(strsrc)){
  344. len = strmid(strdest[aNum], strsrc, li, i, 128);
  345. strdest[aNum][len] = 0;
  346. li = i+1;
  347. aNum++;
  348. }
  349. i++;
  350. }
  351. return 1;
  352. }
  353. public OnPlayerSpawn(playerid)
  354. {
  355. if(GetPVarInt(playerid, "FirstSpawn") == 1)
  356. {
  357. if(IsPlayerModerator(playerid))
  358. {
  359. SendClientMessage(playerid, COLOR_GREEN, "You are allowed to use '/addnote' '/delnote' '/clearnotes'");
  360. }
  361. else
  362. {
  363. SendClientMessage(playerid, COLOR_GREEN, "Please make sure you check /notes before doing anything.");
  364. }
  365. }
  366. }