Здравствуйте, уважаемый посетитель. К сожалению, Вы не были распознаны форумом, как зарегистрированный пользователь. Для полноценного использования возможностей нашего форума вам необходимо зарегистрироваться. Если вы уже зарегистрированы на форуме, то вам необходимо пройти авторизацию, используя Ваш логин и пароль. Зарегистрированные пользователи получают возможность просматривать закрытые разделы форума, а также возможность общения на нашем форуме.
// 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. */
// 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] __________________
new money = cs_get_user_money(id) it stores the value in the integer not get it every time. Quote: Originally Posted by PvtSmithFSSF // 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.
if (get_pcvar_num(plugin_on) == 1) same for price. To use them instead the way that you did you would have to do this in plugin_init Code: register_cvar("amx_tutorial_plugin", "1") register_cvar("amx_tutorial_price", "4000") plugin_on = get_cvar_num("amx_tutorial_plugin") price = get_cvar_num("amx_tutorial_price")
cs_set_user_money(id, money - get_pcvar_num(price)) and upon better inspection of the code since the mass comments overwhelmed everything, I would suggest that you first check if the user has enough money to afford the steroids before setting the health and gravity. Also rather than just arbitrarily setting heath to 150 I would instead add 50 health since someone could use the command just before dieing to reset health to max each time. Code: public steroids(id) { if ( !get_pcvar_num(plugin_on) ) { /* ! operator means false which equates to 0 in numerical sense so this equates to if ( get_pcvar_num(plugin_on) == 0 ) */ client_print(id, print_chat, "Steroids currently disabled"); return; //ends the function on the spot } new money = cs_get_user_money(id); new cost = get_pcvar_num(price); //rather than calling get_pcvar_num 3 times, store it to a variable if ( money >= cost ) //run a check on if user has enough cach { cs_set_user_money(id, money - cost); set_user_health(id, ( get_user_health(id)+50 ) ); //sets user health 50 points greater tehn current health incase they have more or less than starting 100 set_user_gravity(id, 0.50 ); client_print(id, print_chat, "You just purchased some steroids, dude!"); } else //if they didn't have enough cash display a message stating how much more they need client_print(id, print_chat, "Sorry you need %d more cash to afford steroids", cost-money); }