Give randomly script?

Discuss all aspects related to modding Zandronum here.
Post Reply
User avatar
Zeberpal
Forum Regular
Posts: 476
Joined: Mon Jun 04, 2012 6:55 am

Give randomly script?

#1

Post by Zeberpal » Thu Jun 16, 2016 6:45 am

Hello Zandronum!

I was wondering, how to give a shotgun to a random player via acs?

I would like to write down some code here, but I don't really know where to start.

For one thing I know, it have to contain

Code: Select all

for(int v = 0; v < 32; v++)
or something like that.

I just ask for some very simple variation :gasp:

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

Re: Give randomly script?

#2

Post by ZZYZX » Thu Jun 16, 2016 8:30 am

something similar used in ctfcap2

Code: Select all

int randomplayers[64];
int randomplayerslen = 0;

/* ---------------- */
int i;
randomplayerslen = 0;
for (i = 0; i < 64; i++)
{
  if (!PlayerInGame(i)) continue;
  randomplayers[randomplayerslen] = i;
  randomplayerslen++;
}

if (!randomplayerslen) terminate;

int p = random(0, randomplayerslen);
SetActivator(playertid_base+randomplayers[p]);
GiveInventory("Shotgun", 1);

User avatar
Zeberpal
Forum Regular
Posts: 476
Joined: Mon Jun 04, 2012 6:55 am

Re: Give randomly script?

#3

Post by Zeberpal » Thu Jun 16, 2016 9:32 am

ZZYZX, thanks.
However, GZDB could not compile it, barking on playertid_base. And I thought it's missing something. So i manually added some stuff in order to try to get it work
here's what I did.

Code: Select all

#include "zcommon.acs"
#define MAXPLAYERS 64       //<----THIS        
#define PLAYERTID_BASE 1    //<----THIS      

int randomplayers[64];
int randomplayerslen = 0;


script 666(void)          //<----THIS      
{
/* ---------------- */
int i;
randomplayerslen = 0;
for (i = 0; i < 64; i++)
{
  if (!PlayerInGame(i)) continue;
  randomplayers[randomplayerslen] = i;
  randomplayerslen++;
}

if (!randomplayerslen) terminate;

int p = random(0, randomplayerslen);
SetActivator(playertid_base+randomplayers[p]);
GiveInventory("Shotgun", 1);
}
it seems to half-work, except for all players get shotgun(onlinetested). The point was to give it to a one single player out of all the others online

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

Re: Give randomly script?

#4

Post by ZZYZX » Thu Jun 16, 2016 9:49 am

playertid_base is something you use for base for player tid.
Because ZDoom only has 8 players for SetActivator and Zandronum STILL DOESN'T HAVE A WAY TO SET ACTIVATOR TO PLAYERS ABOVE EIGHT!!!!!! (insert sudden Crowley yelling here) you will have to do something like this:

Code: Select all

#define PTID_BASE 16000

script "PTID_Set" ENTER
{
  while (true)
  {
    if (GetActorProperty(0, APROP_Health) > 0) // don't use RESPAWN. RESPAWN breaks with resurrect console command (it doesn't get called). ENTER scripts have their activator updated on respawn though.
      Thing_ChangeTID(0, PTID_BASE+PlayerNumber());
    Delay(1);
  }
}

script "PTID_Unset" DEATH
{
  Thing_ChangeTID(0, 0);
}

User avatar
Zeberpal
Forum Regular
Posts: 476
Joined: Mon Jun 04, 2012 6:55 am

Re: Give randomly script?

#5

Post by Zeberpal » Thu Jun 16, 2016 11:18 am

ZZYZX, looks like it worked! Thanks! Too pity I can't test it with more than two players per IP.
In case you you want to see the whole script, just maybe some mistakes I've done.

Code: Select all

#include "zcommon.acs"
#define MAXPLAYERS 32
#define PTID_BASE 16000

int randomplayers[32];
int randomplayerslen = 0;

script "PTID_Set" ENTER
{
  while (true)
  {
    if (GetActorProperty(0, APROP_Health) > 0) // don't use RESPAWN. RESPAWN breaks with resurrect console command (it doesn't get called).
      Thing_ChangeTID(0, PTID_BASE+PlayerNumber());
    Delay(1);
  }
}

script "PTID_Unset" DEATH
{
  Thing_ChangeTID(0, 0);
}

script 111(void)
{
/* ---------------- */
int i;
randomplayerslen = 0;
for (i = 0; i < 32; i++)
{
  if (!PlayerInGame(i)) continue;
  randomplayers[randomplayerslen] = i;
  randomplayerslen++;
}

if (!randomplayerslen) terminate;

int p = random(0, randomplayerslen);
SetActivator(ptid_base+randomplayers[p]);
GiveInventory("Shotgun", 1);
}

User avatar
Sean
IRC Operator
Posts: 982
Joined: Thu Jan 16, 2014 9:09 pm
Location: United Kingdom
Clan: Zandronum
Clan Tag: [Za]
Contact:

Re: Give randomly script?

#6

Post by Sean » Thu Jun 16, 2016 3:23 pm

ZZYZX wrote:playertid_base is something you use for base for player tid.
Because ZDoom only has 8 players for SetActivator and Zandronum STILL DOESN'T HAVE A WAY TO SET ACTIVATOR TO PLAYERS ABOVE EIGHT!!!!!!
You don't even need SetActivator here. Use GiveActorInventory instead.
<capodecima> i dont say any more word without my loyer jenova

Post Reply