I can hardly believe that I have been asked how to compile a plugin, when there is a webcomplier right on the main site, so I've written this little turorial to encourage people to stop asking that question.
Step 1: Getting the Code
First thing we're going to do, is to get the code for the plugin, in this example we will use the following code:
Code:
#include <amxmodx>
#include <amxmisc>
public plugin_init()
{
register_plugin("Sample Plugin" , "1.0" , "Throstur");
}
This code will do absolutely nothing, because there's nothing in it, but the one you have
will.
All you have to do is copy the code, select all the stuff in the
Small box and press
CTRL + C or right click on the selected code and press
Copy.
If you already have the code in a small or
pawn (.sma) file, just select all the code in the file and copy that.
Great! Now you have your code!
Step 2: Compiling the Plugin
Go to
http://www.amxmodx.org/webcompiler.cgi or click
here to go to the Web Compiler.
On this page there will be
three different boxes, to make the webcompiler work correctly, the best thing to do is to
ignore the first box.
In the second box [Short plugin name]; type in a name which corresponds to your plugin, for example, if you have a respawn plugin, type in respawn, if you have a HE Arena plugin, type in something like he_arena or hearena. The name doesnt matter, as long as it's not the same name as any other used plugin you have on your server.
In the last, bigger box,
paste your code by either pressing
CTRL + V or by right clicking anywhere in the box and clicking on
Paste.
Now that you've inputted your plugin, there's but one thing left to do, compiling it.
To compile, you must press the
lowest compile button,
there are two of these buttons, but the one you are interested in is the one
under the code you just pasted. When done compiling you will see compile messages. If you compiled correctly, you'll see something
similar to this:
Code:
Your plugin successfully compiled!
Use the link below to download your plugin. It will be valid for ten minutes.
http://www.amxmodx.org/webcompiler.cgi?go=dl&id=76337
Welcome to the AMX Mod X 1.70-300 Compiler.
Copyright (c) 1997-2005 ITB CompuPhase, AMX Mod X Team
Header size: 116 bytes
Code size: 76 bytes
Data size: 108 bytes
Stack/heap size: 16384 bytes; estimated max. usage=174 cells (696 bytes)
Total requirements: 16684 bytes
Please take good note of the fact that the bumbers will probably be completely different, because you'll be compiling a real plugin.
If you compiled your plugin correctly, you may stop reading here.
Step 3: Recognising Your Error
Sometimes when you're compiling your plugin, it just wont work, even though somebody else wrote it. Often it is a result of a spelling error or an accidental mixup in parameters, these things happen, and you should post a thread about your problem in the
Scripting Help forum.
To see what your error is, look at the header after compiling your plugin, here I will show some examples:
(This one is so simple that the code isnt needed)
Code:
Your plugin failed to compile! Read the errors below:
Welcome to the AMX Mod X 1.70-300 Compiler.
Copyright (c) 1997-2005 ITB CompuPhase, AMX Mod X Team
/home/users/amxmodx/tmp3/textWOUSkK.sma(6) : error 017: undefined symbol "register_plugain"
1 Error.
Could not locate output file /home/groups/amxmodx/public_html/websc3/textWOUSkK.amx (compile failed).
In this particular plugin error, the mistake is fundamental, it is of spelling. I have mispelt
register_plugin as
register_plugain. To fix this, just make sure that the spelling is correct.
Another example (this time it's called truck):
Code:
#include <amxmodx>
#include <amxmisc>
#include <fun>
public plugin_init()
{
register_plugin("Truck","1.0","Throstur")
register_cvar("amx_truck","0")
}
public truck(id)
{
truck(id)
set_user_hp(id,250)
}
In this example, the error you get is this:
Code:
Your plugin failed to compile! Read the errors below:
Welcome to the AMX Mod X 1.70-300 Compiler.
Copyright (c) 1997-2005 ITB CompuPhase, AMX Mod X Team
/home/users/amxmodx/tmp3/textLzUeWn.sma(15) : error 017: undefined symbol "set_user_hp"
1 Error.
Could not locate output file /home/groups/amxmodx/public_html/websc3/textLzUeWn.amx (compile failed).
The error here is that
set_user_hp doesnt exist, but since there is a symbol which does what you need, you will replace it with that, which is
set_user_health
Code:
#include <amxmodx>
#include <amxmisc>
#include <fun>
public plugin_init()
{
register_plugin("amx_truck","1.0","Throstur")
register_cvar("amx_truck","0")
}
public truck(id)
{
truck(id)
set_user_health(id,250)
}
Another example (this one is longer):
Code:
#include <amxmodx>
#include <amxmisc>
public plugin_init()
{
register_plugin("Sample Plugin" , "1.0" , "Throstur");
register_concmd("amx_sample" , "cmdSample" , ADMIN_KICK , "<player> <1 | 0> - Sampleizes the player");
register_event("ResetHUD" , "Event_Reset" , "b");
}
public Event_Reset(id)
{
if(g_bSample[id])
set_task(0.1 , "Sample" , id);
}
public cmdSample(id , level , cid)
{
if(!cmd_access(id , level , cid , 3))
return PLUGIN_HANDLED;
new szArg[36] , szArg2[4];
read_argv(1 , szArg , 35);
read_argv(2 , szArg2 , 3);
new iMode = str_to_num(szArg2);
new iTarg = cmd_target(id , szArg , 14);
if(!iTarg)
return PLUGIN_HANDLED;
get_user_name(iTarg , szArg , 35);
if(!iMode)
{
if(!g_bSample[iTarg])
console_print(id , "[AMXX] %s is already Sampleized." , szArg);
else
{
g_bSample[iTarg] = false;
console_print(id , "[AMXX] %s is no longer Sampleized." , szArg);
client_print(iTarg , print_chat , "[AMXX] You are no longer Sampleized.");
}
}
else
{
g_bSample[iTarg] = true;
set_task(0.1 , "Sample" , iTarg);
console_print(id , "[AMXX] %s has been Sampleized", szArg);
}
return PLUGIN_HANDLED;
}
public Sample(id)
{
if(!is_user_alive(id))
return PLUGIN_HANDLED;
client_print(id , print_chat ,"[AMXX] You have been Sampleized! HAHAHAHAHA.");
return PLUGIN_HANDLED;
}
public client_disconnect(id)
{
g_bSample[id] = false;
}
This time the code looks pretty good, not much wrong at all, but there's loads of errors:
Code:
Your plugin failed to compile! Read the errors below:
Welcome to the AMX Mod X 1.70-300 Compiler.
Copyright (c) 1997-2005 ITB CompuPhase, AMX Mod X Team
/home/users/amxmodx/tmp3/textSWiElx.sma(12) : error 017: undefined symbol "g_bSample"
/home/users/amxmodx/tmp3/textSWiElx.sma(12) : warning 215: expression has no effect
/home/users/amxmodx/tmp3/textSWiElx.sma(12) : error 001: expected token: ";", but found "]"
/home/users/amxmodx/tmp3/textSWiElx.sma(12) : error 029: invalid expression, assumed zero
/home/users/amxmodx/tmp3/textSWiElx.sma(12) : fatal error 107: too many error messages on one line
Compilation aborted.
4 Errors.
Could not locate output file /home/groups/amxmodx/public_html/websc3/textSWiElx.amx (compile failed).
The problem in this code, is that g_bSample doesnt exist! It hasn't been created in the plugin, so what to do? Easy! You create it!
Since g_bSample is a boolean, it'll look like this:
new bool:g_bSample[33];
now, paste that at the top of your code, so it looks like this:
Code:
#include <amxmodx>
#include <amxmisc>
new bool:g_bSample[33];
public plugin_init()
{
register_plugin("Sample Plugin" , "1.0" , "Throstur");
register_concmd("amx_sample" , "cmdSample" , ADMIN_KICK , "<player> <1 | 0> - Sampleizes the player");
register_event("ResetHUD" , "Event_Reset" , "b");
}
public Event_Reset(id)
{
if(g_bSample[id])
set_task(0.1 , "Sample" , id);
}
// rest of code not shown due to lenght, you get the picture.
Compile it with the extra line near the top, and you get no errors:
Code:
Your plugin successfully compiled!
Use the link below to download your plugin. It will be valid for ten minutes.
http://www.amxmodx.org/webcompiler.cgi?go=dl&id=76348
Welcome to the AMX Mod X 1.70-300 Compiler.
Copyright (c) 1997-2005 ITB CompuPhase, AMX Mod X Team
Header size: 512 bytes
Code size: 4056 bytes
Data size: 1868 bytes
Stack/heap size: 16384 bytes; estimated max. usage=234 cells (936 bytes)
Total requirements: 22820 bytes
Now, I'm not going to take you through every single error possible, but now you know at least that little errors like I've shown you can be asked for help with, as long as you show them the small code.