Advertisement
Guest User

Untitled

a guest
Aug 13th, 2009
331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.64 KB | None | 0 0
  1. #include <a_samp>
  2. #define dcmd(%1,%2,%3) if ((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, "")))||(((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
  3.  
  4. enum Opt
  5. {
  6.     Time_Check,
  7.     Admins_Slots,
  8.     Vip_Slots,
  9.     Max_Slots
  10. }
  11.  
  12. enum Stat
  13. {
  14.     Admins_Online,
  15.     Vip_Online,
  16.     Timer[200],
  17.     Players
  18. }
  19.  
  20. new Options[Opt];
  21. new Status[Stat];
  22.  
  23. forward CheckPlayer(playerid);
  24.  
  25. public OnFilterScriptInit()
  26. {
  27.     print("\n--------------------------------------\nSlots Reservation by Conan/Destrojer v0.2\n--------------------------------------\n");
  28.     Options[Max_Slots] = GetMaxPlayers();
  29.     Options[Vip_Slots] = 1;
  30.     Options[Admins_Slots] = 1;
  31.     return 1;
  32. }
  33.  
  34. public OnFilterScriptExit()
  35. {
  36.     print("\n--------------------------------------\nSlots Reservation unloaded\n--------------------------------------\n");
  37.     return 1;
  38. }
  39.  
  40. public OnPlayerRequestSpawn(playerid)
  41. {
  42.     Status[Players]++;
  43.     if(Status[Players] >= (Options[Max_Slots] - (Options[Vip_Slots] + Options[Admins_Slots])))
  44.         Status[Timer][playerid] = SetTimerEx("CheckPlayer", 10*1000, 0, "d", playerid);
  45.     if(fexist("Slot_Reservation/Reserved_Slots.txt"))
  46.         if(FindName(PlayerName(playerid)))
  47.             Status[Vip_Online]++;
  48.     return 1;
  49. }
  50.  
  51. public OnPlayerCommandText(playerid, cmdtext[])
  52. {
  53.     dcmd(giveslot, 8, cmdtext);
  54.     dcmd(setslot, 7, cmdtext);
  55.     dcmd(showlist, 8, cmdtext);
  56.     dcmd(freeslots, 9, cmdtext);
  57.     return 0;
  58. }
  59.  
  60. public OnPlayerDisconnect(playerid, reason)
  61. {
  62.     if(fexist("Slot_Reservation/Reserved_Slots.txt"))
  63.         if(FindName(PlayerName(playerid)))
  64.             Status[Vip_Online]--;
  65.     if(IsPlayerAdmin(playerid))
  66.         Status[Admins_Online]--;
  67.     Status[Admins_Online] = Status[Admins_Online]>=0 ? Status[Admins_Online] : 0;
  68.     Status[Vip_Online] = Status[Vip_Online]>=0 ? Status[Vip_Online] : 0;
  69.     return 1;
  70. }
  71.  
  72. public CheckPlayer(playerid)
  73. {
  74.     KillTimer(Status[Timer][playerid]);
  75.     if(fexist("Slot_Reservation/Reserved_Slots.txt"))
  76.     {
  77.         if(FindName(PlayerName(playerid)) == 0  && (Options[Vip_Slots] - Status[Vip_Online]) > 0 && Options[Vip_Slots] > 0)
  78.         {
  79.             SendClientMessage(playerid, 0xFFFFFFFF, "Sorry, this slot is reserved");
  80.             Kick(playerid);
  81.             return 1;
  82.         }
  83.     }
  84.     if(!IsPlayerAdmin(playerid) && (Options[Admins_Slots] - Status[Admins_Online]) > 0 && Options[Admins_Slots] > 0)
  85.     {
  86.         SendClientMessage(playerid, 0xFFFFFFFF, "Sorry, this slot is reserved");
  87.         Kick(playerid);
  88.     }
  89.     else
  90.         Status[Admins_Online]++;
  91.     return 1;
  92. }
  93.  
  94. stock PlayerName(playerid)
  95. {
  96.     new name[24];
  97.     GetPlayerName(playerid, name, 24);
  98.     return name;
  99. }
  100.  
  101. stock FindName(name[])
  102. {
  103.     new File:check_file, getname[24], filetext[256];
  104.     check_file = fopen("Slot_Reservation/Reserved_Slots.txt", io_read);
  105.     while(fread(check_file, filetext, 256))
  106.     {
  107.         new idx;
  108.         getname = strtok(filetext, idx, ',');
  109.         if(strcmp(name, getname, false)==0)
  110.             return 1;
  111.     }
  112.     return 0;
  113. }
  114.  
  115. stock strtok(const string[], &index, separator = ' ')
  116. {
  117.     new length = strlen(string);
  118.     while ((index < length) && (string[index] <= separator))
  119.     {
  120.         index++;
  121.     }
  122.     new offset = index;
  123.     new result[24];
  124.     while ((index < length) && (string[index] > separator) && ((index - offset) < (sizeof(result) - 1)))
  125.     {
  126.         result[index - offset] = string[index];
  127.         index++;
  128.     }
  129.     result[index - offset] = EOS;
  130.     return result;
  131. }
  132.  
  133. dcmd_giveslot(playerid, cmdtext[])
  134. {
  135.     new tmp[24], idx, File:playersfile;
  136.     if(!IsPlayerAdmin(playerid))
  137.         return SendClientMessage(playerid, 0xFFFFFFFF, "You are not an admin!");
  138.     tmp = strtok(cmdtext, idx);
  139.     if(!strlen(tmp))
  140.         return SendClientMessage(playerid, 0xFFFFFFFF, "Use /giveslot [name]");
  141.     playersfile = fopen("Slot_Reservation/Reserved_Slots.txt", io_append);
  142.     format(tmp, 24, "%s,\r\n", tmp);
  143.     fwrite(playersfile, tmp);
  144.     fclose(playersfile);
  145.     return 1;
  146. }
  147.  
  148. dcmd_setslot(playerid, cmdtext[])
  149. {
  150.     new tmp[24], idx;
  151.     if(!IsPlayerAdmin(playerid))
  152.         return SendClientMessage(playerid, 0xFFFFFFFF, "You are not an admin!");
  153.     tmp = strtok(cmdtext, idx);
  154.     if(!strlen(tmp))
  155.         return SendClientMessage(playerid, 0xFFFFFFFF, "Use /setslot [admins/players] [slots]");
  156.     if(strcmp(tmp, "admins", true)==0)
  157.     {
  158.         tmp = strtok(cmdtext, idx);
  159.         if(!strlen(tmp) || strlen(tmp) > 3)
  160.             return SendClientMessage(playerid, 0xFFFFFFFF, "ERROR: Wrong slots number");
  161.         if(strval(tmp) < 0)
  162.             return SendClientMessage(playerid, 0xFFFFFFFF, "ERROR: Wrong slots number");
  163.         Options[Admins_Slots] = strval(tmp);
  164.         return 1;
  165.     }
  166.     if(strcmp(tmp, "players", true)==0)
  167.     {
  168.         tmp = strtok(cmdtext, idx);
  169.         if(!strlen(tmp) || strlen(tmp) > 3)
  170.             return SendClientMessage(playerid, 0xFFFFFFFF, "ERROR: Wrong slots number");
  171.         if(strval(tmp) < 0)
  172.             return SendClientMessage(playerid, 0xFFFFFFFF, "ERROR: Wrong slots number");
  173.         Options[Vip_Slots] = strval(tmp);
  174.     }
  175.     else
  176.         return SendClientMessage(playerid, 0xFFFFFFFF, "Use /setslot [admins/players] [slots]");
  177.     return 1;
  178. }
  179.  
  180. dcmd_showlist(playerid, cmdtext[])
  181. {
  182. #pragma unused cmdtext
  183.     new File:file, tmp[24], filetext[256];
  184.     if(!IsPlayerAdmin(playerid))
  185.         return SendClientMessage(playerid, 0xFFFFFFFF, "You are not an admin!");
  186.     if(fexist("Slot_Reservation/Reserved_Slots.txt"))
  187.     {
  188.         file = fopen("Slot_Reservation/Reserved_Slots.txt", io_read);
  189.         while(fread(file, filetext, 256))
  190.         {
  191.             new idx;
  192.             tmp = strtok(filetext, idx, ',');
  193.             SendClientMessage(playerid, 0xFFFFFF, tmp);
  194.         }
  195.     }
  196.     return 1;
  197. }
  198. dcmd_freeslots(playerid, cmdtext[])
  199. {
  200. #pragma unused cmdtext
  201.     new str[20];
  202.     format(str, 20, "Free slots %d", Options[Max_Slots] - (Options[Vip_Slots] + Options[Admins_Slots]));
  203.     SendClientMessage(playerid, 0xFFFFFFFF, str);
  204.     return 1;
  205. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement