Author Topic: [unstable] joinQueue |updated|  (Read 5520 times)

0 Members and 1 Guest are viewing this topic.

Offline cooz

  • Soldier
  • **
  • Posts: 187
  • BANNED
[unstable] joinQueue |updated|
« on: November 07, 2006, 06:50:46 am »
Script Name: joinQueue
Script Description: Script which allows players enter game when server is full and wait for thier turn
(when somebody leaves) to join
Author: cooz
Core Version: 2.5.2

Code: [Select]
const
const
QUEUE_LIMIT = 6;
QUEUE_ON = 1;

var
  queue: array[1..QUEUE_LIMIT] of string;
  queueoff: array[1..32] of string;
  i,j,pos,fromlist,off,offint: integer;

procedure ActivateServer();
begin
  pos:=1;
  offint:=0;
end;

function OnRequestGame(IP: string;state: integer):integer;
begin
  off:=0;
  for i:=1 to 32 do if queueoff[i] = IP then off:= 1;
  if((State=5)and(pos<=QUEUE_LIMIT)and(QUEUE_ON=1)and(off=0)) then begin
    queue[pos]:=IP;
    pos:=pos+1;
    command('/maxplayers '+inttostr(MaxPlayers+1));
    state:=1;
  end;
  result:=state;
end;

function GetPos(IP:string):byte;
begin
  for i:=1 to pos-1 do begin
    if IP = queue[i] then begin
      Result:= i;
      break;
    end;
  end;
end;

procedure OnJoinTeam(IP, Nickname: string;Team: byte);
begin
  for i:=1 to pos-1 do if queue[i] = IP then begin
    command('/setteam5 '+inttostr(IPtoID(IP)));
    SayToPlayer(NametoID(Nickname),'Hi, please wait to play');
    SayToPlayer(NametoID(Nickname),'Your place on queue: '+inttostr(GetPos(IP)));
  end;
end;

function IDtoIP(PlayerID: integer):string;
begin
  case PlayerID of
    1: Result:= Player_IP_1;
    2: Result:= Player_IP_2;
    3: Result:= Player_IP_3;
    4: Result:= Player_IP_4;
    5: Result:= Player_IP_5;
    6: Result:= Player_IP_6;
    7: Result:= Player_IP_7;
    8: Result:= Player_IP_8;
    9: Result:= Player_IP_9;
    10: Result:= Player_IP_10;
    11: Result:= Player_IP_11;
    12: Result:= Player_IP_12;
    13: Result:= Player_IP_13;
    14: Result:= Player_IP_14;
    15: Result:= Player_IP_15;
    16: Result:= Player_IP_16;
    17: Result:= Player_IP_17;
    18: Result:= Player_IP_18;
    19: Result:= Player_IP_19;
    20: Result:= Player_IP_20;
    21: Result:= Player_IP_21;
    22: Result:= Player_IP_22;
    23: Result:= Player_IP_23;
    24: Result:= Player_IP_24;
    25: Result:= Player_IP_25;
    26: Result:= Player_IP_26;
    27: Result:= Player_IP_27;
    28: Result:= Player_IP_28;
    29: Result:= Player_IP_29;
    30: Result:= Player_IP_30;
    31: Result:= Player_IP_31;
    32: Result:= Player_IP_32;
  end;
end;

procedure OnLeaveGame(IP: string; Nickname: string;Team: byte);
begin
  if QUEUE_ON=1 then begin
    fromlist:=0;
    for i:=1 to pos-1 do if IDtoIP(NametoID(Nickname)) = queue[i] then begin
      fromlist:=1;
      command('/maxplayers '+inttostr(MaxPlayers-1));
      for j:=i+1 to pos-1 do queue[j-1]:= queue[j];
      queue[pos-1]:='';
      pos:=pos-1;
    end;

    if((queue[1]<>'')and(fromlist=0)) then begin
      command('/setteam'+inttostr(Team)+' '+inttostr(IPtoID(queue[1])));
  //command('/setteam'+iif(BravoPlayers>AlphaPlayers,1,2)+' '+inttostr(IPtoID(queue[1])));
  //makes teams more equal, but works only for ctf/inf
      command('/maxplayers '+inttostr(MaxPlayers-1));
      for i:=2 to pos-1 do queue[i-1]:= queue[i];
      queue[pos-1]:='';
      pos:=pos-1;
    end;
  end;
end;

procedure OnCommand(ID: integer;Text: string);
begin
  if Copy(Text,1,9) = '/qoffadd ' then begin
      if(Length(Text)>15)then begin
        offint:=offint+1;
        queueoff[offint]:= Copy(Text,10,Length(Text)-9);
        SaytoPlayer(ID, queueoff[offint]+' was added to queueoff list');
      end
       else if((IDtoName(strtoint(Copy(Text,10,Length(Text)-9)))<>'') and (strtoint(Copy(Text,10,Length(Text)-9))<=32)) then begin
         offint:=offint+1;
         queueoff[offint]:= IDtoIP(strtoint(Copy(Text,10,Length(Text)-9)));
         SaytoPlayer(ID, IDtoName(strtoint(Copy(Text,10,Length(Text)-9)))+' was added to queueoff list');
       end
        else SaytoPlayer(ID, 'there''s no player with such ID');
  end;

  if Text = '/qoffshow' then begin
    if offint <> 0 then begin for i:=1 to offint do SaytoPlayer(ID, inttostr(i)+': '+ queueoff[i]+iif(IPtoID(queueoff[i])=32,' [not on server]',' ID: '+inttostr(IPtoID(queueoff[i])))); end
     else SaytoPlayer(ID, 'queueoff list is empty');
  end;

  if Copy(Text,1,9) = '/qoffdel ' then begin
    if strtoint(Copy(Text,10,Length(Text)-9)) <= offint then begin
      SaytoPlayer(ID, queueoff[strtoint(Copy(Text,10,Length(Text)-9))]+ ' was deleted from queueoff list');
      for i:=strtoint(Copy(Text,10,Length(Text)-9))+1 to offint do queueoff[i-1]:= queueoff[i];
      queueoff[offint]:='';
      offint:=offint-1;
    end
     else SaytoPlayer(ID, 'there''s no such position on queueoff list');
  end;

  if Text = '/qoffclear' then begin
    SaytoPlayer(ID, 'queueoff list was cleared');
    for i:=1 to offint do queueoff[i]:='';
    offint:=0;
  end;

  if Text = '/qclear' then begin
    for i:=1 to pos-1 do begin
      KickPlayer(IPtoID(queue[i]));
      queue[i]:='';
      command('/maxplayers '+inttostr(MaxPlayers-1));
    end;
    pos:=1;
  end;

  if Text = '/qshow' then begin
    if pos<>1 then begin for i:=1 to pos-1 do SayToPlayer(ID,inttostr(i)+': '+queue[i]+' nick: '+IDtoName(IPtoID(queue[i]))); end
     else SaytoPlayer(ID, 'queue list is empty');
  end;
end;

procedure OnPlayerSpeak(Name,Text: string);
begin
  if Text = '!queue' then begin
    if GetPos(IDtoIP(NametoID(Name))) = 0 then begin SayToPlayer(NametoID(Name),'You''re not on queue'); end
      else SayToPlayer(NametoID(Name),'Your place on queue: '+inttostr(GetPos(IDtoIP(NametoID(Name)))));
  end;
end;

features:
- after joining full server person is moved to spectators, also on first position on queue, when there's free slot he joins one of teams
- user commands:
  !queue - shows person postion on queue
- admin commands:
  /qshow - shows queue in "IP nick" format
  /qclear - removes all players from queue
  /qoffadd - add player to queueoff list (usage: /qoffadd PlayerID or /qoffadd IP)
  /qoffdel - remove player from queueoff list (usage: /qoffadel queueoff_list_number)
  /qoffshow - shows queueoff list
- script switches, on beginning of joinQueue.pas in const block there are:
  QUEUE_LIMIT - length of queue (default: 8 )
  QUEUE_ON - turns off/on joinQueue script (default: 1 )

known issues:
- script won't work for DM cause afik therer's still no way to set DM team after someone was in spectators
- server will show wrong(higher) player limit on lobby, i advice to put correct into server name
  (eg. "Shotgun|CTF ::MaxPlrs:10")
- script doesn't react when somebody is kicked (fix on todo list)
- script is based on IP queue list, so on duplicated IPs akward things may happen (fix on todo list)

edit:
i added queueoff list, person added to it won't be moved on queue so if server is full he won't get it, also i recomend to add all admins to this list so bug like Avarax's one won't occur (oh and maybe someone would prefer file list option?)

i changed also way to check if someone should be moved to spectators so bug like Flying Dutchman's one maybe won't occur

cause of not reacting for kicked players i don't recomend to use that script yet, let's hope there'll be possibility to fix that in next server version...
« Last Edit: November 21, 2006, 07:59:54 pm by cooz »
Dead man! Dead man walking! We got a dead man walking here! Banned man crawling more like

Offline Avarax

  • Veteran
  • *****
  • Posts: 1529
    • Official Hexer & MMod site
Re: joinQueue
« Reply #1 on: November 07, 2006, 08:01:06 am »
very nice indeed, how do i add it to my scripts? :D
I like to have one Martini
Two at the very most
Three I'm under the table
Four I'm under the host

Offline cooz

  • Soldier
  • **
  • Posts: 187
  • BANNED
Re: joinQueue
« Reply #2 on: November 07, 2006, 10:56:59 am »
i think it is more general question...

to add it, you have to replace orginal procedures and add const,var blocks somewhere at beginning of file with them, also procedures which are sharing variables have to stay in one file

for example i'll attach ziped scripts/ folder for joinQueue script
Dead man! Dead man walking! We got a dead man walking here! Banned man crawling more like

Offline Avarax

  • Veteran
  • *****
  • Posts: 1529
    • Official Hexer & MMod site
Re: joinQueue
« Reply #3 on: November 07, 2006, 05:07:43 pm »
found a bug, if your IP is logged as admin already and you rejoin the full server, you will be alive allthough script puts you in queue.
this made me show as spectator to other players, but on my screen i was moving just as if like Deadwalk hack and i was able to kill others with nothing but nades. also, i survived the end of a round (my server is R/S) but the game commenced without noticing me still alive.
otherwise the script seems to work...
I like to have one Martini
Two at the very most
Three I'm under the table
Four I'm under the host

Offline cooz

  • Soldier
  • **
  • Posts: 187
  • BANNED
Re: joinQueue
« Reply #4 on: November 07, 2006, 06:50:33 pm »
this script can have more bugs than other ones cause i couldn't test it as i would like to,
yep, admins can make it work in wrong way

as far as i know there's no any variable which tells if someone is logged as admin
and it looks like there's also no easy way to catch them when they're logging in, i can't read remote.txt(and i'm not sure if all admins are listed there) cause of bug in split()...

what would you say for additional admin command, something like:
'/queueoff userID' (it will work on IPs anyway) which won't let in normal user when server is full, and admins server will enter simply cause they can ::)

or maybe you have in your mind suggest for another solution?
Dead man! Dead man walking! We got a dead man walking here! Banned man crawling more like

Offline Mistercharles

  • Veteran
  • *****
  • Posts: 1371
  • +
Re: joinQueue
« Reply #5 on: November 07, 2006, 09:38:34 pm »
Cooz, you're a brilliant scripter. 5 points for you (+1 karma for a week).
shoutout to m'boyz eagles_arrows, echo_trail, wraithlike, sadistatheart, chakapoko maker, jrgp, aznblood, chakra, keron cyst, et al, miss you, let's '#gather some day

Offline Valorman

  • Flagrunner
  • ****
  • Posts: 545
Re: joinQueue
« Reply #6 on: November 07, 2006, 10:41:05 pm »
Bloody Brilliant! Appluad-tacular!
.

Offline Flying Dutchman

  • Soldier
  • **
  • Posts: 242
  • Boomshakalack!
    • Real Soldat!
Re: joinQueue
« Reply #7 on: November 08, 2006, 10:18:15 am »
Awesome script, added it to my server to try it out.
I've noticed that sometimes people always get changed to spectator as soon as they join, even if there's room. And if they try to move to a team, they will be putted back on spectator again.

Edit: Here's picture of the log in ARSSE. You can see him trying to join a team (... has left spectators) but he's immidiatly putted back on spectators even if there's room. I don't know if this is a bug in the script or a fault from my side, but it would be nice if it could be fixed. :)

« Last Edit: November 08, 2006, 12:15:52 pm by Flying Dutchman »

Offline cooz

  • Soldier
  • **
  • Posts: 187
  • BANNED
Re: joinQueue [unstable] |updated|
« Reply #8 on: November 11, 2006, 01:56:37 pm »
script updated, check first post
Dead man! Dead man walking! We got a dead man walking here! Banned man crawling more like