Semiclip

Who walks through whom, as a rule over two players
v0.2.2kukson777 kukson777

Semiclip lets players walk through each other. amxts does it on the server itself, as pairs of players; this module lets a plugin say who walks through whom as a rule over two players, (player, target) => boolean, and keeps the pairs up to date with it.

Features

  • Works as soon as it is installed. Teammates walk through each other, see-through up close and not drawn right against you; a teammate's grenade flies through you, and you stand on a teammate's head - before any plugin says a word.
  • A rule, not pairs by hand. One function says whether one player walks through another; the module works every pair out.
  • Kept up to date by itself. A spawn, a death, a team change, a player coming in, and a change of any field plugins add to Player work the pairs out again - only the pairs of the player it happened to.
  • Nothing else on the server. No AMX Mod X module is needed: the pairs are amxts's own.
  • One instance per server. Every plugin that uses it sets the same rule.

Installation

The project needs @amxts/core 0.3.5 or later.

npx amxts module add semiclip

It installs the package and adds it to your project's amxts.config.ts:

export default 
defineConfig
({
modules
: ["@amxts/semiclip"],
});

Usage

A plugin uses the module as semiclip, without an import line: the build adds the import to the plugins that use it, and builds the module only when some plugin does.

Installed, the module needs no plugin: teammates walk through each other, and a partner is see-through closer than 250 units fades out and is not drawn closer than 60 (the project's options). A plugin changes who walks through whom with a rule - everyone through everyone, on a KZ server:

semiclip
.
rule
= () => true;

Setting the rule is all it takes: the module works every pair out, and works a player's pairs out again when he spawns, dies, changes sides or comes in. semiclip.rule = null makes everyone solid; when the plugin that set the rule stops - unloaded or reloaded - teammates walk through each other again, until a rule is set again.

A rule that changes in play

spawnProtected below is the plugin's own field on Player, declared with declare module: it starts false, every plugin on the server reads and writes it, and it is cleared when the player leaves. A player who has just spawned walks through everyone alive for 3 seconds, and teammates walk through each other:

declare module "@amxts/core" {
    interface Player {
        
spawnProtected
: boolean;
} }
semiclip
.
rule
= (
player
,
target
) =>
player
.
isAlive
&&
target
.
isAlive
&& (
player
.
spawnProtected
||
player
.
team
==
target
.
team
);
game
.
addEventListener
("spawn", ({
player
}) => {
player
.
spawnProtected
= true; // walks through everyone for 3 seconds
setTimeout
(() => (
player
.
spawnProtected
= false), 3000);
});

The module works the pairs out again by itself when the field changes - on the spawn, and when the timer clears it - with no update() call.

When the pairs are worked out

WhenWhich pairs
rule is setevery pair
a player comes into the gamehis
a player spawns, dies or changes sideshis
a field plugins add to Player changes on a player - any plugin's, or Pawn'shis
a player leaveshis pairs go with him
semiclip.update(player)player's
semiclip.update()every pair

update() is for what the rule reads that the module does not hear - a round's mode kept in a variable, a plugin's own record of a player:

let 
everyone
= false;
semiclip
.
rule
= (
player
,
target
) =>
everyone
||
player
.
team
==
target
.
team
;
server
.
addCommand
("/party", () => {
everyone
= !
everyone
;
semiclip
.
update
();
});

Either way lets a pair through

rule(player, target) says whether player walks through target, but a pair is one: two players walk through each other, or neither does. The pair walks through when the rule lets either one - rule(a, b) || rule(b, a). A rule that says yes for a protected player lets him through everyone, and everyone through him, with no || target.spawnProtected needed.

The project's options

A partner is see-through up close and not drawn right against you, so he does not block the view; a grenade flies through the partners of the player who threw it; and a player wholly above a partner stands on his head instead of falling through him. The project sets all of it in amxts.config.ts - the values below are the defaults:

export default 
defineConfig
({
modules
: ["@amxts/semiclip"],
semiclip
: {
fadeDistance
: 250, // closer than 250 units a partner is see-through; 0 is off
opacity
: 0.4, // 40% opaque at hideDistance, whole at fadeDistance
hideDistance
: 60, // closer than 60 units he fades out, is not drawn, and is no target of your aim; 0 is off
grenades
: true, // false: a grenade bounces off a partner of its thrower
standOnHead
: true, // false: a partner above falls through
}, });

A shot, a flash's light and an explosion stop at a partner as at anyone. All of it works on every server, with ReHLDS and ReGameDLL or without them.

Standing on a head in one mode only

A plugin sets semiclip.standOnHead for as long as it runs. A server with several modes keeps head boosts in one and turns them off in another, through the plugin of that mode:

semiclip
.
standOnHead
= false; // while this plugin runs, a partner above falls through

When the plugin stops - it is unloaded, or the mode changes and it is not loaded - the project's standOnHead comes back.

One rule

The rule is one for the server. A plugin that sets it over another plugin's replaces it, and the console warns: the last one set is used. Plugins that each have a say write it into fields (player.spawnProtected) that one rule reads.

API

MemberWhat it is
semiclip.rule(player, target) => boolean - whether player walks through target; a pair walks through when either way says so. Setting it works every pair out; null makes everyone solid again.
semiclip.standOnHeadboolean - whether a player wholly above a partner stands on him; the project's option until a plugin sets it, and again when that plugin stops.
semiclip.update(player?)Works player's pairs out again, or everyone's, after something the rule reads changed that the module does not hear.