AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   Spawnpoints Creator - Easy to use spawn points managing library (https://forums.alliedmods.net/showthread.php?t=147542)

Seta00 01-10-2011 13:39

Spawnpoints Creator - Easy to use spawn points managing library
 
5 Attachment(s)



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) :D

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(clientshow=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"DumpSpawnsInfoADMFLAG_GENERIC);
}

public 
Action:DumpSpawnsInfo(clientargs) {
    new 
Handle:spawns SC_GetSpawnsArray();
    new 
count GetArraySize(spawns);
    new 
Float:spawn[3];
    
    
ReplyToCommand(client"Dumping %d spawn point%s"countcount == "" "s");
    for (new 
0count; ++i) {
        
GetArrayArray(spawnsispawn);
        
ReplyToCommand(client"%2d - (.2f, .2f, .2f)"ispawn[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(); 


Samantha 01-10-2011 15:13

Re: Spawnpoints Creator - Easy to use spawn points managing library
 
Wow this is really neat. I love how it shows the location of spawns that you already placed.

berni 01-13-2011 17:39

Re: Spawnpoints Creator - Easy to use spawn points managing library
 
Nice, I always wanted to write such a plugin, but never had the time.

What about if you replace the lights by real player models ? Maybe a little transparent :)

Seta00 01-14-2011 07:06

Re: Spawnpoints Creator - Easy to use spawn points managing library
 
Quote:

Originally Posted by berni (Post 1393012)
What about if you replace the lights by real player models ? Maybe a little transparent :)

Because it's meant to be generic. Player models would suggest it's creating real spawnpoints, but all it does is manage coordinates, the plugin author does whatever he wants with them.

berni 01-14-2011 09:56

Re: Spawnpoints Creator - Easy to use spawn points managing library
 
Because it's called "Spawnpoints creator" I kinda thought it does exactly that, too bad ^^

Seta00 02-07-2011 18:21

Re: Spawnpoints Creator - Easy to use spawn points managing library
 
Updated to fix a problem with infinite spawns.

ChioX 02-09-2011 11:48

Re: Spawnpoints Creator - Easy to use spawn points managing library
 
do you also support different spawnpoints for t and ct? If not, could you implement it? Thanks a lot

Seta00 02-11-2011 23:05

Re: Spawnpoints Creator - Easy to use spawn points managing library
 
Fixed a bug where the plugin wouldn't clear the previous map spawns if it couldn't find the .spawns file.

Samantha 02-14-2011 23:05

Re: Spawnpoints Creator - Easy to use spawn points managing library
 
Add Coordinate groups please.

Chanz 05-28-2011 18:24

Re: Spawnpoints Creator - Easy to use spawn points managing library
 
Could you add an array that contains the orginal spawnpoints of the map?
I'd like to see what spawn points the mapper set and those I set with this lib.
Also a reset and/or undo would be nice. :-)


All times are GMT -4. The time now is 16:58.

Powered by vBulletin®
Copyright ©2000 - 2021, vBulletin Solutions, Inc.