Page 1 of 1

Scripting stuff

Posted: Tue Oct 09, 2012 11:25 pm
by Krispy
How do I give a random player a tag of 1?

OR
How can I make a random player activate a particular script....?

RE: Scripting stuff

Posted: Tue Oct 09, 2012 11:46 pm
by Qent
I don't know if it's the best way, but you can get all the players who are actually playing with PlayerInGame and Random to pick one of those.

RE: Scripting stuff

Posted: Wed Oct 10, 2012 12:08 am
by Krispy
Specify? I'd like the answer to question #1 more, BTW.

RE: Scripting stuff

Posted: Wed Oct 10, 2012 1:55 am
by Catastrophe
On an ENTER script, give everyone a new tid(eg playernumber + 1000)

Once done you can just do a random(1000, playercount+1000) for script activator.

RE: Scripting stuff

Posted: Wed Oct 10, 2012 3:04 am
by Llewellyn
Obviously replace the "do my stuff" block with your stuff and call script 3 to activate this

Code: Select all

#include "zcommon.acs"

#define P_BASETID 1000
#define MAXPLAYERS 64

script 1 ENTER
{
	Thing_ChaneTID(0, P_BASETID+PlayerNumber());
}

script 2 RESPAWN
{
	Thing_ChangeTID(PBASETID+PlayerNumber(), 0);
	Thing_ChaneTID(0, P_BASETID+PlayerNumber());
}

//Your Script
script 3 (void)
{
	int r = random(0, MAXPLAYERS-1)
	if (PlayerInGame(r))
	{
		//Do Your Stuff
		Thing_Damage(1000+r, 1000, 0);
		//End Your stuff
	}
	else
		restart;	
}

RE: Scripting stuff

Posted: Wed Oct 10, 2012 7:41 pm
by Krispy
Sorry for being so vague here's my scripts.

Code: Select all

script 1 open
{
Clearinventory();
HudMessageBold(s:"Selecting Seeker..."; HUDMSG_FADEOUT, 2, 0, 0.1, 0.8, 3.7);
//script to assign random player a tag of 1
Delay(200);
//script to get said player to activate script 2
{

script 2 (void)
{
    delay(50);
    SetFont("BIGFONT");
    printbold(n:"0", s:" \c[Green]has been chosen!");
    Thing_ChangeTID (0, 1000+PlayerNumber());
    TeleportOther(1001,4,1);
    delay(10);
    TeleportOther(1002,4,1);
    delay(10);
    TeleportOther(1003,4,1);
    delay(10);
    TeleportOther(1004,4,1);
    delay(10);
    TeleportOther(1005,4,1);
    delay(10);
    TeleportOther(1006,4,1);
    delay(10);
    TeleportOther(1007,4,1);
    delay(10);
    TeleportOther(1008,4,1);
    delay(10);
    TeleportOther(1009,4,1);
    delay(10);
    TeleportOther(1010,4,1);
    delay(10);
    TeleportOther(1011,4,1);
    delay(10);
    TeleportOther(1012,4,1);
    delay(10);
    TeleportOther(1013,4,1);
    delay(10);
    TeleportOther(1014,4,1);
    delay(10);
    TeleportOther(1015,4,1);
    delay(10);
    TeleportOther(1016,4,1);
    delay(10);
    TeleportOther(1017,4,1);//and so on...
}

And now I have one player out of however many with a tag of 1. He's special now, and he's gonna do other stuff. Everyone else I'm assuming has a tag over 1000.

RE: Scripting stuff

Posted: Thu Oct 11, 2012 3:57 am
by Llewellyn
You should have just modified the script I gave you, I'm not really fond of holding your hand for scripts anymore, you need to learn how to actually script because the script you wrote makes so many novice mistakes that it would have never worked in the first place:

Code: Select all

#include "zcommon.acs"

#define P_BASETID 1000
#define MAXPLAYERS 64

script 1 ENTER
{
    ClearInventory();
    Thing_ChaneTID(0, P_BASETID+PlayerNumber());
}

script 2 RESPAWN
{
    Thing_ChangeTID(PBASETID+PlayerNumber(), 0);
    Thing_ChangeTID(0, P_BASETID+PlayerNumber());
    Delay(1);
    Thing_ChangeTID(1, 0);
}

script 3 OPEN
{
    int r = random(0, MAXPLAYERS-1)
    if (PlayerInGame(r))
    {
        HudMessageBold(s:"Selecting Seeker..."; HUDMSG_FADEOUT, 2, 0, 0.1, 0.8, 3.7);
        Delay(250);
        Thing_ChangeTID(P_BASETID+r, 1);
        SetFont("BIGFONT");
        printbold(n:r+1, s:" \c[Green]has been chosen!");
	for (int x; x < MAXPLAYERS; ++X)
		if (x != r && PlayerInGame(x))
		{
			TeleportOther(P_BASETID+x, 4, 1);
			Delay(10); //Delay between teleports
		}
    }
    else
        restart;    
}

That code should work if your code is doing what I think it's doing.
Also, use this to make it so another seeker will be picked upon the Seeker's death (completely optional):

Code: Select all

script 4 DEATH
{
	if (ActivatorTID() == 1)
	     ACS_Execute(3,0,0,0,0); //Choose New Seeker
}
Here are some things I noticed about the code you wrote:
Spoiler: read this (Open)
Open scripts are only executed when the map opens, and has world as the activator, so it would not clear the player's inventory with clearInventory()
Your delays are in increments of 10 for no good reason, it is best practice to do Delay(35*2) or somesuch, because this means that you're delaying the script by, lets say, 2 seconds and it is easy to modify.
The less scripts the better, there is no reason to activate script outside of script one.
n:"0"
I don't even know what to say to this one, how does this even compile, you're sending it a string so it's going to access the index of the string which might just HAPPEN to be 0, or not and you should be passing it n:0 without quotes.
You're also assuming the activator of the script would be the player with TID 1, which would not be the case since it is a world script, so it would not print a name. You could have used SetActivator(1), or you could have done what I did which is just do n:r+1 being the player's playerNumber + 1 because n is 1based meaning 1 is player 0, and 33 is player 32.
Come on, please use a for loop for accessing all the players like that... also it would start at 1000 not 1001, which brings me to my next point....
You're assuming players will have the tid 1000+Playernumber without ever setting it in your scripts... how would that even work?

RE: Scripting stuff

Posted: Thu Oct 11, 2012 8:39 pm
by Krispy
I'm sorry, but
[spoiler]Image[/spoiler]
But really I'm just kidding. you're very helpful, thank you. I hope I haven't used up all my help passes by now. And you're right, I should probably have gotten the hang of this by now... Playing is by far better than scripting!