View Single Post
Author Message
PvtSmithFSSF
Senior Member
Join Date: Jul 2008
Old 08-09-2008 , 12:23   2-Part Beginner Scripting Tutorial [REVISED]
Reply With Quote #1

I was really bored last week..So for your enjoyment I made a 2-part tutorial covering the VERY basics of amxx scripting for those new scripters who don't understand how anything works.

I really hope you enjoy them and learn from them. +Karma is appreciated if you like my work.

Part I - The Beginning...

Code:
/* This is my part one of my first tutorial, meant for people that just cannot learn scripting.
What we're going to do with this tutorial is make it so when a player types /tutorial, they get
special abilities and stuff.  In part II, you will learn more basics and stuff we can add on
to make this plugin better.
 
You can PM me on AlliedModders if you have questions or need extra help.  I hope
you all like it.  By the way, if I put // in front of a line, that means it's a comment.
If you want a comment to be multiple lines long, do what I did like in this comment.
You can delete all the lines with // in front once your finished, if you want.
*/
 
// These are the modules you need to make the plugin work.  Leave them alone
// unless you know what you're doing.
#include <amxmodx>
#include <cstrike>
#include <fun>
 
// These define the name, version, and author of the plugin.
#define PLUGIN "Beginner Tutorial Part I"
#define VERSION "1.0"
#define AUTHOR "PvtSmithFSSF"
 
// Think of this as your control center, where many things happen.
public plugin_init() 
// These {'s and }'s are needed whenever you have code.  They need to surround all the code.
{    
    // This defines what we wrote above.
    register_plugin(PLUGIN, VERSION, AUTHOR)
 
    // Register_clcmd is saying 'When a user types 'something' , then 'something' happens.
    register_clcmd("say /tutorial", "steroids")
    // The first parameter ("say /tutorial"), is where you define what the user must type
    // in chat, in order for the second parameter ("steriods") to happen.  So this is saying,
    // "When a user types /tutorial , "steriods" happens.  But AMXX doesn't know what 'steroids'
    // is yet.  So we tell it.
}
 
// This tells AMXX what 'steriods' is, which is what you made above.
public steroids(id)
{
    // Now lets make something happen.  Everything here will happen when a user
    // types /tutorial .  This is because of the register_clcmd that we just put in.
 
    // So let's set the players health to 150. This is easy, and only takes one line.
    set_user_health(id, 150)
    // set_user_health is the command, don't mess with "id", and 150 is the amount
    // to set the players health to.
 
    // Now let's give the player 400 gravity (800 is normal).
    set_user_gravity(id,0.50)
    // This is a bit more tricky, but still simple. 
    // set_user_gravity is the command. Once again, don't mess with "id".
    // 0.50 is the amount of gravity to set them with.  It's at 0.50 because if we set
    // it to "1", that would be 800 gravity (normal gravity).  0.50 is half of 1 so it's
    // half of 800 gravity (400 gravity).
 
    // Now.. let's send them a message in chat.
    client_print(id, print_chat,"You just purchased some steroids, dude!")
    // client_print is the command, 'id'.. just leave it, 'print_chat'.. just leave it,
    // and what's in quotes, that's the message to display.
}
 
// Now, when a user types /tutorial, his health goes to 150, his gravity is set to 400, and
// a message is sent to him saying "You just purchased some steroids, dude!"
// This part I of II tutorial was meant to show you the basics.  In part II,
// I will show you some cooler things you can add and some more advanced things you 
// can do to spice up your new plugin.
 
// I hope you enjoyed reading this. If it helped you, it never hurts to leave me
// a good ole +karma on the forums.  It's more appreciated than you think!
// - Pvt. Smith [FSSF]
Part II - A little more advanced...But still simple.

Code:
/* Welcome! This is part II of II in "Beginner Tutorial" in my scripting tutorials series.
If you haven't read the last one, please read it.  I won't explain things that I already
explained in Part I.  I will only explain the new things that I introduce. */
 
// Here we go!
 
#include <amxmodx>
#include <cstrike>
#include <fun>
 
#define PLUGIN "Beginner Tutorial Part II"
#define VERSION "1.0"
#define AUTHOR "PvtSmithFSSF"
 
// These register new phrases called "plugin_on" and "price" for the plugin to use later.
new plugin_on
new price
 
public plugin_init() 
 
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_clcmd("say /tutorial", "steroids")
 
 
// This tells us what "plugin_on" and "price are. We registered the phrases so
// now we say what they are. We're going to make an ON/OFF cvar out of plugin_on,
// and we're going to make a cvar for the price of steroids (price).
plugin_on = register_cvar("amx_tutorial_plugin", "1")
price = register_cvar("amx_tutorial_price", "4000")
// register_cvar is the command to use. "amx_tutorial_plugin" or
// "amx_tutorial_price" is the cvar name.
// For example the cvar that is typed in game will be whatever is here. 
// "1" is what the default is set to for the cvar amx_tutorial_plugin. 
// We set it to 1 because we want the plugin to be on when the server starts, 
// don't we? The 4,000 on "amx_tutorial_price is the default cost of steroids.
}
 
public steroids(id)
{
// This is making a new phrase called 'money' that we can use later.
// What we're saying here is "the phrase 'money' means "Get a player's money".
// So whenever we have 'money' written in this section of the plugin, 
// it will get a player's money.
new money = cs_get_user_money(id)
// The reason we put it here and not with the others at the beginning of the plugin
// is because this line contains (id) in it, and that must be there. 
// You cannot put (id) where the others are, unfortunately.  So we put it here
// where we need it.
 
// Before we do anything, we want to make sure that plugin_on = 1.  
// In other words, we want to make sure the plugin is still on, by checking
// if the cvar is set to 1.
if (get_pcvar_num(plugin_on) == 1)
 
{
 // this is saying if a player's money is more than/equal to the price, we give them everything.
 if (money >= get_pcvar_num(price))
 {
 
  set_user_health(id, 150)
 
  set_user_gravity(id,0.50)
 
  client_print(id, print_chat,"You just purchased some steroids, dude!")
 }
 
 // and this is saying 'if money is was NOT equal to or greater than the price, 
 // we display them a message shown here.
 else
 {
  client_print(id, print_chat,"Not enough money. Go work out, loser!")
 }
 
 
 // This makes it cost money.  What we're doing here is saying
 // "set the user's money to:  money - price".  Now remember, since we registered
 // the new phrase 'money', it now gets a players current money amount. Also, we
 // set "price" to what this will cost.
 // So what this will do is actually get the player's money and subtract whatever
 // the admin has the cvar set to, making it cost whatever the cvar is set to.
 cs_set_user_money(id, money - get_pcvar_num(price))
}
// Yes, the "if (plugin_on == 1)" function needs its own {'s and }'s because it's saying
// "If plugin_on = 1, than do 'this'"
 
 
// I hope you learned a lot.  PM me on AlliedMods for questions or extra help.
// If it helped you, it never hurts to leave me a good ole +karma on the forums.  
// It's more appreciated than you think!
// - Pvt. Smith [FSSF]

Last edited by PvtSmithFSSF; 11-10-2008 at 08:37.
PvtSmithFSSF is offline