1 VScript Filters
Blixibon edited this page 2021-03-13 11:12:12 -06:00

Mapbase associates filters with VScript in a few different ways.

Functions

Mapbase adds a few new functions which could be used on entity handles in VScript code:

  • PassesFilter
  • PassesDamageFilter
  • PassesFinalDamageFilter
  • BloodAllowed
  • DamageMod

These are documented in more detail on the VScript in Mapbase article. They can be used like this:

function CheckIfPassFilter( entity )
{
	local filter = Entities.FindByName(null,"filter_acceptable")

	if ( filter != null )
	{
		return filter.PassesFilter( self, entity )
	}
	else
	{
		return false;
	}
}

filter_script

filter_script is a new filter entity which uses its entity scripts for all regular filter functions, including functions new with Mapbase.

For example, the following code uses the PassesFilter hook to only pass activators with a weapon that has <10 ammo in it:

function PassesFilter()
{
    if (activator.GetActiveWeapon())
    {
        local ammo = activator.GetActiveWeapon().Clip1()
        if (ammo < 10)
        {
            printl("Has weapon with <10 ammo, damaging")
            return true;
        }
        else
        {
            printl("Has weapon with " + ammo + " ammo, no damage")
            return false;
        }
    }

    printl("Returning false")
    return false;
}