Please swap out OnSwitchToggle with OnSwitchToggled. This improves compatibility with other plugins as it allows them to block the switch from being toggled using the pre-hook.
I have tested the following code in your plugin and it is working correctly. This code also fixes a bug where it could allow toggling of turrets that are not parented to Minicopters, which can cause problems for servers that use both Modular Car Turrets and Vehicle Deployed Locks since it would allow a player to switch on/off a turret on a car they are locked out of.
I have tested the following code in your plugin and it is working correctly. This code also fixes a bug where it could allow toggling of turrets that are not parented to Minicopters, which can cause problems for servers that use both Modular Car Turrets and Vehicle Deployed Locks since it would allow a player to switch on/off a turret on a car they are locked out of.
private object OnSwitchToggled(ElectricSwitch electricSwitch, BasePlayer player)
{
if (IsBatEnabled()) return null;
AutoTurret turret = electricSwitch.GetParentEntity() as AutoTurret;
if (turret == null) return null;
var mini = turret.GetParentEntity() as MiniCopter;
if (mini == null) return null;
if (electricSwitch.IsOn())
PowerTurretOn(turret);
else
PowerTurretOff(turret);
return null;
}I would have submitted a pull request on your GitHub repo to save you time, but the repo appears to be private or does not exist.