From acfb4c63083e49fc9e0d0a5a22601826e89ecedb Mon Sep 17 00:00:00 2001 From: Blixibon Date: Fri, 29 May 2020 16:45:41 -0500 Subject: [PATCH] Created VScript : Filters (markdown) --- VScript-:-Filters.md | 57 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 VScript-:-Filters.md diff --git a/VScript-:-Filters.md b/VScript-:-Filters.md new file mode 100644 index 0000000..56dee0e --- /dev/null +++ b/VScript-:-Filters.md @@ -0,0 +1,57 @@ +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: + +```squirrel +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: +```squirrel +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; +} +``` \ No newline at end of file