Half-Life Icon HL Script

[AMXX] [ALL] Auto Plugins Adder

Hey, you! We are one of the oldest mod sites on the Interwebs. Sign up and maximize your browsing experience.

  • Subscribe: Get notified of new submissions like this.
  • Say Thanks: Show your appreciation by sending Rj. points.
  • Post: Give Rj. your thoughts on this Script.
  • Vote: Help Rj. win the Monthly Awards.
  • Rate: Give this Script a rating out of 10.
  • Flag: Alert moderators and warn members of a problem with this Script.
  • Watch: Get notified when this Script is updated.
Mascot

Interested?

Become a Bananite

Already a Bananite? Login

228 lines | 5 kb | Raw Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/*
        Copyleft 2016 @ HamletEagle
        Plugin Thread: https://forums.alliedmods.net/showthread.php?t=259471
       
        Auto Plugins Adder to file is free software;
        you can redistribute it and/or modify it under the terms of the
        GNU General Public License as published by the Free Software Foundation.

        This program is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    
        GNU General Public License for more details.

        You should have received a copy of the GNU General Public License
        along with Auto Plugins Adder; if not, write to the
        Free Software Foundation, Inc., 59 Temple Place - Suite 330,
        Boston, MA 02111-1307, USA.
*/

#include <amxmodx>

#define Plugin  "Auto Plugins Adder"
#define Version "0.0.4"
#define Author  "HamletEagle"

new Trie:TriePluginsFromFile
new Array:ArrayPlugins

new HandleDir
new CurrentDir[128]
new CurrentFileName[256]

new CvarLoadFromCustomDir
new CvarLoadOnlyWithPrefix
new CvarRequieredPrefix

public plugin_init()
{
        register_plugin
        (
                .plugin_name = Plugin,
                .version     = Version,
                .author      = Author
        )
       
        CvarLoadFromCustomDir  = register_cvar("load_from_custom_dir"    , "0"      )
        CvarLoadOnlyWithPrefix = register_cvar("load_plugins_with_prefix", "0"      )
        CvarRequieredPrefix    = register_cvar("requiered_prefix"        , "_prefix")
       
        TriePluginsFromFile = TrieCreate()
        ArrayPlugins        = ArrayCreate(120)
       
        ReadPluginsFolder()
}

ReadPluginsFolder()
{
        get_localinfo("amxx_pluginsdir", CurrentDir, charsmax(CurrentDir))
       
        if(get_pcvar_num(CvarLoadFromCustomDir))
        {
                new const CustomFolder[] = "autoloader"
                format(CurrentDir, charsmax(CurrentDir), "%s/%s", CurrentDir, CustomFolder)
               
                if(!dir_exists(CurrentDir))
                {
                        mkdir(CurrentDir)
                }
        }
       
        HandleDir = open_dir(CurrentDir, CurrentFileName, charsmax(CurrentFileName))
        if(HandleDir)
        {
                new const Extension[] = ".amxx"
                new CheckForPrefix = get_pcvar_num(CvarLoadOnlyWithPrefix)
                new NeededPrefix[10], PosToCheck, bool:Replace
               
                if(CheckForPrefix)
                {
                        get_pcvar_string(CvarRequieredPrefix, NeededPrefix, charsmax(NeededPrefix))
                        PosToCheck = strlen(NeededPrefix)
                }
               
                //Get all plugins from plugins dir
                while(next_file(HandleDir, CurrentFileName, charsmax(CurrentFileName)))
                {
                        if(contain(CurrentFileName, Extension) != -1)
                        {
                                Replace = true
                                if(CheckForPrefix)
                                {
                                        Replace = !!equal(CurrentFileName, NeededPrefix, PosToCheck)
                                }
                               
                                if(Replace)
                                {
                                        ArrayPushString(ArrayPlugins, CurrentFileName)
                                }
                        }
                }
               
                close_dir(HandleDir)
                ParsePluginsFiles()
        }
        else
        {
                log_amx("Plugins folder could not be found")
                pause("a")
        }
}

ParsePluginsFiles()
{    
        new const OpenFlags[] = "rt"
       
        //Step 1: parse plugins.ini file
        get_localinfo("amxx_plugins", CurrentDir, charsmax(CurrentDir))
        ReadFile(fopen(CurrentDir, OpenFlags))
       
        //Step 2: parse plugins-.ini files
        get_localinfo("amxx_configsdir", CurrentDir, charsmax(CurrentDir))
       
        HandleDir = open_dir(CurrentDir, CurrentFileName, charsmax(CurrentFileName))
        if(HandleDir)
        {
                while(next_file(HandleDir, CurrentFileName, charsmax(CurrentFileName)))
                {
                        if(equal(CurrentFileName, "plugins-", 8))
                        {
                                format(CurrentFileName, charsmax(CurrentFileName), "%s/%s", CurrentDir, CurrentFileName)
                                ReadFile(fopen(CurrentFileName, OpenFlags))
                        }
                }
               
                close_dir(HandleDir)
        }
       
        //Step 3: parse custom configuration per map name
        new const MapFile[] = "maps"
        format(CurrentDir, charsmax(CurrentDir), "%s/%s", CurrentDir, MapFile)

        HandleDir = open_dir(CurrentDir, CurrentFileName, charsmax(CurrentFileName))
        if(HandleDir)
        {
                while(next_file(HandleDir, CurrentFileName, charsmax(CurrentFileName)))
                {
                        if(equal(CurrentFileName, "plugins_", 8))
                        {
                                format(CurrentFileName, charsmax(CurrentFileName), "%s/%s", CurrentDir, CurrentFileName)
                                ReadFile(fopen(CurrentFileName, OpenFlags))
                        }
                }
               
                close_dir(HandleDir)
        }
       
        AddPlugins()
}

ReadFile(FilePointer)
{
        if(FilePointer)
        {
                new FileData[128], Needed[128], UnNeeded[128]
               
                while(!feof(FilePointer))
                {
                        fgets(FilePointer, FileData, charsmax(FileData))
                        trim(FileData)
                       
                        if(FileData[0] != EOS)
                        {
                                parse(FileData, Needed, charsmax(Needed), UnNeeded, charsmax(UnNeeded))
                               
                                if(Needed[0] == ';' && Needed[1] != EOS)
                                {
                                        copy(Needed, charsmax(Needed), Needed[1])
                                }
                               
                                TrieSetCell(TriePluginsFromFile, Needed, 0)
                        }
                }
               
                fclose(FilePointer)
        }
}

AddPlugins()
{    
        new i, PluginName[120]
        for(i = 0; i < ArraySize(ArrayPlugins); i++)
        {
                ArrayGetString(ArrayPlugins, i, PluginName, charsmax(PluginName))
                if(TrieKeyExists(TriePluginsFromFile, PluginName))
                {    
                        ArrayDeleteItem(ArrayPlugins, i)
                        i = i - 1
                }
        }
       
        TrieDestroy(TriePluginsFromFile)
       
        new bool:FileEdited, Size = ArraySize(ArrayPlugins)
        if(Size)
        {
                get_localinfo("amxx_plugins", CurrentDir, charsmax(CurrentDir))
               
                new FilePointer = fopen(CurrentDir, "a")
                if(FilePointer)
                {
                        for(i = 0; i < Size; i++)
                        {
                                ArrayGetString(ArrayPlugins, i, PluginName, charsmax(PluginName))
                                fprintf(FilePointer, "%s^n", PluginName)
                        }
                       
                        fclose(FilePointer)
                        FileEdited = true
                }
        }
       
        ArrayDestroy(ArrayPlugins)
       
        if(FileEdited)
        {
                //Restart so all new added plugins are loaded
                server_cmd("restart")
        }
}
Description top

While I had some servers, I found quite annoying that after every plugin I was installing, I must add it manually in plugins.ini. But the biggest problem was that sometimes I forget to do it and was wondering why the plugin does not work. 

This plugin, as it name says, is a plugin auto adder. At every server start/restart/map change it parse plugins folder and add everything in plugins.ini
I'm sure that you think now, "this won't work, it will keep adding same plugins that are already in a file" or "what if I have custom plugins configuration per map or per mod ?". Well:
  • It adds only the plugins that ARE NOT already in plugins.ini
  • Custom configuration are taken into accout:
    • Any plugin from addons/amxmodx/configs/plugins-mod*.ini is not added.
    • Any plugin from addons/amxmodx/configs/maps/plugins_map_name*.ini is not added.
    • Any plugin from addons/amxmodx/configs/maps/plugins_map_prefix*.ini is not added.
  • Any disabled plugin(no matter from what config file from above) won't be added again.

1.plugins_mod: mod can be any custom mod(like the one from Furiens by ConnorMcLeod)
2.plugins_map_name: can be any map name
3.plugins_map_prefix: can be any map prefix(de/cs/fy/as)

You don't have to do anything, just install and let it do all the work for you. Plugins are instantly loaded.
I'm open to suggestions, please post any ideea you have, I would be glad to add it, if it's fine.
Requirements top

Nothing, just:
  • AmxModX
  • A server without dproto.This is not generally needed, but I won't help you if you are running an outdated server with dproto. If you are experiencing problems, update your server/ fix the erros by yourself.
Installation top

To install the plugin:
  1. Download the resources from this post.
  2. Put AutoPluginsAdder.amxx in addons/amxmodx/plugins
  3. Open addons/amxmodx/configs/plugins.ini and add at the end of this file AutoPluginsAdder.amxx
  4. You can put AutoPluginsAdder.sma file into addons/amxmodx/sources but this is not mandatory.
  5. Restart the server/change map.
Cvars top

Cvars that you can configure:
  • load_from_custom_dir
    • Default Value: 0 -> use 1 to turn on
    • If you want to load plugins from a custom folder enable this cvar.
    • At the first time when it is turned on, it will create in addons/amxmodx/plugins a folder called autoloader. Place inside it any plugin that you want to get loaded.
    • Any plugin from addons/amxmodx/plugins won't get loaded.
  • load_plugins_with_prefix
    • Default Value: 0 -> 1 to turn on
    • Allow you to load only plugins that have a custom prefix.
  • requiered_prefix
    • Default Value: _prefix
    • If the above cvar is turned on it will load only plugins that have a custom prefix set from this one.
    • If you set it to zm_, then only plugins that starts with zm_will be loaded
ChangeLog top
  • V 0.0.4:
    • Fixed bugs
    • Code improved
Downloads top
  • V 0.0.3:115

Comments

None found

Share

Shareable Image:
Share banner
HTML embed code:
BB embed code:
Markdown embed code:

More embeddable images

Bookmark and Share

Credits

Original Authors
HamletEagle
AMXX Script/Codes

Submitter

Rj. avatar
Rj. IN PLAYGROUND
Homepage
Member Joined 9 months ago
34 medals 4 legendary 8 rare
  • Submitted 15 Tools Medal icon
  • Submitted 50 Gamefiles Medal icon
  • 15+ Entries! GameBanana’s Christmas Giveaway 2016 Medal icon
  • Thanked 500 submitters Medal icon
  • 2nd Place - Game Poetry Contest Medal icon
  • Submitted 5 Tools Medal icon

Rj.
Redistributor
Are you the owner? Request Ownership
Send a Private Message to the submitter

Category

Attributes

Language
Pawn (AMXX)

Stats

Posts
0
Views
108
Date Added
13 days ago
Mar 17 2017 @ 1:09pm UTC
Date Updated
13 days ago
Mar 17 2017 @ 1:09pm UTC