Raised This Month: $ Target: $400
 0% 

Spawnpoints Creator - Easy to use spawn points managing library


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Seta00
The Seta00 user has crashed.
Join Date: Jan 2010
Location: Berlin
Old 01-10-2011 , 13:39   Spawnpoints Creator - Easy to use spawn points managing library
Reply With Quote #1

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(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(); 
Attached Files
File Type: inc spawnpoints.inc (12.0 KB, 883 views)
File Type: sp Get Plugin or Get Source (spawnpoints_example.sp - 855 views - 967 Bytes)
File Type: sp Get Plugin or Get Source (spawnpoints_example2.sp - 461 views - 294 Bytes)

Last edited by Seta00; 02-11-2011 at 23:05.
Seta00 is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 15:19.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode