Raised This Month: $ Target: $400
 0% 

Brand new


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Savior69
New Member
Join Date: Jan 2005
Location: Brisbane, Australia
Old 01-04-2005 , 05:15   Brand new
Reply With Quote #1

Hey everyone,

This is my first time to these forums and am going to make an attempt at learning amxx coding. I dont know anything about coding so i was wondering where the best place to start would be. If i learn enough im looking at major plugins in the far future. As i said im just looking for the best thing to start me off.

Any help is appreciated.

Savior
Savior69 is offline
PM
hello, i am pm
Join Date: Jan 2004
Location: Canalization
Old 01-04-2005 , 07:35  
Reply With Quote #2

I have a good mood so I decided to say all the basics here.

1) You should know what you are trying to do.
This one is probably self explaining ;)

2) You can write plugins for AMXX in the Small(C) scripting language. If you want to read about the technical stuff, you will find it somewhere on http://www.compuphase.com/small.htm (the docs)

3) When you write a plugin in the SmallC language, save it as a .sma file. Then you have to compile it. The "compiler", that is the program that compiles your plugin, checks whether the syntax of what you wrote is correct, and checks the language grammar and stuff. Then it generates something that is easy for AMXX to load and run (a .amxx file). You can not turn a .amxx file back to a .sma file without a lot of skill, effort and guessing, so better keep your sma files in a safe place.

4) Let's start with an example plugin:
Code:
#include <amxmodx> public plugin_init()    register_plugin("Plugin name", "Version", "Author")

If you copy-and-paste this into a new .sma file, save it in the scripting subdirectory of your AMXX tree, run amxxsc.exe filename.sma , it should produce filename.amxx, which you can put into the plugins directory and add into plugins.ini as usual.
Let's examine what the plugins does:

The compiler skips blank lines. So the first actual line is
#include <amxmodx>
This basically tells the compiler what is possible and what not in the world of AMXX.

The next line is
Code:
public plugin_init()
This is a function. Programs in the SmallC language consist of such functions. The first word, public, tells the compiler that it should make the function available for AMXX. If you would leave it out, AMXX wouldn't know about it. But we want this function to be called by AMXX so we declare it public. plugin_init is the name of the function. The () tells the compiler that that function has no parameters. We will see more about parameters later.

The next line is:
Code:
   register_plugin("Plugin name", "Version", "Author")
When the function plugin_init is called, this command is executed. What you see is a function call. This time, it's the other way round: We call a function in AMXX. The function name is register_plugin, and it takes three parameters: The plugin name, the plugin version, and the plugin author. Obviously, it tells AMXX information about the plugin.

Ok, this plugin should only load and do nothing.
So, let's add something funky: We want it to print "Hello world!" on load!!! (elite)

So, the command to print something into AMXX's logs is log_amx.
We can try to add:
Code:
   log_amx("Hello world!")
to the end of the plugin. But, when we try to compile it, we would most likely get a lot of errors. Why is that? Because the compiler doesn't know that the line belongs to the plugin_init function. It normally only takes one line. But, that would be boring. So what can we do? We can group the two commands into one block. Let's replace the plugin_init stuff with this:
Code:
public plugin_init() {    register_plugin("Plugin name", "Version", "Author")    log_amx("Hello world!") }
In this case, { and } tell the compiler that all the code between them belongs to the function. If you compile and run the plugin, you will probably see Hello world! in the logs on load.

Ok, we have a plugin that logs something. But that's still pretty boring. We should try to make some fun of some players!

Let's say, we want a plugin that tells the players all the time that they can have god mode if they write something into the console. Let's say, every minute. But when they write the command, it kills them! MWAHAHAHAH!
Ok, let's start like this again:
Code:
#include <amxmodx> public plugin_init() {    register_plugin("Ownzor", "1.0", "The elite man")
Ok, we changed the name, version, and author. But now, we want to show the message every minute. We can use a "task" for this. Let's continue like this:
Code:
   set_task(60.0, "show_message", _, _, _, "b") }
Uh, looks pretty complicated? Ok, this looks a bit similar to the line with register_plugin. So this will also be a function call. Let's reveal something: Open the file amxmodx.inc in the scripting/include folder, and search for set_task. You will find this:

Code:
/* Calls function on specified time. * Flags: * "a" - repeat. * "b" - loop task. * "c" - do task on time after a map timeleft. * "d" - do task on time before a map timelimit. */ native set_task(Float:time,const function[],id = 0,parameter[]="",len = 0,flags[]="", repeat = 0);
There we have it! amxmodx.inc contains all the commands, somehow! You would surely also find register_plugin. Ok, let's examine this section.
It start's with a /* . This tells the compiler that it should ignore everything, until it finds a */ . Ok, so the compiler doesn't see the code until the line native set_task(blablabla); . So what's it for? It tells the human readers what the function does. It's a so called comment. There are two kinds of comments: multi-line comments and single-line comments. The /* stuff */ comment is a multi line comments. The more common comment is the other one:
Code:
code // This is a comment! more code
It starts with // and goes until the end of the line. Ok, so let's skip the comments for now, and look at the relevant line:
Code:
native set_task(Float:time,const function[],id = 0,parameter[]="",len = 0,flags[]="", repeat = 0);
The first word is native. This tells the compiler that it is a function inside of AMXX which a plugin can call. Ok, then, the function name follows, and then the parameters:

1) Float:time
Float: tells the compiler that the parameter is not a whole number. We will talk about this later. the next parameter is const function[] . This is a string parameter. You can pass text to it, not only numbers. const tells the compiler that the function does not modify the parameter, and [] indicates the string property in this case. Let's ignore the next 3 parameters, and go to flags: flags[]="" . This is also a string. The const is lacking, but the function does not modify it anyway, someone forgot the const, although it's actually not needed at all. Anyway, this has to be a string parameter again because there is [] . What is ="" ? It tells the compiler that if you don't specify the parameter, the default value will be "", which is an empty string. So, what does this parameter do? Let's look at the comment again. It specifies the behaviour of the task. Ok, let's forget about this, and return to our plugin:

We did:
Code:
   set_task(60.0, "show_message", _, _, _, "b")
So, 60.0 is the time parameter. It needs the .0 because it was declared as Float, you remember. This is how often the task will be called, in seconds. The next parameter is the name of the function that will be called. We set it to "show_message". We set the next 3 parameters to _. What is that? Well, if you look at the set_task line of amxmodx.inc again, you will notice that these parameters have a =something declaration, so they have default values. _ tells the compiler to use the default value.
We set the last parameter to "b". In the set_task comment, it says, that "b" is a looping task. So it goes on forever. Ok, so now, we have made a task that is called every minute. But, what does it do? It calls the show_message function. So, we need to write it!
Code:
public show_message() {    client_print(0, print_center, "Enter gimme_god into the console to get godmode!") }
Ok, this is a function like plugin_init. We want the tasks system which is inside of AMXX to call it, so it needs to be public. Again, it has no parameters. So, the code inside of it calls client_print. You can look it up in amxmodx.inc again. 0 means that it will show the message to all players. print_center means that the message will be centered. The next parameter is the text that will be printed. Ok, so now we have done this part. Now, let's make the gimme_god command!
Let's add this to the end of plugin_init (before the } and after set_task):
Code:
   register_clcmd("gimme_god", "gimme_god")
Ok, what does this do? It registers a client command. If the client enters "gimme_god" in the console (without quotes) (that's the first parameter), the function gimme_god will be called in the plugin (that's the second parameter). They names don't need to be equal, but if the plugin is simple, we can keep it simple

Ok, so AMXX will want to call the gimme_god function.. So what will we need? Exactly, to write a public function!
Code:
public gimme_god(id) {    client_cmd(id, "kill")    client_print(id, print_center, "OLOLOL! PWNZ0RED!") }
Wow, this one is different! It has a parameter. The parameter is id. It contains the id of the player that entered the command. So, what does it do? It executes "kill" on the player, as if he entered it into his console! So it kills him. Then it shows him a centered message. MWAHAH!
So the plugin should look like this in the end:
Code:
#include <amxmodx> public plugin_init() {    register_plugin("Ownzor", "1.0", "The elite man")    set_task(60.0, "show_message", _, _, _, "b")    register_clcmd("gimme_god", "gimme_god") } public show_message() {    client_print(0, print_center, "Enter gimme_god into the console to get godmode!") } public gimme_god(id) {    client_cmd(id, "kill")    client_print(id, print_center, "OLOLOL! PWNZ0RED!") }

Ok, this was a mini tutorial, I have done my best, but I want to stop now and I hope you have understood something
Also, I haven't tested this, so I'm not 100% sure whether it works.
You can find more here:
http://amxmodx.org/doc/ under the Scripting Tutorial section.

Good luck
__________________
hello, i am pm
PM is offline
Savior69
New Member
Join Date: Jan 2005
Location: Brisbane, Australia
Old 01-04-2005 , 17:09  
Reply With Quote #3

Thanks for your time PM, your tutorial will be put to great use
Savior69 is offline
Savior69
New Member
Join Date: Jan 2005
Location: Brisbane, Australia
Old 01-04-2005 , 18:33  
Reply With Quote #4

On another note where can i get every command from?

Also,

Am i allowed to open up other peoples amx scripts and read them and try incorporate it into my own, and give credit to the original author?
Savior69 is offline
FeuerSturm
AlliedModders Donor
Join Date: Apr 2004
Old 01-04-2005 , 18:36  
Reply With Quote #5

here you can get the functions:
http://amxmodx.org/funcwiki.php

further more they're declared in the includes as well
(\addons\amxmodx\scripting\include\)

and yes, you can read and use other people's plugins as a reference,
but you have to mention the original authors.
FeuerSturm is offline
XxAvalanchexX
Veteran Member
Join Date: Oct 2004
Location: abort73.com
Old 01-04-2005 , 19:05  
Reply With Quote #6

Sticky: Helpful Stuff / Read here first!
__________________
No longer around. Thanks your support, everyone! As always:
THIS ONES FOR YOU
3000 PTS
XxAvalanchexX is offline
Peli
Veteran Member
Join Date: Mar 2004
Location: San Diego, CA
Old 01-05-2005 , 00:22  
Reply With Quote #7

Avalanche posted a nice link but you might also want to search "Scripting Tutorial" and you will find some other nice ones.
Peli is offline
Send a message via MSN to Peli
Da Bishop
Senior Member
Join Date: Aug 2004
Location: Chester County PA
Old 01-05-2005 , 12:22  
Reply With Quote #8

erhm... stickey has the link to the tutorials
__________________
Anything that is done can only be done better by urself - since life is a opinion make it the way urs feel its best

~live by it
Da Bishop is offline
Send a message via MSN to Da Bishop
Peli
Veteran Member
Join Date: Mar 2004
Location: San Diego, CA
Old 01-05-2005 , 22:05  
Reply With Quote #9

Yea but trust me , there are some that were not posted. I read them myself when I started scripting. But I guess it doesn't matter , you can just search google for some Small tutorials.
Peli is offline
Send a message via MSN to Peli
-Jedi-Knight
Junior Member
Join Date: Jan 2005
Old 01-07-2005 , 22:28   .sma
Reply With Quote #10

I like the Tutorial Help..its awsome, just cant figure out how to create a .sma file well plz post reply thanks
__________________
May the force be with you, always.
-Jedi-Knight is offline
Send a message via AIM to -Jedi-Knight
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 19:17.


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