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 2

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

28.04.2023, 19:09adminViews: 73Comments: 0
Pawn from Scratch? Is it really possible to write your own server plugin Week 2

About this content

Pawn с Нуля? реально ли написать свой плагин для сервера Неделя 2
Week 2: Functions and arrays

  1. Functions
  • What functions are and why they are needed
  • How to declare and call functions
  • Function return values

Example of working with functions:

main()

{

    new result = add(2, 3);

    print(result);

}

add(num1, num2)

{

    new sum = num1 + num2;

    return sum;

}


Explanation:

  • add() - declaration of a function with two arguments
  • new sum - declaration of a variable inside a function
  • return - keyword for returning a value from a function
  1. Arrays
  • What arrays are and how they work
  • How to declare and use arrays

Example of working with arrays:

main()

{

    new array[5]; // Объявляем массив из 5 элементов

    for(new i = 0; i < sizeof(array); i++) // Заполняем массив значениями

    {

        array[i] = i + 1;

    }

 

        print("Array before changes:");

        for(new i = 0; i < sizeof(array); i++) // Display the array values before changes

    {

        print(array[i]);

    }

 

        array[2] = 10; // Change the value of the array element with index 2

 

        print("Array after changes:");

        for(new i = 0; i < sizeof(array); i++) // Display the array values after changes

    {

        print(array[i]);

    }

}

Explanation:

  • new array[5] - declaration of an array with 5 elements
  • for(new i = 0; i < sizeof(array); i++) - loop for filling and displaying array values
  • array[i] = i + 1 - assigning a value to the array element with index i
  • array[2] = 10 - changing the value of the array element with index 2
  1. Strings
  • What strings are and how they work
  • How to declare and use strings

Example of working with strings:

main()

{

    new str[50] = "Hello, world!"; // Объявляем строку и присваиваем ей значение

    print(str); // Выводим строку на экран

 

    format(str, sizeof(str), "Значение числа PI: %.2f", 3.14); // Форматируем строку с помощью функции format()

    print(str); // Выводим отформатированную строку на экран

}

Explanation:

  • new str[50] - declaration of a string and allocation of 50 characters for it


Similar content

Comments (0)

Add comment

Leave a comment

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