Page 1 of 1
Give randomly script?
Posted: Thu Jun 16, 2016 6:45 am
by Zeberpal
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
or something like that.
I just ask for some very simple variation

Re: Give randomly script?
Posted: Thu Jun 16, 2016 8:30 am
by ZZYZX
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);
Re: Give randomly script?
Posted: Thu Jun 16, 2016 9:32 am
by Zeberpal
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
Re: Give randomly script?
Posted: Thu Jun 16, 2016 9:49 am
by ZZYZX
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);
}
Re: Give randomly script?
Posted: Thu Jun 16, 2016 11:18 am
by Zeberpal
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);
}
Re: Give randomly script?
Posted: Thu Jun 16, 2016 3:23 pm
by Sean
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.