Catalog News Guides Community For contributors
Everything for CS 1.6 / CSS / CS:GO servers - Plugins | Builds | Models | Maps » Articles » Pawn from Scratch? Is it really possible to write your own server plugin Week 4

Pawn from Scratch? Is it really possible to write your own server plugin Week 4

28.04.2023, 19:32adminViews: 290Comments: 3
Pawn from Scratch? Is it really possible to write your own server plugin Week 4

About this content

Pawn с Нуля? реально ли написать свой плагин для сервера Неделя 4

Week 4: Functions and Multidimensional Arrays

  1. Functions
  • What are functions and why are they needed
  • How to declare and call functions
  • How to pass arguments to functions
  • What is a function's return value

Example of working with functions:

main()

{

    new x = 5;

    new y = 10;

    new z = add(x, y); // Вызов функции add

 

    print(z);

}

 

add(num1, num2) // Definition of the add function

{

    new result = num1 + num2;

    return result; // Возвращаем сумму num1 и num2

}

Explanation:

  • add(num1, num2) - declaration of the add function, which takes two arguments
  • new result = num1 + num2 - calculating the sum of num1 and num2 and saving it in the result variable
  • return result - returning the result of the function's execution
  1. Multidimensional Arrays
  • What are multidimensional arrays and why are they needed
  • How to declare and use multidimensional arrays

Example of working with multidimensional arrays:

main()

{

    new matrix[3][3]; // Объявляем двумерный массив размером 3x3

    for(new i = 0; i < 3; i++)

    {

        for(new j = 0; j < 3; j++)

        {

            matrix[i][j] = i + j; // Присваиваем каждому элементу массива значение i+j

        }

    }

 

        for(new i = 0; i < 3; i++)

    {

        for(new j = 0; j < 3; j++)

        {

            print(matrix[i][j]); // Выводим каждый элемент массива на экран

        }

    }

}

Explanation:

  • new matrix[3][3] - declaration of a two-dimensional array of size 3x3
  • matrix[i][j] = i + j - assigning the value i+j to each array element
  • print(matrix[i][j]) - displaying each array element on the screen

These are just examples of what you can learn over the course of a week, and you can study these concepts in more detail and apply them in more complex programs. Good luck!

 And now, most importantly, the first plugin for Counter Strike

#include < amxmodx >

#include < amxmisc >

#include < hamsandwich >

 

public plugin_init()

{

    register_plugin("Simple Plugin", "1.0", "Your Name");

    register_clcmd("hello", "Say hello to the player", "Syntax: hello", "1", "z");

    register_event("Round_Start", "OnRoundStart", "a", "1=0");

}

 

public OnRoundStart()

{

    client_print(0, print_chat, "Round started!");

}

 

public plugin_precache()

{

    precache_model("models/player/terror/terror.mdl");

    precache_sound("weapons/ak47-1.wav");

    precache_generic("sprites/smoke.spr");

}

 

public client_cmd(id, cmd[])

{

    if(!strcmp(cmd, "hello", true))

    {

        client_print(id, print_chat, "Hello, player!");

        return PLUGIN_HANDLED;

    }

        return PLUGIN_CONTINUE;

}

This plugin example registers several functions that can be used in Counter-Strike:

  • plugin_init() - The plugin initialization function, where you can register commands and events.
  • register_plugin() - The function for registering the plugin; it accepts the plugin name, version, and author.
  • register_clcmd() - The function for registering client commands that players can invoke in chat. It accepts the command name, command description, and other parameters.
  • register_event() - The function for registering game events, such as the start of a round. It accepts the event name, the event handler function, and other parameters.
  • OnRoundStart() - The function that is called when a round starts. In this case, it simply displays a message in chat.
  • plugin_precache() - The function for precaching models, sounds, and other resources on the server.
  • precache_model(), precache_sound(), precache_generic() - Functions for precaching models, sounds, and other resources on the server.
  • client_cmd() - The function that is called when a player enters a client command in chat. In this case, it checks whether the command "hello" was entered and displays a message in chat.

The plugin example is quite simple and demonstrates Pawn's basic capabilities for working with a Counter-Strike server. Of course, depending on the specific task, the plugin can be more complex and use other functions and libraries.




Similar content

Comments (3)

Add comment

Leave a comment

  1. admin
    admin
    28 April 2023 23:32

    Надеюсь мне стоит продолжать ? жду комменов 

    1. Zaur
      Zaur
      2 May 2024 15:16

      Да, стоит! Жду новых уроков!

      1. m2mix
        m2mix
        12 September 2024 04:18

         Заур постараемся выпустить ещё уроки, просто времени очень мало

New content by email

Subscription with email confirmation. No more than one email per day. Unsubscribe via the link in any email.

Join the community

Register · Reset password