Spawnpoints Creator
This library manages spawn points, it's a plug-and-play configurable spawn points feature to your plugins.
Table of Contents:
Rationale:
After having to copy-paste several lines of spawn point management code in three plugins, I decided I was going to make it into a library and release. Besides making my life easier, the benefits are several: more people can test it, I can add configurable spawn points feature to existing plugins with only a few extra lines, and it seems I don't have anything released here (yet)
API:
SC_Initialize:
Call this to initialize the library. This must be called once per-plugin, so it's generally called OnPluginStart.
Params:
- pluginName - Plugin name shown to clients on menus, chat messages, etc
- menuCmdName - Name of the admin command to show the spawn point editing menu. If this param is empty ("") the command won't be registered.
- menuAdmFlag - Menu command admin flags
- addSpawnCmdName - Name of the admin command to add a spawn point on the current player location. If this param is empty ("") the command won't be registered.
- addSpawnAdmFlag - Add spawn command admin flags
- delSpawnCmdName - Name of the admin command to delete the nearest spawn point (on a 64 units radius) to the player. If this param is empty ("") the command won't be registered.
- delSpawnAdmFlag - Delete spawn command admin flags
- showSpawnsCmdName - Name of the admin command to show the saved spawn points to the player. If this param is empty ("") the command won't be registered.
- showSpawnAdmFlag - Show spawns command admin flags
- configFileDir - Directory to save .spawns files to.
- maxSpawns - Maximum number of spawn points to load/save/allow creation. Default is infinite.
- showSpawnsSprite - Sprite index to use when showing saved spawns. Default is "materials/sprites/glow.vmt".
Return values:
- SC_NoError if everything went fine
- SC_AlreadyInitialized if the library has already been initialized
- SC_InvalidPluginName if pluginName is not valid
PHP Code:
stock SCError:SC_Initialize(const String:pluginName[]
,const String:menuCmdName[]
,menuAdmFlag
,const String:addSpawnCmdName[]
,addSpawnAdmFlag
,const String:delSpawnCmdName[]
,delSpawnAdmFlag
,const String:showSpawnsCmdName[]
,showSpawnsAdmFlag
,const String:configFileDir[]
,maxSpawns = -1
,showSpawnsSprite = -1
)
SC_LoadMapConfig:
Loads the config file for this map.
The config file is addons/sourcemod +
configFileDir + mapname.spawns (
addons/sourcemod/my_plugin/de_dust2.spawns).
This is normally called OnMapStart.
Return values:
- SC_NoError if everything went fine
- SC_NotInitialized if the library hasn't been initialized.
PHP Code:
stock SCError:SC_LoadMapConfig()
SC_SaveMapConfig:
Saves the current spawn points to the config file.
See
SC_LoadMapConfig for how the config file name is generated.
This is normally called OnMapEnd.
Return values:
- SC_NoError if everything went fine
- SC_NotInitialized if the library hasn't been initialized.
PHP Code:
stock SCError:SC_SaveMapConfig()
SC_GetSpawnsArray:
Returns a Handle to the internal ADT array used by the library to store spawn points.
PHP Code:
stock Handle:SC_GetSpawnsArray()
SC_GetRandomSpawn:
Get a random spawn point.
Params:
- spawn - vector to store the spawn point coordinates into
PHP Code:
stock SC_GetRandomSpawn(Float:spawn[3])
SC_AddSpawnPoint:
Manually add a spawn point from its coordinates.
Params:
- spawn - coordinates of the spawn point to save.
Return values:
- SC_NoError if everything went fine.
- SC_MaxSavedSpawns if the number of saved spawn points is already maximum (specified by maxSpawns).
PHP Code:
stock SCError:SC_AddSpawnPoint(Float:spawn[3])
SC_ShowSpawnsToClient:
Shows or hides saved spawn points to clients.
Uses a GlowSprite TE with a sprite specified by
showSpawnsSprite.
See
screenshots.
Params:
- client - client index of the player
- show - true for show, false for hide. Default is true.
Return values:
- SC_NoError if everything went fine.
- SC_CantShowSpawns if the library couldn't create the timer used to setup the TE's.
PHP Code:
stock SCError:SC_ShowSpawnsToClient(client, show=true)
Examples:
Limit the amount of spawn points to 10, let the library create the admin menu and all the editing commands, and provide a command to dump the coordinates of the saved spawn points:
PHP Code:
#include <sourcemod>
#include "spawnpoints"
public OnPluginStart() {
SC_Initialize("sc_test",
"sc_test_menu", ADMFLAG_GENERIC,
"sc_test_add", ADMFLAG_GENERIC,
"sc_test_del", ADMFLAG_GENERIC,
"sc_test_show", ADMFLAG_GENERIC,
"configs/sc_test",
10);
RegAdminCmd("sc_test_dump", DumpSpawnsInfo, ADMFLAG_GENERIC);
}
public Action:DumpSpawnsInfo(client, args) {
new Handle:spawns = SC_GetSpawnsArray();
new count = GetArraySize(spawns);
new Float:spawn[3];
ReplyToCommand(client, "Dumping %d spawn point%s", count, count == 1 ? "" : "s");
for (new i = 0; i < count; ++i) {
GetArrayArray(spawns, i, spawn);
ReplyToCommand(client, "%2d - (.2f, .2f, .2f)", i, spawn[0], spawn[1], spawn[2]);
}
ReplyToCommand(client, "End of spawn points dump", count);
return Plugin_Handled;
}
public OnMapStart()
SC_LoadMapConfig();
public OnMapEnd()
SC_SaveMapConfig();
Library will only create the show/hide spawns command:
PHP Code:
#include <sourcemod>
#include "spawnpoints"
public OnPluginStart() {
SC_Initialize("sc_test2",
"", 0,
"", 0,
"", 0,
"sc_test2_show", ADMFLAG_GENERIC,
"sc_test2");
}
public OnMapStart()
SC_LoadMapConfig();
public OnMapEnd()
SC_SaveMapConfig();