Page 1 of 1

ACS Team Player Problems

Posted: Tue Jan 06, 2015 6:33 pm
by Captain Toenail
I'm trying to setup a new gamemode that works with TLMS.

The gist of it is, every 10 seconds one team is given a weapon and the other is disarmed. This alternates till everyone on one team is dead.

Problem is my script is giving both teams the weapon at the same time, and then disarming both teams at the same time. I'm stumped, any ideas?

Attempt 1:

Code: Select all

#include "zcommon.acs"

// assign players a TID
Script 749 ENTER
{
	Thing_ChangeTID(0, 1000 + PlayerNumber()); // This assigns the TID
}

// Set player health to 1 and remove all weapons
script 751 ENTER
{
    int playerTID = ActivatorTID();

    SetActorProperty (playerTID, APROP_Health, 1);
    ClearInventory();
}

// Set player health to 1 and remove all weapons
script 750 RESPAWN
{
    int playerTID = ActivatorTID();

    SetActorProperty (playerTID, APROP_Health, 1);
    ClearInventory();
}


// choose starting team
script 754 OPEN
{
    ACS_Execute(random(752, 753), 0, 0, 0, 0);
}

// red team then blue team
script 752 (void)
{
    ACS_Execute (755, 0, 0, 0, 0);
    Delay (350); // 10 seconds
    ACS_Execute (756, 0, 0, 0, 0);
    Delay (350);
    Restart;
}

// blue team then red team
script 753 (void)
{
    ACS_Execute (756, 0, 0, 0, 0);
    Delay (350); // 10 seconds
    ACS_Execute (755, 0, 0, 0, 0);
    Delay (350);
    Restart;
}

// give red team chainsaws
script 755 (void)
{
    int playerTID = ActivatorTID();
    int teamNumber = GetPlayerInfo(playerTID, PLAYERINFO_TEAM);
    
    if (teamNumber == 1)
    {
        Print (s:"Give RED TEAM chainsaws");
        GiveInventory("Chainsaw", 1);
    }
    else
    {
        ClearInventory();
    }
}

// give blue team chainsaws
script 756 (void)
{
    int playerTID = ActivatorTID();
    int teamNumber = GetPlayerInfo(playerTID, PLAYERINFO_TEAM);
    
    if (teamNumber == 0)
    {
        Print (s:"Give BLUE TEAM chainsaws");
        GiveInventory("Chainsaw", 1);
    }
    else
    {
        ClearInventory();
    }
}
Attempt 2:

Code: Select all

Script 1 OPEN
{
    ACS_ExecuteAlways(2, 0, 0, 0);
    Delay(350);
    ACS_ExecuteAlways(3, 0, 0, 0);
    Delay(350);
    Restart;
}

Script 2 (void)
{
    int teamNumber = GetPlayerInfo(0, PLAYERINFO_TEAM);
    if (teamNumber == 0)
    {
        GiveInventory("Chainsaw", 1);
    }
    else
    {
        ClearInventory();
    }
}

Script 3 (void)
{
    int teamNumber = GetPlayerInfo(0, PLAYERINFO_TEAM);
    if (teamNumber == 1)
    {
        GiveInventory("Chainsaw", 1);
    }
    else
    {
        ClearInventory();
    }
}

Script 4 ENTER
{
    //SetActorProperty (0, APROP_Health, 1);
    ClearInventory();
}

Script 5 RESPAWN
{
    //SetActorProperty (0, APROP_Health, 1);
    ClearInventory();
}

RE: ACS Team Player Problems

Posted: Tue Jan 06, 2015 7:22 pm
by Vincent(PDP)

Code: Select all

int playerTID = ActivatorTID();
Here's your problem. The script is originally activated by the server (via the OPEN script), which means the tid returns -1. When the server activates it it will apply to every single player.

You need to do a loop through all players.

Code: Select all

For(Int i=0; i<64; i++)
{
    If(PlayerInGame(1000+i) && GetPlayerInfo(1000+i, PLAYERINFO_TEAM) == TEAM_RED)
    {
        GiveActorInventory(1000+i, "Chainsaw", 1);
    }
    Else If(PlayerInGame(1000+i) && GetPlayerInfo(1000+i, PLAYERINFO_TEAM) != TEAM_RED)
    {
        ClearActorInventory(1000+i);
    }
}

RE: ACS Team Player Problems

Posted: Tue Jan 06, 2015 7:45 pm
by Captain Toenail
Hmm, ok thanks Vincent, that makes sense. However now when I run the map no players receive weapons at all. Any ideas?

Code: Select all

#include "zcommon.acs"


// assign players a TID
Script 749 ENTER
{
	Thing_ChangeTID(0, 1000 + PlayerNumber()); // This assigns the TID
}

// Set player health to 1 and remove all weapons
script 751 ENTER
{
    SetActorProperty (0, APROP_Health, 1);
    ClearInventory();
}

// Set player health to 1 and remove all weapons
script 750 RESPAWN
{
    SetActorProperty (0, APROP_Health, 1);
    ClearInventory();
}


// choose starting team
script 754 OPEN
{
    ACS_Execute(random(752, 753), 0, 0, 0, 0);
}

// red team then blue team
script 752 (void)
{
    ACS_Execute (755, 0, 0, 0, 0);
    Delay (350); // 10 seconds
    ACS_Execute (756, 0, 0, 0, 0);
    Delay (350);
    Restart;
}

// blue team then red team
script 753 (void)
{
    ACS_Execute (756, 0, 0, 0, 0);
    Delay (350); // 10 seconds
    ACS_Execute (755, 0, 0, 0, 0);
    Delay (350);
    Restart;
}

// give red team chainsaws
script 755 (void)
{

For(Int i=0; i<64; i++)
{
    If(PlayerInGame(1000+i) && GetPlayerInfo(1000+i, PLAYERINFO_TEAM) == TEAM_RED)
    {
        GiveActorInventory(1000+i, "Chainsaw", 1);
    }
    Else If(PlayerInGame(1000+i) && GetPlayerInfo(1000+i, PLAYERINFO_TEAM) != TEAM_RED)
    {
        ClearActorInventory(1000+i);
    }
}
}

// give blue team chainsaws
script 756 (void)
{

For(Int i=0; i<64; i++)
{
    If(PlayerInGame(1000+i) && GetPlayerInfo(1000+i, PLAYERINFO_TEAM) == TEAM_BLUE)
    {
        GiveActorInventory(1000+i, "Chainsaw", 1);
    }
    Else If(PlayerInGame(1000+i) && GetPlayerInfo(1000+i, PLAYERINFO_TEAM) != TEAM_BLUE)
    {
        ClearActorInventory(1000+i);
    }
}
}

RE: ACS Team Player Problems

Posted: Tue Jan 06, 2015 7:50 pm
by Vincent(PDP)
How about this?

Code: Select all

GetPlayerInfo(i, PLAYERINFO_TEAM) == TEAM_RED

RE: ACS Team Player Problems

Posted: Tue Jan 06, 2015 8:06 pm
by Captain Toenail
The player's now receive their weapons, but the original problem is back in that both teams receive and lose weapons at the same time.

I think it is because the server is activating the script rather than the players individually as you said earlier. I don't know how to go about that unfortunately.

RE: ACS Team Player Problems

Posted: Tue Jan 06, 2015 8:10 pm
by Vincent(PDP)
Captain Toenail wrote: The player's now receive their weapons, but the original problem is back in that both teams receive and lose weapons at the same time.

I think it is because the server is activating the script rather than the players individually as you said earlier. I don't know how to go about that unfortunately.
That's strange... According to code it should only give the players in the specific team.
I will try the code and see what happens.

... Neither of the scripts works for me.
Okay this works a 100% to me:

Code: Select all

 // give red team chainsaws
 script 755 (void)
 {
 For(Int i=0; i<64; i++)
 {
     If(PlayerInGame(i) == True && GetPlayerInfo(i, PLAYERINFO_TEAM) == TEAM_RED)
     {
         GiveActorInventory(1000+i, "Chainsaw", 1);
     }
     Else If(PlayerInGame(i) == True && GetPlayerInfo(i, PLAYERINFO_TEAM) == TEAM_BLUE)
     {
         ClearActorInventory(1000+i);
     }
 }
 }

 // give blue team chainsaws
 script 756 (void)
 {
 For(Int i=0; i<64; i++)
 {
     If(PlayerInGame(i) == True && GetPlayerInfo(i, PLAYERINFO_TEAM) == TEAM_BLUE)
     {
         GiveActorInventory(1000+i, "Chainsaw", 1);
     }
     Else If(PlayerInGame(i) == True && GetPlayerInfo(i, PLAYERINFO_TEAM) == TEAM_RED)
     {
         ClearActorInventory(1000+i);
     }
 }
 }

RE: ACS Team Player Problems

Posted: Tue Jan 06, 2015 10:10 pm
by Captain Toenail
Excellent, thank you! :smile:

RE: ACS Team Player Problems

Posted: Wed Jan 07, 2015 5:54 am
by Dusk
Whoops, I accidentally made it shorter.

Code: Select all

// give offensive team chainsaws
script 755 (int offensiveTeam)
{
	for (int i = 0; i < 64; i++)
	{
		if (PlayerInGame(i) == false)
			continue;
		
		if (GetPlayerInfo(i, PLAYERINFO_TEAM) == offensiveTeam)
			GiveActorInventory(1000+i, "Chainsaw", 1);
		else
			ClearActorInventory(1000+i);
	}
}

RE: ACS Team Player Problems

Posted: Wed Jan 07, 2015 6:52 am
by Lollipop
If it isn't uber important that all players have an unique id, then all players on one team can use one id and the other team another id.

RE: ACS Team Player Problems

Posted: Wed Jan 07, 2015 10:01 am
by Vincent(PDP)
Dusk wrote: Whoops, I accidentally made it shorter.

Code: Select all

// give offensive team chainsaws
script 755 (int offensiveTeam)
{
	for (int i = 0; i < 64; i++)
	{
		if (PlayerInGame(i) == false)
			continue;
		
		if (GetPlayerInfo(i, PLAYERINFO_TEAM) == offensiveTeam)
			GiveActorInventory(1000+i, "Chainsaw", 1);
		else
			ClearActorInventory(1000+i);
	}
}
Hahaha. Nice. :)