Pawn from Scratch? Is it really possible to write your own server plugin ( 1 full-fledged plugin )
About this content

We've already learned how to write a simple plugin, and now it's time to make something more complex and simple at the same time.
Let's write a plugin that adds a tag to chat based on an access flag—a fairly useful and simple plugin, and most importantly, FREE
We'll have a VIP tag for us and our buddies, and DOG for those who have annoyed us )
Code explanation:
- At the beginning, we include two header files -
amxmodxиamxmisc, which are needed for the plugin to work. - Then we declare two constants -
TAG_VIPиTAG_DOG, which store the corresponding tags. - Next, we register the plugin and the command
/mytags, which will display the list of the player's available tags. - In the function
cmdTagswe declare several local variables:szTags- a string to which the available tags will be added,szTag- a temporary buffer for retrieving each tag from the config. - Using the function
GetConfigStringwe get the list of available tags from the config and add each one to the stringszTags. - Then we get the player's access flags using the function
get_user_flags. - If the player has the flag
ADMIN_J, then we display a message about it in the console and add the VIP tag to the player's chat. - Similarly, if the player has the flag
ADMIN_I, then we display
Don't forget to change the flags and names... After all, this is a lesson, not just copy-pasting my code!!!
Write about the results in the comments, and for convenience, let's make things a little more complicated: I don't like having to recompile the plugin all the time, so let's move everything into a config.
To do this, we need to make some changes to the plugin.
- We need to add a new configuration file "chatvip.cfg" to the "configs" directory.
- In the plugin code, we need to replace hard-coded values with values read from the configuration file.
- To read values from the configuration file, we need to use functions from the "file" library.
- We also need to check that the values were read successfully from the configuration file.
Here's what the updated plugin code will look like:
After these changes, you can change the values of the variables "tagVIP" and "tagDOG" in the file "configs/chatvip.cfg", without needing to change
Compile it and give it a try. Well, it's really easy and simple; I hope it worked for everyone, and don't forget to leave comments—I look forward to hearing from you.
We can make life a little harder for our Dogs on the server and add a sound. I'll add a barking sound; they'll bark as soon as they start typing, so I'll know whether I should read the chat or not...
Here's the updated plugin code, which adds a tag to a player's chat if they have a specific access flag and plays a sound when a specific tag is typed in chat:
Updated configuration file "configs/chatvip.cfg":
In this version of the plugin, if a player types the tag "i", then the sound /cstrike/music/dog.mp3 will play every time someone types the tag "i" in chat.






Comments (1)