ACS Help - Waiting Queue

Discuss all aspects related to modding Zandronum here.
Post Reply
User avatar
fr blood
Frequent Poster Miles card holder
Posts: 995
Joined: Wed Mar 06, 2013 4:04 pm
Location: France

ACS Help - Waiting Queue

#1

Post by fr blood » Sun Nov 22, 2015 6:04 pm

Hi everyone, I would like to know how to make a waiting queue for players with only ACS.

In my Invasion Project when people die they are teleported in the waiting room, if there are no reinforcement then the waiting queue is turned on and will free the 1st player who spawned in the room in a random delay then loop and deal with the second.

I know ACS but don't know where to start to make it works.

Thanks for the help.

Jigsaw
Forum Regular
Posts: 180
Joined: Sun Jun 24, 2012 9:43 am

RE: ACS Help - Waiting Queue

#2

Post by Jigsaw » Sun Nov 22, 2015 8:25 pm

A quirky but surefire way could be creating a dummy ammotype, and giving 1 of it to every player each time someone spawns in there. That way, the player with most of that ammotype would be the first one. Then you can use CheckInventory to see how many the player has, and if they have enough (should be the number of players you want in there), then they get to teleport back AND lose all of that ammotype. This could work by itself too, if implemented correctly, but also requires DECORATE.
Spoiler: Decorate code (Open)
Actor CountMeIn : Ammo
{
Inventory.Maxamount 10 //Change this according to how many players you want in there
Ammo.Backpackmaxamount 10 //this too
}
Spoiler: ACS (Open)
script 3 ENTER //Need ENTER so every player activates it upon entering level.
{
If (CheckInventory("CountMeIn")) == 10
{
TakeInventory("CountMeIn",10);
Teleport(X,Y,1);
}
delay (1); //need a delay because this'll be repeating constantly
restart;
}
For giving a CountMeIn to everyone that enters the spawn area, you need to define a RESPAWN script with a FOR loop and GiveActorInventory, like this:
Spoiler: ACS (Open)
script 4 respawn
{
acs_execute (3,0,0,0,0); //activate the ENTER script once again.
int playerid = 0;

for (playerid = 200; playerid < 264; playerid++ ) // Repeats until playernumbers 200-264 have been given the items once.
{
GiveActorInventory(playerid,"CountMeIn",1);
}
}
Last edited by Jigsaw on Sun Nov 22, 2015 8:52 pm, edited 1 time in total.

User avatar
ZZYZX
Posts a lot
Posts: 742
Joined: Thu Jun 07, 2012 5:56 pm
Location: Ukraine
Clan: A3
Clan Tag: [A3]

RE: ACS Help - Waiting Queue

#3

Post by ZZYZX » Sun Nov 22, 2015 11:29 pm

"surefire way"

[spoiler]

Code: Select all

#define MAXPLAYERS 64
int WaitQueueLen = 0;
int WaitQueue[MAXPLAYERS+1];

function bool WQ_Contains(int playernum)
{
  for (int i = 0; i < WaitQueueLen; i++)
  {
    if (WaitQueue[i] == playernum)
      return true;
  }
  return false;
}

function void WQ_AddPlayer(int playernum)
{
  if (WQ_Contains(playernum))
    return;
  WaitQueue[WaitQueueLen] = playernum; // put at the end of the queue
  WaitQueueLen++;
}

function void WQ_RemovePlayer(int playernum)
{
  bool found = false;
  for (int i = 0; i < WaitQueueLen; i++)
  {
    if (WaitQueue[i] == playernum)
      found = true;
    if (found) WaitQueue[i] = WaitQueue[i+1];
  }
  if (found) WaitQueueLen--;
}

function int WQ_RemoveFirstPlayer(void)
{
  if (WaitQueueLen <= 0) return -1;
  int player = WaitQueue[0];
  WQ_RemovePlayer(player);
  return player;
}
[/spoiler]

On DEATH (that, or ENTER and RESPAWN), run WQ_AddPlayer. Then once WaitQueueLen is above 0, wait your random delay and run WQ_RemoveFirstPlayer.
The number returned by WQ_RemoveFirstPlayer is the first player from the queue.
On DISCONNECT, run WQ_RemovePlayer on the player that disconnects.

The code isn't tested, but should work.
Last edited by ZZYZX on Sun Nov 22, 2015 11:43 pm, edited 1 time in total.

User avatar
fr blood
Frequent Poster Miles card holder
Posts: 995
Joined: Wed Mar 06, 2013 4:04 pm
Location: France

RE: ACS Help - Waiting Queue

#4

Post by fr blood » Mon Nov 23, 2015 7:09 am

Thank for you help guys, this seems very hard as I tought, I'll keep you guys informed if I managed or not to make it works properly.

User avatar
fr blood
Frequent Poster Miles card holder
Posts: 995
Joined: Wed Mar 06, 2013 4:04 pm
Location: France

RE: ACS Help - Waiting Queue

#5

Post by fr blood » Sun Jan 10, 2016 3:55 pm

Sorry I didn't manage to impliment it into my wad.

Post Reply