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 3

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

28.04.2023, 19:12adminViews: 95Comments: 0
Pawn from Scratch? Is it really possible to write your own server plugin Week 3

About this content

Pawn с Нуля? реально ли написать свой плагин для сервера Неделя 3
Week 3: Control Structures and Files

  1. Control Structures
  • What control structures are and why they are needed
  • How to use the conditional operators if, else, and switch
  • How to use the for, while, and do-while loops

Example of using conditional operators and loops:

main()

{

    new x = 10;

 

    if(x > 5)

    {

        print("x больше 5");

    }

        else

    {

        print("x меньше или равен 5");

    }

 

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

    {

        print(i);

    }

 

        new y = 0;

        while(y < 5)

    {

        print(y);

        y++;

    }

 

        new z = 0;

        do

    {

        print(z);

        z++;

    } while(z < 5);

}

Explanation:

  • if(x > 5) - the if conditional operator for checking the value of variable x
  • else - the keyword for executing an alternative block of code
  • for(new i = 0; i < 5; i++) - the for loop for executing code 5 times
  • while(y < 5) - the while loop for executing code as long as the condition is true
  • do-while - the do-while loop for executing code at least once, even if the condition is false
  1. Working with Files
  • How to open and close files
  • How to write and read data from files

Example of working with files:

main()

{

    new file = fopen("test.txt", "w"); // Открываем файл для записи

    if(file != INVALID_HANDLE) // Проверяем, удалось ли открыть файл

    {

        fwrite(file, "Hello, world!", sizeof("Hello, world!")); // Записываем строку в файл

        fclose(file); // Закрываем файл

    }

        else

    {

        print("Ошибка открытия файла");

    }

 

        new readfile[50];

        file = fopen("test.txt", "r"); // Open the file for reading

        if(file != INVALID_HANDLE) // Check whether the file was opened successfully

    {

        fgets(readfile, sizeof(readfile), file); // Считываем строку из файла

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

        fclose(file); // Закрываем файл

    }

        else

    {

        print("Ошибка открытия файла");

    }

}

Explanation:

  • fopen("test.txt", "w") - opening the test.txt file for writing
  • fwrite(file, "Hello, world!", sizeof("Hello, world!")) - writing a string to a file
  • `fclose(file



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