Skip to content
This repository has been archived by the owner on Jun 16, 2024. It is now read-only.

Plugin API

Impact edited this page Jan 14, 2021 · 21 revisions

The plugin is build very modular, it has multiple forwards and natives you can use to interact with it.
The idea behind this was to have a better overview of the existing code, thus making changes easier.
Of course these features can be used by any other plugin, here are some examples, tips and important information.
Please note that some of the functions presented here might not have been released to public yet.

Require as optional

Sometimes you want to have calladmin as an optional dependency, therefore the plugin registers a library you can check for.
Here is an example.

#include <sourcemod>

// This is important
#undef REQUIRE_PLUGIN
#include "calladmin"
#pragma semicolon 1


// We use this to check for the library
#define CALLADMIN_AVAILABLE()      (LibraryExists("calladmin"))


public void OnPluginStart()
{
	if (CALLADMIN_AVAILABLE())
	{
		// Do something if the library exists
	}
}

If you want to know more about optional dependencies, we suggest you take a read here.

Backward compatibility

Because the plugin is very api-centric we might add or remove some natives from version to version.
If your module wants to use a native added in v0.2.0 and the api-version is below that, your plugin will throw errors.
We suggest that you check if a native exists before you try to use it, here is an example.

public void OnPluginStart()
{
	if (NativeExists("CallAdmin_GetHostIP"))
	{
		// Grab the hostip from calladmin
	}
}


stock bool NativeExists(const char[] name)
{
	return (CanTestFeatures() && GetFeatureStatus(FeatureType_Native, name) == FeatureStatus_Available);
}

Blocking reports

Lets pretend you want to only allow players with a specific flag or override to report another player.

public Action CallAdmin_OnReportPre(int client, int target, const char[] reason)
{
	// Client doesn't have the permission we want
	if (!CheckCommandAccess(client, "my_immunity_override", ADMFLAG_GENERIC, false))
	{
		return Plugin_Handled;
	}
	
	return Plugin_Continue;
}

You don't have to verify if a client is valid, though it can't hurt.
Just be sure that you check if the caller is REPORTER_CONSOLE, see the existing modules to learn how.

Catching reports

Lets pretend you want to send an email when a report was sent.

public void CallAdmin_OnReportPost(int client, int target, const char[] reason)
{
	// Send this data to an email address
}

You don't have to verify if a client is valid, though it can't hurt.
Just be sure that you check if the caller is REPORTER_CONSOLE, see the existing modules to learn how.

Catching client selection

Lets pretend you want to add immunity for admins, so they can't be selected within the client selection menu.

public Action CallAdmin_OnDrawTarget(int client, int target)
{
	// Target has permissions
	if (CheckCommandAccess(target, "my_immunity_override", ADMFLAG_GENERIC, false))
	{
		return Plugin_Handled;
	}
	
	return Plugin_Continue;
}

Initiating a report call

Since v0.1.3 you can initiate own report calls which will be forwarded to all modules.
Because none of the modules use this functionality yet, we show you an example.

void SomeCoolFunction(int client, int target, const char[] reason)
{
	bool success;
	
	// It's important that we set the client to REPORTER_CONSOLE if it's not a real client
	// You should go ahead and enhance this check, for the sake of this example it's okay
	if (!client)
	{
		client = REPORTER_CONSOLE;
	}
	
	
	// Do the actual call and retrieve the result
	success = CallAdmin_ReportClient(client, target, reason)
	
	// Further use the result
}

Further reading

You can take a look at our calladmin_test.sp file to see some more examples (it doesn't cover all functions though).
The best way is to take a look at the include file. You can also our existing modules and see how we use the api.
If you have questions, suggestions or critique you are invited to let us know!.