[TUT] AMXX Scripting / What Starters Must Know.
Dec 31, 2016 13:14:05 GMT
zmd94, P!KaChu~, and 3 more like this
Post by DoNii on Dec 31, 2016 13:14:05 GMT
Hey, we are back at it again, AMXX scripting. Instead of jumping straight to the Request/Scripting section, read this so you can start doing things on your own. If you don't want to read it all, don't bother asking.
At first you need to have a deep understanding on variables, you can learn about them here. So probably right now, your question is "WHY?", "Why do we have to learn about variables" ?
Because :
Example :
Example :
I think this is enough for variables, let's step ahead. Now, let's take a look at NATIVES.
What are natives ?
You can find natives by visiting the AMXX Doc here or in the includes folder in your compiler.
Let's start with register_plugin native.
Syntax :
Example :
Or ..
Native is_user_alive
Syntax :
Example :
Native get_user_flags
Syntax :
Example :
Native is_user_connected
Syntax :
Example :
Native get_user_name
Syntax :
Example :
Native get_user_ip
Syntax :
Example :
Native get_user_authid
Syntax :
Example :
At first you need to have a deep understanding on variables, you can learn about them here. So probably right now, your question is "WHY?", "Why do we have to learn about variables" ?
Because :
- Some natives, need a variable to store the information, like the native get_user_name
Example :
#include <amxmodx>
public plugin_init( )
{
register_plugin( "Test", "1.0", "DoNii" )
register_clcmd("say /saymyname", "function_show")
}
public function_show( id )
{
new name[ 32 ] // here we create a variable in which we will store our name
get_user_name( id, name, charsmax( name ) )
// Note - get_user_name
// id -> the player index, it picks the player that used the /saymyname function
// name -> the variable that we store our name in (you can re-name it to whatever you want)
// charsmax(name) -> since it's zero based, just you need to do charsmax(variable_name) or sizeof variable_name - 1
}
- Other than that, you might want to specify price of something in a easier way rather than scrolling down in a 3000 line code just to change its price.
Example :
#include <amxmodx>
#include <fun>
#include <cstrike>
new item_price = 50 // We create a global variable so we can use it in multiple functions
// Note - item_price [ global variable ]
// new - you create variables by typing "new" before the name
// item_price - variables name
// 50 - the data the variable is storing
public plugin_init( )
{
register_plugin( "Test", "1.0", "DoNii" )
register_clcmd("say /buygodmode", "buy_godmode_function")
}
public buy_godmode_function( id )
{
if( cs_get_user_money( id ) >= item_price ) // If user's money is 50 or greater
{
cs_set_user_money( id , cs_get_user_money( id ) - item_price ) // take $50 from him
set_user_godmode( id , 1 ) // give him godmode , note : 1 - set godmode , 0 - unset godmode
}
}
I think this is enough for variables, let's step ahead. Now, let's take a look at NATIVES.
What are natives ?
Natives are functions which allow users to do multiple things, such as :
- Get user's name
- Slap/Kick/Ban/Kill him
- Change his model
- Change the map
etc...
- Get user's name
- Slap/Kick/Ban/Kill him
- Change his model
- Change the map
etc...
You can find natives by visiting the AMXX Doc here or in the includes folder in your compiler.
Let's start with register_plugin native.
It registers your plugin so when you type amx_plugins it will be there.
Syntax :
register_plugin(const plugin_name[],const version[],const author[]);
Note - register_plugin
const plugin_name[] - in this string you can specify your plugins name
const version[] - here you set the version (1.0, 1.1..)
const author[] - author's name
Example :
#include <amxmodx>
public plugin_init( )
{
register_plugin( "My First Plugin" , "1.0" , "DoNii" )
}
Or ..
#include <amxmodx>
#define PLUGIN "My First Plugin"
#define VERSION "1.0"
#define AUTHOR "DoNii"
public plugin_init( )
{
register_plugin( PLUGIN, VERSION, AUTHOR )
}
Native is_user_alive
This native returns 1 if user is alive and 0 if he's not
Syntax :
is_user_alive(index)
// Note - is_user_alive
// index - player's index
Example :
#include <amxmodx>
#include <hamsandwich>
public plugin_init( )
{
register_plugin( "Test" , "1.0" , "DoNii" )
RegisterHam( Ham_Spawn , "player" , "fw_HamSpawnPost" , 1 )
}
public fw_HamSpawnPost( id )
{
if( is_user_alive( id ) ) { // if user is alive
client_print( id , print_chat , "You're Alive !!" ) // send him a message saying "you're alive"
}
}
Native get_user_flags
It checks if user has specified flags.
Syntax :
get_user_flags(index,id=0);
// Note - get_user_flags
// index - player index
// id=0 - if you want to show server flags set it 0 (zero)
Example :
#include <amxmodx>
#include <hamsandwich>
public plugin_init( )
{
register_plugin( "Test" , "1.0" , "DoNii" )
RegisterHam( Ham_Spawn , "player" , "fw_HamSpawnPost" , 1 )
}
public fw_HamSpawnPost( id )
{
if( is_user_alive( id ) && get_user_flags( id ) & ADMIN_KICK )
{
client_print( id , print_chat , "You're Alive And You're An Admin !" )
}
else if( ( !is_user_alive( id ) && get_user_flags( id ) & ADMIN_KICK ) )
{
client_print( id , print_chat , "You're Dead And You're An Admin !" )
}
}
Native is_user_connected
This native checks if defined user is connected (in the server)
Syntax :
is_user_connected(index)
// Note - is_user_connected
// index - player index
Example :
#include <amxmodx>
#include <hamsandwich>
public plugin_init( )
{
register_plugin( "Test" , "1.0" , "DoNii" )
RegisterHam( Ham_Spawn , "player" , "fw_HamSpawnPost" , 1 )
}
public fw_HamSpawnPost( id )
{
if( is_user_connected( id ) ) { // if player is connected
client_print( id , print_chat , "You're Connected In Our Server , Thank You For Playing Here" )
}
else { // else if not connected
new disconnected_user[32];
get_user_name(id, disconnected_user, charsmax(disconnected_user))
client_print( 0 , print_chat , "Player %s Left The Server" , disconnected_user )
}
}
Native get_user_name
This native returns Player Name.
Syntax :
get_user_name(index,name[],len)
// Note - get_user_name
// index - player index
// name[] - the string (buffer) we will store our name in
// len - size of buffer
Example :
#include <amxmodx>
public plugin_init( )
{
register_plugin( "Test" , "1.0" , "DoNii" )
register_clcmd( "say /myname" , "show_player_name" )
}
public show_player_name( id )
{
new name[ 32 ] // the buffer that we will store our name in, it has to be 32
get_user_name( id , name , charsmax( name ) ) // get the player name
client_print( id , print_chat, "Your Name Is : %s" , name ) // print the name
}
Native get_user_ip
This native returns Player IP ( Internet Protocol )
Syntax :
get_user_ip(index,ip[],len, without_port = 0);
// Note - get_user_ip
// index - player index
// ip[] - buffer we will store player IP in
// len - buffer length
// without_port = 0 - if you want to show port you need to set it to 1 , otherwise 0 or simply leave it blank
Example :
#include <amxmodx>
public plugin_init( )
{
register_plugin( "Test" , "1.0" , "DoNii" )
register_clcmd( "say /myip" , "show_player_ip" )
}
public show_player_ip( id )
{
new ip[ 16 ] // the buffer that we will store our IP in
get_user_ip( id , ip , charsmax( ip ) ) // get the player IP
client_print( id , print_chat , "Your IP is %s" , ip ) // print the IP
}
Native get_user_authid
This native returns Player SteamID
Syntax :
get_user_authid(index, authid[], len);
// Note - get_user_authid
// index - player index
// authid[] - buffer that we will store our SteamID
// len - buffer length
Example :
#include <amxmodx>
public plugin_init( )
{
register_plugin( "Test" , "1.0" , "DoNii" )
register_clcmd( "say /mysteamid" , "show_player_steamid" )
}
public show_player_steamid( id )
{
new authid[ 32 ] // create a buffer
get_user_authid( id , authid , charsmax( authid ) ) // get the player SteamID
client_print( id , print_chat , "Your SteamID is %s" , authid ) // print the SteamID
}