Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #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
- enum Opt
- {
- Time_Check,
- Admins_Slots,
- Vip_Slots,
- Max_Slots
- }
- enum Stat
- {
- Admins_Online,
- Vip_Online,
- Timer[200],
- Players
- }
- new Options[Opt];
- new Status[Stat];
- forward CheckPlayer(playerid);
- public OnFilterScriptInit()
- {
- print("\n--------------------------------------\nSlots Reservation by Conan/Destrojer v0.2\n--------------------------------------\n");
- Options[Max_Slots] = GetMaxPlayers();
- Options[Vip_Slots] = 1;
- Options[Admins_Slots] = 1;
- return 1;
- }
- public OnFilterScriptExit()
- {
- print("\n--------------------------------------\nSlots Reservation unloaded\n--------------------------------------\n");
- return 1;
- }
- public OnPlayerRequestSpawn(playerid)
- {
- Status[Players]++;
- if(Status[Players] >= (Options[Max_Slots] - (Options[Vip_Slots] + Options[Admins_Slots])))
- Status[Timer][playerid] = SetTimerEx("CheckPlayer", 10*1000, 0, "d", playerid);
- if(fexist("Slot_Reservation/Reserved_Slots.txt"))
- if(FindName(PlayerName(playerid)))
- Status[Vip_Online]++;
- return 1;
- }
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- dcmd(giveslot, 8, cmdtext);
- dcmd(setslot, 7, cmdtext);
- dcmd(showlist, 8, cmdtext);
- dcmd(freeslots, 9, cmdtext);
- return 0;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- if(fexist("Slot_Reservation/Reserved_Slots.txt"))
- if(FindName(PlayerName(playerid)))
- Status[Vip_Online]--;
- if(IsPlayerAdmin(playerid))
- Status[Admins_Online]--;
- Status[Admins_Online] = Status[Admins_Online]>=0 ? Status[Admins_Online] : 0;
- Status[Vip_Online] = Status[Vip_Online]>=0 ? Status[Vip_Online] : 0;
- return 1;
- }
- public CheckPlayer(playerid)
- {
- KillTimer(Status[Timer][playerid]);
- if(fexist("Slot_Reservation/Reserved_Slots.txt"))
- {
- if(FindName(PlayerName(playerid)) == 0 && (Options[Vip_Slots] - Status[Vip_Online]) > 0 && Options[Vip_Slots] > 0)
- {
- SendClientMessage(playerid, 0xFFFFFFFF, "Sorry, this slot is reserved");
- Kick(playerid);
- return 1;
- }
- }
- if(!IsPlayerAdmin(playerid) && (Options[Admins_Slots] - Status[Admins_Online]) > 0 && Options[Admins_Slots] > 0)
- {
- SendClientMessage(playerid, 0xFFFFFFFF, "Sorry, this slot is reserved");
- Kick(playerid);
- }
- else
- Status[Admins_Online]++;
- return 1;
- }
- stock PlayerName(playerid)
- {
- new name[24];
- GetPlayerName(playerid, name, 24);
- return name;
- }
- stock FindName(name[])
- {
- new File:check_file, getname[24], filetext[256];
- check_file = fopen("Slot_Reservation/Reserved_Slots.txt", io_read);
- while(fread(check_file, filetext, 256))
- {
- new idx;
- getname = strtok(filetext, idx, ',');
- if(strcmp(name, getname, false)==0)
- return 1;
- }
- return 0;
- }
- stock strtok(const string[], &index, separator = ' ')
- {
- new length = strlen(string);
- while ((index < length) && (string[index] <= separator))
- {
- index++;
- }
- new offset = index;
- new result[24];
- while ((index < length) && (string[index] > separator) && ((index - offset) < (sizeof(result) - 1)))
- {
- result[index - offset] = string[index];
- index++;
- }
- result[index - offset] = EOS;
- return result;
- }
- dcmd_giveslot(playerid, cmdtext[])
- {
- new tmp[24], idx, File:playersfile;
- if(!IsPlayerAdmin(playerid))
- return SendClientMessage(playerid, 0xFFFFFFFF, "You are not an admin!");
- tmp = strtok(cmdtext, idx);
- if(!strlen(tmp))
- return SendClientMessage(playerid, 0xFFFFFFFF, "Use /giveslot [name]");
- playersfile = fopen("Slot_Reservation/Reserved_Slots.txt", io_append);
- format(tmp, 24, "%s,\r\n", tmp);
- fwrite(playersfile, tmp);
- fclose(playersfile);
- return 1;
- }
- dcmd_setslot(playerid, cmdtext[])
- {
- new tmp[24], idx;
- if(!IsPlayerAdmin(playerid))
- return SendClientMessage(playerid, 0xFFFFFFFF, "You are not an admin!");
- tmp = strtok(cmdtext, idx);
- if(!strlen(tmp))
- return SendClientMessage(playerid, 0xFFFFFFFF, "Use /setslot [admins/players] [slots]");
- if(strcmp(tmp, "admins", true)==0)
- {
- tmp = strtok(cmdtext, idx);
- if(!strlen(tmp) || strlen(tmp) > 3)
- return SendClientMessage(playerid, 0xFFFFFFFF, "ERROR: Wrong slots number");
- if(strval(tmp) < 0)
- return SendClientMessage(playerid, 0xFFFFFFFF, "ERROR: Wrong slots number");
- Options[Admins_Slots] = strval(tmp);
- return 1;
- }
- if(strcmp(tmp, "players", true)==0)
- {
- tmp = strtok(cmdtext, idx);
- if(!strlen(tmp) || strlen(tmp) > 3)
- return SendClientMessage(playerid, 0xFFFFFFFF, "ERROR: Wrong slots number");
- if(strval(tmp) < 0)
- return SendClientMessage(playerid, 0xFFFFFFFF, "ERROR: Wrong slots number");
- Options[Vip_Slots] = strval(tmp);
- }
- else
- return SendClientMessage(playerid, 0xFFFFFFFF, "Use /setslot [admins/players] [slots]");
- return 1;
- }
- dcmd_showlist(playerid, cmdtext[])
- {
- #pragma unused cmdtext
- new File:file, tmp[24], filetext[256];
- if(!IsPlayerAdmin(playerid))
- return SendClientMessage(playerid, 0xFFFFFFFF, "You are not an admin!");
- if(fexist("Slot_Reservation/Reserved_Slots.txt"))
- {
- file = fopen("Slot_Reservation/Reserved_Slots.txt", io_read);
- while(fread(file, filetext, 256))
- {
- new idx;
- tmp = strtok(filetext, idx, ',');
- SendClientMessage(playerid, 0xFFFFFF, tmp);
- }
- }
- return 1;
- }
- dcmd_freeslots(playerid, cmdtext[])
- {
- #pragma unused cmdtext
- new str[20];
- format(str, 20, "Free slots %d", Options[Max_Slots] - (Options[Vip_Slots] + Options[Admins_Slots]));
- SendClientMessage(playerid, 0xFFFFFFFF, str);
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement