Raised This Month: $ Target: $400
 0% 

[TF2] Plugin review, NoSentries


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
FlyveHest
Member
Join Date: Nov 2010
Location: Denmark
Old 11-18-2012 , 15:13   [TF2] Plugin review, NoSentries
Reply With Quote #1

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(sentryIndexProp_Send"m_bMiniBuilding");

        
// Alert player
        
Client_PrintToChat(clientIDfalse"[{L}GB.NoSentries{N}] Sentry building is not allowed.");

        
// Destroy sentry
        
AcceptEntityInput(sentryIndex"Kill");

        
// Reimburse metal
        
new currentMetal GetEntProp(clientIDProp_Data"m_iAmmo"43);

        
// 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(clientIDProp_Data"m_iAmmo"currentMetal43);
    }

__________________
FlyveHest
-
GB.CritVote - Let people vote to en/disable random crits each round

Visit Gladblad Gamers
FlyveHest is offline
MasterOfTheXP
Veteran Member
Join Date: Aug 2011
Location: Cloudbank
Old 11-18-2012 , 20:25   Re: [TF2] Plugin review, NoSentries
Reply With Quote #2

Better thing to do in my opinion would be to use SDK Hooks to hook when a building entity is created, then remove that. They're created whenever the Engineer chooses what to build (so before their actual construction)
__________________
Plugins / My Steam / TF2 Sandbox (plugin beta testing!)
MasterOfTheXP is offline
FlyveHest
Member
Join Date: Nov 2010
Location: Denmark
Old 11-19-2012 , 02:55   Re: [TF2] Plugin review, NoSentries
Reply With Quote #3

Just out of curiosity, is there any game-related reason for this? (For instance, you actually save telling all the clients about a created/destroyed sentry or so?)

Advice seems sound enough, and i'll try and do that instead later, I just really want to understand why this is a better idea
__________________
FlyveHest
-
GB.CritVote - Let people vote to en/disable random crits each round

Visit Gladblad Gamers
FlyveHest is offline
pheadxdll
AlliedModders Donor
Join Date: Jun 2008
Old 11-19-2012 , 09:42   Re: [TF2] Plugin review, NoSentries
Reply With Quote #4

To block sentries from being built, you could hook the build command and block it whenever the parameters are "build 2 0" I think this is better as you don't have to worry about giving back ammo and it's more clean. You could also set the cvar tf_sentrygun_notarget so they won't shoot. My melee plugin does this.
__________________
pheadxdll is offline
FlyveHest
Member
Join Date: Nov 2010
Location: Denmark
Old 11-19-2012 , 12:59   Re: [TF2] Plugin review, NoSentries
Reply With Quote #5

I think I read somewhere (which might have been in an old post) that hooking the command could still result in sentries being built.

But yes, that would seem like a very clean way of doing it.
__________________
FlyveHest
-
GB.CritVote - Let people vote to en/disable random crits each round

Visit Gladblad Gamers
FlyveHest is offline
Reply



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 20:40.


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