Raised This Month: $ Target: $400
 0% 

Extremely Basic Amxx Scripting For First Time Coders!


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Rolnaaba
Veteran Member
Join Date: May 2006
Old 07-10-2006 , 01:04   Extremely Basic Amxx Scripting For First Time Coders!
Reply With Quote #1

NOTE: To make plugin creating easier use a text editor! AMXX Studio , Crimson Editor

Through out this tutorial you will be creating a extremely simple and basic plugin.
You will learn the most basic of AMXX scripting. Before we begin you need to understand
that anything writen with two forward slashes ("//") in front of it will be a coment and
will not interfer with your code. ANYTHING can be typed after ("//"), but that only lasts
for one line for long coment messages ("/*") and ("*/") are used for multiple lines
For Example:
Code:
// look at me i am a coment and NOT code, but i only last for one line! /* I am also a comment but i can last for multiple lines until you end the coment! see? this why you dont have to type ("//") every line on long messages! */
Now Let us Begin:
When you create a plugin the very first thing you do is choose something to make,
in this case we will be creating a simple plugin that will allow people to get hp
by saying something in the chat

Begining your plugin!
When starting your plugin the first step is the includes, these are the files wich will
allow you to use comands, certain comands are defined in the includes so for the computer
to know what your tlaking about it has to have the manuals (the includes!)
For Example:
Code:
#include <amxmodx> #include <amxmisc> //these two includes are the basic includes they contain the most basic comands required for a plugin to work #include <fun> //this module allows you to change hp, ac, ect.
Many include files have modules that run them such as cstrike, and fun but that is a different tutorial
Moving on, now that we have the proper includes the next thing we would do is precache.
For this perticular plugin we dont need to cache any models or sounds or anything but
why dont we look at how anyway?
For Example:
Code:
public plugin_precache() //this states that you are starting the precache sequence next you will define what needs to be cached (downloaded by people joining the server) { //These are not required, and most comands do not require them, ut i like to use them(keep in mind the stuff behind the ("//") is NOT code!!)  precache_model("models/mymodel.mdl") //this states you want to cache a model, and you specify the path to the .mdl file  precache_sound("sounds/mysound.mp3") //this states you want to cache a sound, and you specify the path to the .mp3 file }
*NOTE* in between your bracers ("{") and ("}") be sure to indent, agin this makes the code neat and provides a smooth run
Next we will be doing the plugin_init() this is where your plugin will be declared, and
where comands, events, menues and many many things are initialized (hence the init). ( we will
not be doing events and menues in this plugin)
For Example:
Code:
public plugin_init() //this states that you are starting the init of your plugin and you will declare comands, ect. here {  register_plugin("Get Hp Mod", "1.0", "Rolnaaba") //this registers your plugin, the first thing in quotes in the plugin name, second the version number, and lastly the author's name  register_concmd("say gethp", "func_gethp") //this registers a console comand, the comand is "say gethp" which is the same as saying "gethp in the chat, the second quotes is the func it will call upon (will define it later)  register_cvar("hpmod_on", "1") //this makes a cvar which will turn on or off the plugin (1=on 0=off) the first quotes is the cvar name, second the default value of the cvar }
This concludes the beging section of your plugins, now we move on to coding functions,
this should take long in this case since we defined only 1 function, the "func_gethp"
which is called upon anytime someone says gethp in the chat.

Coding the rest of your plugin!
Now earlier on the plugin_init() we made that function called "func_gethp" that is called when someone
says gethp in the chat lets define that now.
For Example:
Code:
public func_gethp(id) //the index in the parenthasis () is who this will be executed on (id is whoever called up the function) {  if(get_cvar_num("hpmod_on") == 0)  {   return PLUGIN_HANDLED  }  else  {   set_user_health(id, get_user_health(id) + 100)   return PLUGIN_HANDLED  }  return PLUGIN_HANDLED }
Whoa, what did we just do? Lets reqind starting with "if" this is called an "if function" it
executes whats after it IF w/e u put in perenthasis is true, next we wrote (get_cvar_num("hpmod+on") == 0)
"get_cvar_num" will read the cvar and see what it is set to, ("hpmod_on") is which cvar to read, and
== 0 is what you want the cvar should equal to be able to continue. return PLUGIN_HANDLED returns the value
PLUGIN_HANDLED, which tells plugins to end that function immediately. if you were a computer you weould
read the line "if(get_cvar_num("hpmod_on") == 0)" as: If the cvar "hpmod_on" is 0 I must end this function!

Next we typed "else" this calls the OPPOSITE of and if function you type above it, which is the same as typing
"if(get_cvar_num("hpmod_on") == 1)" but we skipped all that and just wrote else. then we used
"set_user_health(id, get_user_health(id) + 100)" set_user_health changes a persons health to what you want,
id is who's hp to change, and "get_user_health(id) + 100)" is the amount to set it to. This will get how much HP
they have at the moment, add 100 to it and set their health to that.

The code above has been dragged out for the sake of teaching if we were actually to make this plugin you could
condense this to simply:
Code:
public func_gethp(id)</p>     if(get_cvar_num("hpmod_on"))</p>         set_user_health(id, get_user_health(id) + 1
(credits to Hawk552 for this code snipette)
As i said before Bracers are not required and it is mostly up to the creater whether or not to use them.

Our Plugin!

Code:
#include <amxmodx> #include <amxmisc> #include <fun> public plugin_init() {  register_plugin("Get Hp Mod", "1.0", "Rolnaaba")  register_concmd("say gethp", "func_gethp")  register_cvar("hpmod_on", "1") } public func_gethp(id) {  if(get_cvar_num("hpmod_on") == 0)  {   return PLUGIN_HANDLED  }    else  {   set_user_health(id, get_user_health(id) + 100)   return PLUGIN_HANDLED  }  return PLUGIN_HANDLED }
Congradulations, You have made a plugin!
If there you still need more help visit This More Advanced Beginer's Guide or post below for help or correction about my imperfect code
Attached Files
File Type: txt SIMPLE_SCRIPTING_BEGINER_GUIDE.txt (6.2 KB, 237 views)
__________________
DO NOT PM me about avp mod.

Last edited by Rolnaaba; 07-10-2006 at 15:29.
Rolnaaba is offline
 



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:05.


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