[ACS] Check if everyone doesn't have something

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
User avatar
TheGameratorT
Posts: 63
Joined: Sun Mar 04, 2018 4:42 am
Graphics Processor: nVidia with Vulkan support
Location: Portugal
Contact:

[ACS] Check if everyone doesn't have something

Post by TheGameratorT »

I want to check if anyone doesn't have an item.

As CheckActorInventory doesn't treat 0 as an activator I tried this:

Code: Select all

If(!CheckActorInventory(0, "IsBonnie"))
{
	HudMessage(s:"Bonnie isn't available because no one has chosen it."; HUDMSG_FADEINOUT, 0, CR_RED, 1.5, 0.5, 2.5, 0.05, 1.0);
	Terminate;
}
But It always gives a false postive which ends up running the message and the terminate.

This is the full code if it helps:

Code: Select all

Script "ViewBonnie" (void)
{
	SetFont("BIGFONT");
        
	If(!CheckActorInventory(0, "IsBonnie"))
	{
		HudMessage(s:"Bonnie isn't available because no one has chosen it."; HUDMSG_FADEINOUT, 0, CR_RED, 1.5, 0.5, 2.5, 0.05, 1.0);
		Terminate;
	}

	If(CheckActorInventory(1000,"IsBonnie"))
	{ChangeCamera(1000,0,1);}
	If(CheckActorInventory(1001,"IsBonnie"))
	{ChangeCamera(1001,0,1);}
	If(CheckActorInventory(1002,"IsBonnie"))
	{ChangeCamera(1002,0,1);}
	If(CheckActorInventory(1003,"IsBonnie"))
	{ChangeCamera(1003,0,1);}
	If(CheckActorInventory(1004,"IsBonnie"))
	{ChangeCamera(1004,0,1);}
	If(CheckActorInventory(1005,"IsBonnie"))
	{ChangeCamera(1005,0,1);}
	If(CheckActorInventory(1006,"IsBonnie"))
	{ChangeCamera(1006,0,1);}
	If(CheckActorInventory(1007,"IsBonnie"))
	{ChangeCamera(1007,0,1);}

	HudMessage(l:"NOW_SPECTATING", s:"Bonnie."; HUDMSG_FADEINOUT, 0, CR_RED, 1.5, 0.5, 2.5, 0.05, 1.0);
}
Thanks in advance.
User avatar
TheMightyHeracross
Posts: 2100
Joined: Sun Aug 18, 2013 9:41 am
Location: Philadelphia, PA

Re: [ACS] Check if everyone doesn't have something

Post by TheMightyHeracross »

Only GiveActorInventory and TakeActorInventory affect all player when the 0 TID is used. "CheckActorInventory(0, "IsBonnie")" will always be 0 (therefore making the check always positive) because it's not actually checking anyone's inventory for "IsBonnie," therefore no items are counted. But you've already done almost all of the work, since you already seem to check every player. Simply move the HudMessage to after all of the If statements, as a final result. You'll also want the change every "if" except the first to an "else if" because presumably there is only one Bonnie. Although the better solution would be to neaten that code up using loops:

Code: Select all

Script "ViewBonnie" (void)
{
   SetFont("BIGFONT");
   bool bonnieexists = false; //This boolean variable keeps track of whether Bonnie exists. Bonnie doesn't exist by default.
   for(int i = 1000; i < (1000+PlayerCount()); i++) //Loops once for every player present.
   {
        If(CheckActorInventory(i,"IsBonnie")) //Checks each player, individually, for "IsBonnie". If there is a player who is Bonnie...
        {
            ChangeCamera(i,0,1); //Change the camera
            bonnieexists = true; //Tell the script that Bonnie does, in fact, exist
            break; //End the loop, since we already found Bonnie, and there is no need to continue checking everyone else
        }

   if(bonnieexists) //If Bonnie was found in the loop...
   {
       HudMessage(l:"NOW_SPECTATING", s:"Bonnie."; HUDMSG_FADEINOUT, 0, CR_RED, 1.5, 0.5, 2.5, 0.05, 1.0); //Print this
   }
   else //If Bonnie was not found...
   {
        HudMessage(s:"Bonnie isn't available because no one has chosen it."; HUDMSG_FADEINOUT, 0, CR_RED, 1.5, 0.5, 2.5, 0.05, 1.0); //Tell the players 
   }
}
User avatar
TheGameratorT
Posts: 63
Joined: Sun Mar 04, 2018 4:42 am
Graphics Processor: nVidia with Vulkan support
Location: Portugal
Contact:

Re: [ACS] Check if everyone doesn't have something

Post by TheGameratorT »

Sorry for the bump but I really have to thank you for your help. Thx :)
Post Reply

Return to “Scripting”