Raised This Month: $12 Target: $400
 3% 

[TF2] Coloring Engineer Buildings v1.1


Post New Thread Reply   
 
Thread Tools Display Modes
Author
Oshizu
Veteran Member
Join Date: Nov 2012
Location: Warsaw
Plugin ID:
3399
Plugin Version:
1.1
Plugin Category:
Fun Stuff
Plugin Game:
Team Fortress 2
Plugin Dependencies:
    Servers with this Plugin:
    14 
    Plugin Description:
    Allows Adminstrators to change color of their engineer buildings
    Old 12-06-2012 , 11:26   [TF2] Coloring Engineer Buildings v1.1
    Reply With Quote #1

    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

    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
    Attached Files
    File Type: sp Get Plugin or Get Source (buildingcolors.sp - 10686 views - 3.9 KB)
    __________________
    ...

    Last edited by Oshizu; 09-14-2013 at 17:24.
    Oshizu is offline
    Eyelanderules
    Member
    Join Date: Jul 2011
    Old 12-06-2012 , 16:17   Re: [TF2] [MvM] Coloring Engineer Buildings v1.0
    Reply With Quote #2

    Ill give it a try.
    Eyelanderules is offline
    ReFlexPoison
    ☠☠☠
    Join Date: Jul 2011
    Location: ☠☠☠
    Old 12-06-2012 , 19:38   Re: [TF2] [MvM] Coloring Engineer Buildings v1.0
    Reply With Quote #3

    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;

    Attached Files
    File Type: sp Get Plugin or Get Source (buildingcolors.sp - 1078 views - 3.9 KB)

    Last edited by ReFlexPoison; 12-06-2012 at 19:40.
    ReFlexPoison is offline
    island55
    Senior Member
    Join Date: Aug 2010
    Location: charleston
    Old 12-07-2012 , 10:39   Re: [TF2] [MvM] Coloring Engineer Buildings v1.0
    Reply With Quote #4

    pictures!
    island55 is offline
    DJ Data
    SourceMod Donor
    Join Date: Dec 2012
    Location: Switzerland
    Old 02-27-2013 , 13:53   Re: [TF2] Coloring Engineer Buildings v1.1
    Reply With Quote #5

    Confirmed...
    It works
    __________________
    SourcePawn Coding Level: Novice
    DJ Data is offline
    Nanochip
    Senior Member
    Join Date: Jan 2014
    Old 01-05-2015 , 13:59   Re: [TF2] Coloring Engineer Buildings v1.1
    Reply With Quote #6

    Could you implement client prefs into this so that it remembers your settings even when map changes and/or reconnect.
    Nanochip is offline
    Nanochip
    Senior Member
    Join Date: Jan 2014
    Old 03-30-2015 , 22:16   Re: [TF2] Coloring Engineer Buildings v1.1
    Reply With Quote #7

    Got around to implementing client prefs myself. If anyone is interested, here ya go:
    Attached Files
    File Type: sp Get Plugin or Get Source (buildingcolors.sp - 1017 views - 4.9 KB)
    __________________
    Nanochip is offline
    Reply


    Thread Tools
    Display Modes

    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 04:49.


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