Modme Forums

Array help

Game Modding | Call of Duty: Black Ops 3 | Scripting


ModmeBot:

Thread By: mathfag
SOLVED
As you may have noticed I "discovered" a gobble gum anti cheat I want to add more options. Instead of having if() arguments for all gobbles, I want to add them all in an array and check if any of them is >0.

So how does one check if any values in an array is >0 or at least how to add up all the values in an array?

Orig post: http://aviacreations.com/modme/index.php?view=topic&tid=1858


ModmeBot:

Reply By: ZombieKid164

mathfag
As you may have noticed I "discovered" a gobble gum anti cheat I want to add more options. Instead of having if() arguments for all gobbles, I want to add them all in an array and check if any of them is >0. So how does one check if any values in an array is >0 or at least how to add up all the values in an array? Orig post: http://aviacreations.com/modme/index.php?view=topic&tid=1858

I'd do something like this maybe?
function anticheat()
{

	nogum_array = []; //create a list of gums you don't want here

	wait(10);

	while(1)
    {
    	player = GetPlayers();
    	for( i=0;i<player.size;i++ )="" {="" for(i="0;" i="" <="" nogum_array.size)="" {="" gum="player[i]" getbgbremaining(="" nogum_array[i]="" );="" if(gum="">0)
        		{
        			IPrintLnBold("NO " +nogum_array[i] +" ALLOWED!");
        			wait(5);
        			level notify("end_game");
        		}
        	}
        }
    }
	wait(60);
}
</player.size;i++>


ModmeBot:

Reply By: mathfag
gg


ModmeBot:

Reply By: WARDOGSK93

ZombieKid164
mathfag As you may have noticed I "discovered" a gobble gum anti cheat I want to add more options. Instead of having if() arguments for all gobbles, I want to add them all in an array and check if any of them is >0. So how does one check if any values in an array is >0 or at least how to add up all the values in an array? Orig post: http://aviacreations.com/modme/index.php?view=topic&tid=1858 I'd do something like this maybe? function anticheat() { nogum_array = []; //create a list of gums you don't want here wait(10); while(1) { player = GetPlayers(); for( i=0;i<player.size;i++ )="" {="" for(i="0;" i="" <="" nogum_array.size)="" {="" gum="player" getbgbremaining(="" nogum_array="" );="" if(gum="">0) { IPrintLnBold("NO " +nogum_array+" ALLOWED!"); wait(5); level notify("end_game"); } } } } wait(60); }
1 major issue with this, you are using the variable "i" for looping over both players and gums, which will causes major issues if array sizes are different

i would use this code, note that this code is untested but should work fine ;)

function anticheat()
{
	level endon("end_game");

	nogum_array = [];
	// ARRAY_ADD(nogum_array, "some_gum_name");

	for(;;)
	{
		WAIT_SERVER_FRAME

		foreach(player in GetPlayers())
		{
			foreach(gum in player GetBubbleGumPack())
			{
				if(IsInArray(gum, nogum_array))
				{
					IPrintLnBold(sprintf("The BGB ^3{0}^7 has been disallowed in this mod.", gum));
					level notify("pre_end_game");
					wait 5;
					level notify("end_game");
				}
			}
		}
	}
}
</player.size;i++>


ModmeBot:

Reply By: mathfag

WARDOGSK93
ZombieKid164 mathfag As you may have noticed I "discovered" a gobble gum anti cheat I want to add more options. Instead of having if() arguments for all gobbles, I want to add them all in an array and check if any of them is >0. So how does one check if any values in an array is >0 or at least how to add up all the values in an array? Orig post: http://aviacreations.com/modme/index.php?view=topic&tid=1858 I'd do something like this maybe? function anticheat() { nogum_array = []; //create a list of gums you don't want here wait(10); while(1) { player = GetPlayers(); for( i=0;i<player.size;i++ )="" {="" for(i="0;" i="" <="" nogum_array.size)="" {="" gum="player" getbgbremaining(="" nogum_array="" );="" if(gum="">0) { IPrintLnBold("NO " +nogum_array+" ALLOWED!"); wait(5); level notify("end_game"); } } } } wait(60); } 1 major issue with this, you are using the variable "i" for looping over both players and gums, which will causes major issues if array sizes are different i would use this code, note that this code is untested but should work fine ;) function anticheat() { level endon("end_game"); nogum_array = []; // ARRAY_ADD(nogum_array, "some_gum_name"); for(;;) { WAIT_SERVER_FRAME foreach(player in GetPlayers()) { foreach(gum in player GetBubbleGumPack()) { if(IsInArray(gum, nogum_array)) { IPrintLnBold(sprintf("The BGB ^3{0}^7 has been disallowed in this mod.", gum)); level notify("pre_end_game"); wait 5; level notify("end_game"); } } } } }
thanks</player.size;i++>