Hi all,
Just wondered if someone with a little more experience in SourceModding could give my newest plugin a lookover? The thing i'm mostly concerned about is how I remove sentries after they have spawned, and if this could pose a problem down the line?
Plugin is simply, is disallows sentries from being built, and reimburses the engineer the "lost" metal.
PHP Code:
/*
* ============================================================================
* GB.NoSentries, disallows building of sentries entirely
*
* Done in 2012 by GB.FlyveHest
* =============================================================================
*/
// Semicolons are nice at EOLs :)
#pragma semicolon 1
// Defines
#define GB_NS_VERSION "1.00"
// Includes
#include <sourcemod>
#include <smlib>
// Info
public Plugin:myinfo =
{
name = "GB.NoSentries",
author = "FlyveHest",
description = "Disallows the building of sentries of any kind.",
version = GB_NS_VERSION,
url = "http://gaming.gladblad.dk/"
};
// Global variables
// ConVars
new Handle:gb_ns_enabled = INVALID_HANDLE;
// Called when plugin is loaded, initialize it
public OnPluginStart()
{
// Create our ConVars
CreateConVar("gb_nosentries_version", GB_NS_VERSION, "Restarts server after server empties.", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY|FCVAR_DONTRECORD);
gb_ns_enabled = CreateConVar("gb_ns_enabled", "0", "Enables/disables nosentries");
// Hook into the game
HookEvent("player_builtobject", Event_PlayerBuiltObject);
// Create/Load a config file
AutoExecConfig(true, "gb_nosentries");
}
// When a players builds something
public Event_PlayerBuiltObject(Handle:eventHandle, const String:eventName[], bool:dontBroadcast)
{
// Check if NoSentries is enabled
if (GetConVarInt(gb_ns_enabled) != 1)
{
return;
}
// Check if its a sentry
new builtObject = GetEventInt(eventHandle, "object");
if (builtObject == 2)
{
// Its a sentry, get ID of client (so we can alert him) and sentry (so we can destroy it)
new clientID = GetClientOfUserId(GetEventInt(eventHandle, "userid"));
new sentryIndex = GetEventInt(eventHandle, "index");
// Determine if minisentry or normal sentry (0: normal, 1: mini)
new sentryType = GetEntProp(sentryIndex, Prop_Send, "m_bMiniBuilding");
// Alert player
Client_PrintToChat(clientID, false, "[{L}GB.NoSentries{N}] Sentry building is not allowed.");
// Destroy sentry
AcceptEntityInput(sentryIndex, "Kill");
// Reimburse metal
new currentMetal = GetEntProp(clientID, Prop_Data, "m_iAmmo", 4, 3);
// Handle type of sentry
if (sentryType == 0)
{
currentMetal = currentMetal + 130;
}
else
{
currentMetal = currentMetal + 100;
}
// Small sanity check
if (currentMetal > 200)
{
currentMetal = 200;
}
// Update metal for engi
SetEntProp(clientID, Prop_Data, "m_iAmmo", currentMetal, 4, 3);
}
}
__________________