Raised This Month: $ Target: $400
 0% 

Compiling a Plugin


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Throstur
Senior Member
Join Date: Nov 2004
Location: Iceland
Old 06-10-2006 , 11:20   Compiling a Plugin
Reply With Quote #1

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.
Throstur is offline
Send a message via AIM to Throstur Send a message via MSN to Throstur
Deviance
Veteran Member
Join Date: Nov 2004
Location: Sweden
Old 06-10-2006 , 11:27  
Reply With Quote #2

well, nice done
but you should leave comment's in code of what that part/code do
Deviance is offline
Throstur
Senior Member
Join Date: Nov 2004
Location: Iceland
Old 06-10-2006 , 11:30  
Reply With Quote #3

To keep things at a minimum, I leave the code raw, because a person who wants to compile a plugin doesnt need to know what the code does, they just need to know how to ask for help, and compile it if there are no errors.

Thanks for the constructive criticism though
Throstur is offline
Send a message via AIM to Throstur Send a message via MSN to Throstur
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 06-10-2006 , 12:08  
Reply With Quote #4

This won't help at all simply because there are too many people who aren't willing to put any effort into something themselves and instead jump right to the fastest possible source of assistance. Still worth a sticky IMO, or maybe a link in the scripting tutorial thread.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
Velocity36
Senior Member
Join Date: Jul 2005
Old 06-10-2006 , 15:17  
Reply With Quote #5

Quote:
Originally Posted by Doombringer
well, nice done
but you should leave comment's in code of what that part/code do
__________________
[img]http://img81.**************/img81/593/velocityferrari7mx.jpg[/img]
Velocity36 is offline
Peli
Veteran Member
Join Date: Mar 2004
Location: San Diego, CA
Old 06-10-2006 , 15:19  
Reply With Quote #6

Doing that would just confuse people who don't know how to script. There's no real point, this isn't a 'how to script tutorial' it's a 'how to compile tutorial'.
Peli is offline
Send a message via MSN to Peli
Throstur
Senior Member
Join Date: Nov 2004
Location: Iceland
Old 06-10-2006 , 15:43  
Reply With Quote #7

Quote:
Originally Posted by Peli
Doing that would just confuse people who don't know how to script. There's no real point, this isn't a 'how to script tutorial' it's a 'how to compile tutorial'.
Precisely my point.

Quote:
Originally Posted by Throstur
To keep things at a minimum, I leave the code raw, because a person who wants to compile a plugin doesnt need to know what the code does, they just need to know how to ask for help, and compile it if there are no errors.
Throstur is offline
Send a message via AIM to Throstur Send a message via MSN to Throstur
Deviance
Veteran Member
Join Date: Nov 2004
Location: Sweden
Old 06-10-2006 , 15:56  
Reply With Quote #8

Quote:
Originally Posted by Peli
Doing that would just confuse people who don't know how to script. There's no real point, this isn't a 'how to script tutorial' it's a 'how to compile tutorial'.
if you dont know how to script, why compile a plugin if you dont know how to create one?
Deviance is offline
Peli
Veteran Member
Join Date: Mar 2004
Location: San Diego, CA
Old 06-10-2006 , 16:02  
Reply With Quote #9

Quote:
Originally Posted by Doombringer
Quote:
Originally Posted by Peli
Doing that would just confuse people who don't know how to script. There's no real point, this isn't a 'how to script tutorial' it's a 'how to compile tutorial'.
if you dont know how to script, why compile a plugin if you dont know how to create one?
He's implying that you go and try to install and eventually compile plugins that you download from this website.

If having plugins on your server required you to know how to script in AMX Mod X, than there would only be so few servers running AMX Mod X, think about that.

You don't need to understand the scripting language in a plugin to know how to compile it.
Peli is offline
Send a message via MSN to Peli
Deviance
Veteran Member
Join Date: Nov 2004
Location: Sweden
Old 06-10-2006 , 16:14  
Reply With Quote #10

Quote:
Originally Posted by Peli
Quote:
Originally Posted by Doombringer
Quote:
Originally Posted by Peli
Doing that would just confuse people who don't know how to script. There's no real point, this isn't a 'how to script tutorial' it's a 'how to compile tutorial'.
if you dont know how to script, why compile a plugin if you dont know how to create one?
He's implying that you go and try to install and eventually compile plugins that you download from this website.

If having plugins on your server required you to know how to script in AMX Mod X, than there would only be so few servers running AMX Mod X, think about that.

You don't need to understand the scripting language in a plugin to know how to compile it.
lol you need to understand what your doing when your compile, that means you need an basic of what your compiling

ppl'z doesn't need to know anything about scripting only cause they have AMX MOD X plugins on their server, they just go and spam up in some help thread if it's something wrong.
Deviance 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 08:09.


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