AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Trash (https://forums.alliedmods.net/forumdisplay.php?f=22)
-   -   Amx Mod X scripting tutorial (https://forums.alliedmods.net/showthread.php?t=6923)

LynX 10-19-2004 09:54

Amx Mod X scripting tutorial
 
Well, this is my tutorial on scripting plugins for Amx Mod X.
I made this tutorial to make a life easier for n00bs who are
just getting used to small and amx mod x. Now, let's get going:


To make an plugin, just create a new document (preferably notepad or wordpad document),
and change his extension to .sma file. That's it. After that, open i. Windows will ask you
which program to use for opening it. You choose Notepad or Wordpad ( you can choose Word,
or any other text writing program, thought).After that, you get a textual window opened
(don't worry, it's sill in Graphical User Interface).

The first thing you should want to do in your plugin is to make an copyright/
credits/guide on using your plugin, etc.

Now, that function can be called by two ways. First is used exceptionaly for this. You write it like
this : */

Now, it should look like this:

-----------------------

*/
blah, blah, blah
/*

-----------------------


Notice that you close it with this : /*

Also notice that between these two signs you CAN write anything you want.
It doesn't affect on plugin and it will be "jumped" by compiler. Alright, after
your "I-don't-know-what-and-I-don't-want-to-know", the most important part of plugin comes
to your service. Now, after that YOU MUST include modules that your plugin will be pulling off
functions that your task ingame works perfectly. It should look like this:



-----------------------

*/
blah, blah, blah
/*

#include <amxmodx>
#include <fun>
#include <cstrike>

-----------------------



For this example, I've chosen to include amx mod x module ( that's the main one,
you should ALWAYS include it). I've also chosen to include fun and cstrike module.
Why?
Because, fun module has capatibilty of changing health, armor, speed, and giving you
noclip and godmode. In this tutorial plugin, I will make godmode on player.
I've chosen cstrike module, also why? Because, he has some functions that I could use,
for example, I will change player's model, and that's function is usefull in this example
plugin. And if you want to know which modules to include, you should open scripting/include
folder of Amx Mod X directory. You should open them all in your searching for functions
that you would use in plugin. You must have an idea what your plugin should do, or, it
could get nasty when searching throught all that functions.

Now, the next thing in plugin you should write is "public plugin_init()" function.
It's necesarry to get your plugin working. You can put it at begining or ending of plugin.
We'll put it forward this time. And, there is one more thing. When making that function, no,
in fact, all functions get opened by braces. For your safety of your nerves, you should always
make them like this in example. And one more function that is useful is "//"
The function of this is similar as "*/ ; /*". But, with this one
you can directly post comments on line of plugin:



------------------------

*/
bljuh, bljuh, bljuh
/*

#include <amxmodx>
#include <fun>
#include <cstrike>


public plugin_init() //this function calls another functions inside of it, just continue looking

{ // without this, your functions won't work

register_plugin("Example_tut_plugin","1.0","L enux, dish washer") // first function is for name of plugin, second for version of plugin, and third one for plugin's author name
register_clcmd("Bind_this_sentence","model_hp _change") // first function is that client will write in console, or bind it to key, and second is the function you make, continue looking

} // you close it with this brace

-------------------------


Just remember, when putting braces, the begining and ending brace should be "in same level",
so not that first brace is in first position of line, and second brace on downer line is at fifth position.
Also, the functions between braces should begin exactly on same position as "l" of "plugin_init()",well, at least I do that, and every plugin compiles

Also, then next thing you should start with is writing function of "register_clcmd" function.
Now, let's get to it:



-------------------------

*/
bljuh, bljuh, bljuh
/*

#include <amxmodx>
#include <fun>
#include <cstrike>


public plugin_init() //this function calls another functions inside of it, just continue looking

{ // without this, your functions won't work

register_plugin("Example_tut_plugin","1.0","L enux, dish washer") // first function is for name of plugin, second for version of plugin, and third one for plugin's author name
register_clcmd("Bind_this_sentence","model_hp _change") // first function is that client will write in console, or bind it to key, and second is the function you make, continue looking

} // you close it with this brace

public model_hp_change // notice that you can put anything on place of "model_hp_change" function

{ // braces!

cs_set_user_model(id,"models/player/super_tutorial_man.mdl") // this function is pulled from cstrike module, you should put your destination in "" signs, in this example, destination is bogus
set_user_health(id,240) // function called from fun module, notice that 240 is maximum hp that will show correctly in Half-Life

return PLUGIN_HANDLED // this function should be always leveled below functions in same spot of line below them

} // kh, kh, brace!

-------------------------

This would be an ending of first of three tutorials for Amx Mod X I will write.
Remember that you can also make other functions and put it on same client command (clcmd), like this:


--------------
register_clcmd("C4","donut_function")
register_clcmd("C4","donut_explosion")
--------------


Ok, so, this would be it. Any questions?[/small]

Puntje 10-19-2004 10:41

just 1:

can i have a cookie?

devicenull 10-19-2004 14:48

A few..
This is going to confuse more people then it will help.
Why.. there's a few errors there.. comments are /* comment */ for one
Comments are not functions either
Your totally wrong about needing braces either
Code:
public plugin_init() register_plugin(...)
is perfectly valid. Braces are only needed with multiple line functions

cs_set_user_model has the wrong syntax (it takes a model name, like "gign" , not a path to a model) and wouldn't work anyway (No precache)

public model_hp_change needs () on the end of it, so it becomes
public model_hp_change()

register_clcmd("C4","donut_function")
register_clcmd("C4","donut_explosion")
... Why would you ever do something like that?

Whats wrong with all the ones linked to here?http://forums.alliedmods.net/showthread.php?p=42838

Votorx 10-20-2004 07:09

Lmao, I had a hard time reading that and I know how to script. BTW, public plugin_init() is an exclusive function for amxmodx which is ran on server activation (not sure if you added that)

Quote:

Ok, so, this would be it. Any questions?
Err, that's just the tip of the iceberg buddy.

LynX 10-20-2004 10:02

Oops, sorry. I didn't knew I made such much mistakes :shock: . Thanks for pointing that mistakes. I guess learning one day to script doesn't helps. :?

Isobold 10-21-2004 08:51

plz fix these errors at least in your first post, so noobs will not have to search your faults :)

Ronkkrop 11-29-2004 08:59

Quote:

register_clcmd("C4","donut_function")
register_clcmd("C4","donut_explosion")
damn you Americans :P Its Doughnut, not donut

LynX 11-29-2004 16:07

I'm not american. Lol, it was funny to see that this topic got so responses. I'm gonna write new tutorial, cause I'm pretty much expirienced with AMXX now. :oops:

Rolnaaba 07-09-2006 23:37

Re: Amx Mod X scripting tutorial
 
If you think LynX has a stupid sig, paste this in your sig
lol just playin, but i going to have to agree with other on this
this will probably confuse newbs more than it will help them but good try ;)

Xanimos 07-10-2006 08:54

Re: Amx Mod X scripting tutorial
 
Wow, you bumped a two year post. GJ.


All times are GMT -4. The time now is 22:15.

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