AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Plugins (https://forums.alliedmods.net/forumdisplay.php?f=108)
-   -   [TF2] Coloring Engineer Buildings v1.1 (https://forums.alliedmods.net/showthread.php?t=202484)

Oshizu 12-06-2012 11:26

[TF2] Coloring Engineer Buildings v1.1
 
1 Attachment(s)
Description:
- Allows Adminstrators To Paint Their Engineer Buildings in Mann Vs Machine to any other color
- Plugins is recommended to be used in MvM / COOP Maps. Player can be confused in normal gameplay about team of sentry :nono:

Installation:
- Place buildingcolors.smx in : addons/sourcemod/plugins
- Change Map

Changelog:
v1.0 - First Release
v1.1 - Slightly Improved (Thanks to ReFlexPoison)
Commands:
- sm_buildingcolors / !buildingcolors - Turns on Coloring Menu - Requires Admin Generic Flag

Media:
- None

Requires to compile:
- Nothing

Future Plans:
- Make menu appear when player places building with choosing colors panel instead of writing !buildingcolors and making sentry :twisted:

Eyelanderules 12-06-2012 16:17

Re: [TF2] [MvM] Coloring Engineer Buildings v1.0
 
Ill give it a try.

ReFlexPoison 12-06-2012 19:38

Re: [TF2] [MvM] Coloring Engineer Buildings v1.0
 
1 Attachment(s)
When you create your menu you never close the handle if the menu is closed. This will cause memory leaks and can crash the server.

I wouldn't keyword this as MvM as, even though it may not be preferable for said "regular game-play," it can still be used in different mods.

Also some advice:
  • You should use #pragma semicolon 1 so you aren't mixing up using and not using semicolons after your functions.
  • You shouldn't use floats to designate specific client variables unless you need to. Use a simple integer value.
  • You should include enable CVars for users so in the situation they can disable the plugin without unloading it.
  • Use proper indenting to make your code more read-able. If you are going to use one type of indentation in your plugin, make sure to use it all the way through.

Here's a re-code:
PHP Code:

#pragma semicolon 1

#include <sourcemod>
#include <sdktools>

#define VERSION "1.1"

new Handle:cvarEnabled;
new 
bool:gEnabled;

new 
gColor[MAXPLAYERS 1];

public 
Plugin:myinfo =
{
    
name "[TF2] Colored Engineer Buildings",
    
author "Oshizu",
    
description "Allows admins to paint their engineer buildings.",
    
version VERSION,
    
url "http://www.sourcemod.net/"
}

public 
OnPluginStart()
{
    
CreateConVar("sm_ceb_version"VERSION"TF2 Colored Engineer Buildings Version"FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);

    
cvarEnabled CreateConVar("sm_ceb_enabled""1""Enable Colored Engineer Buildings\n0 = Disabled\n1 = Enabled"FCVAR_NONEtrue0.0true1.0);
    
gEnabled GetConVarBool(cvarEnabled);

    
HookConVarChange(cvarEnabledCVarChange);

    
HookEvent("player_builtobject"SentryColor);

    
RegAdminCmd("sm_buildingcolors"ColorMenuADMFLAG_GENERIC);

    for(new 
1<= MaxClientsi++)
    {
        if(
IsValidClient(i)) gColor[i] = 0;
    }
}

public 
OnPluginEnd()
{
    new 
ent = -1;
    while((
ent FindEntityByClassname(ent"obj_dispenser")) != -1)
    {
        
SetEntityRenderColor(ent255255255_);
    }
    while((
ent FindEntityByClassname(ent"obj_teleporter")) != -1)
    {
        
SetEntityRenderColor(ent255255255_);
    }
    while((
ent FindEntityByClassname(ent"obj_sentry")) != -1)
    {
        
SetEntityRenderColor(ent255255255_);
    }
}

public 
CVarChange(Handle:convar, const String:oldValue[], const String:newValue[])
{
    if(
convar == cvarEnabled)
    {
        
gEnabled GetConVarBool(cvarEnabled);

        if(!
gEnabled)
        {
            for(new 
1<= MaxClientsi++)
            {
                if(
IsValidClient(i)) gColor[i] = 0;
            }

            new 
ent = -1;
            while((
ent FindEntityByClassname(ent"obj_dispenser")) != -1)
            {
                
SetEntityRenderColor(ent255255255_);
            }
            while((
ent FindEntityByClassname(ent"obj_teleporter")) != -1)
            {
                
SetEntityRenderColor(ent255255255_);
            }
            while((
ent FindEntityByClassname(ent"obj_sentry")) != -1)
            {
                
SetEntityRenderColor(ent255255255_);
            }
        }
    }
}

public 
OnClientPutInServer(client)
{
    
gColor[client] = 0;
}

public 
Action:SentryColor(Handle:event, const String:name[], bool:dontBroadcast)
{
    if(!
gEnabled) return Plugin_Continue;

    new 
client GetClientOfUserId(GetEventInt(event"userid"));
    if(!
IsValidClient(client)) return Plugin_Continue;

    new 
building GetEventInt(event"index");

    switch(
gColor[client])
    {
        case 
1SetEntityRenderColor(building000_);
        case 
2SetEntityRenderColor(building2551020_);
        case 
3SetEntityRenderColor(building2552550_);
        case 
4SetEntityRenderColor(building01280_);
        case 
5SetEntityRenderColor(building00255_);
        case 
6SetEntityRenderColor(building25500_);
        case 
7SetEntityRenderColor(building0255255_);
    }
    return 
Plugin_Continue;
}

public 
Action:ColorMenu(clientargs)
{
    new 
Handle:cm CreateMenu(ColorMenuCallback);
    
SetMenuTitle(cm"Choose Color For Your Building");

    
AddMenuItem(cm"0""No Color");
    
AddMenuItem(cm"1""Black");
    
AddMenuItem(cm"2""Orange");
    
AddMenuItem(cm"3""Yellow");
    
AddMenuItem(cm"4""Green");
    
AddMenuItem(cm"5""Blue");
    
AddMenuItem(cm"6""Red");
    
AddMenuItem(cm"7""Aqua");

    
DisplayMenu(cmclientMENU_TIME_FOREVER);

    return 
Plugin_Handled;
}

public 
ColorMenuCallback(Handle:menuMenuAction:actionclientparam2)
{
    if(
action == MenuAction_EndCloseHandle(menu);

    if(
action == MenuAction_Select)
    {
        
decl String:info[12];
        
GetMenuItem(menuparam2infosizeof(info));
        
gColor[client] = StringToInt(info);
    }
}

stock bool:IsValidClient(clientbool:replay true)
{
    if(
client <= || client MaxClients || !IsClientInGame(client)) return false;
    if(
replay && (IsClientSourceTV(client) || IsClientReplay(client))) return false;
    return 
true;



island55 12-07-2012 10:39

Re: [TF2] [MvM] Coloring Engineer Buildings v1.0
 
pictures!

DJ Data 02-27-2013 13:53

Re: [TF2] Coloring Engineer Buildings v1.1
 
Confirmed...
It works

Nanochip 01-05-2015 13:59

Re: [TF2] Coloring Engineer Buildings v1.1
 
Could you implement client prefs into this so that it remembers your settings even when map changes and/or reconnect.

Nanochip 03-30-2015 22:16

Re: [TF2] Coloring Engineer Buildings v1.1
 
1 Attachment(s)
Got around to implementing client prefs myself. If anyone is interested, here ya go:


All times are GMT -4. The time now is 00:46.

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