[TUTORIAL] How to create a command - DarkPlaces engine C programming - Printable Version +- Xonotic Forums (https://forums.xonotic.org) +-- Forum: Creating & Contributing (https://forums.xonotic.org/forumdisplay.php?fid=10) +--- Forum: Xonotic - Development (https://forums.xonotic.org/forumdisplay.php?fid=12) +--- Thread: [TUTORIAL] How to create a command - DarkPlaces engine C programming (/showthread.php?tid=8531) |
How to create a command - DarkPlaces engine C programming - LegendGuard - 03-27-2021 Hello, all! It's the first time I've touched engine code to test something simple. IMPORTANT NOTE: only modifies engine part. 1. Open a file called console.c in xonotic/darkplaces folder 2. Write the following in the line 842 (NOTE: This line is specific, if you see something not empty, don't do. The code may change in some time due to the development, so don't write inside the functions, write it outside the functions) Code: //LegendGuard first time using engine code 27-03-2021 3. Write the following line to call the command function in the line 917 more or less where says "// register our commands": Code: Cmd_AddCommand ("hello", Con_Hello_f, "output a hello message"); 4. Save console.c file and go to console MSYS2 (as I use Windows) 5. In the console, while you're in xonotic/darkplaces directory, write and execute make sdl-release (optionally, you can use ./all compile -r when you're in xonotic directory but IT'S NOT RECOMMENDED, since it compiles all contents and is slow to check the results of your code in the engine) NOTE: about make sdl-release = xonotic-sdl sv-release = xonotic-dedicated You can compile graphical with glx or sdl interface or non graphical dedicated good for servers without a windowing system. There are differences: make sdl-release uses sdl2-config (in my system is version 2.0.12) (uses -ljpeg) - USE THIS COMMAND IN xonotic/darkplaces DIRECTORY - ./all compile sdl uses xonotic/misc/builddeps/win64/sdl/bin/sdl2-config (version 2.0.10) (doesn't use -ljpeg) - USE THIS COMMAND IN xonotic DIRECTORY - You can see more info in the makefile 6. After compiled successfully, go to xonotic directory and run the game with ./all run 7. Press Shift + Esc, type hello and ENJOY!!! RE: How to create a command - DarkPlaces engine C programming - LegendGuard - 03-31-2021 In this section, it will show you how to develop a Basic Calculator command: There are things to keep in mind:
Requires having learned something from it, anyway, let's get started! 1. Open a file called console.c in xonotic/darkplaces folder 2. Write the following in the line 843 (NOTE: This line is specific, if you see something not empty, don't do. The code may change in some time due to the development, so don't write inside the functions, write it outside the functions) Code: /* 3. Write the following line to call the command function in the line 1019 more or less where says "// register our commands" inside "Con_Init" function: Code: Cmd_AddCommand ("calc", Con_Calc_f, "basic calculator, input parameters to get a result: [num1] [operator] [num2]"); 4. Save console.c file and go to console MSYS2 (as I use Windows) 5. In the console, while you're in xonotic/darkplaces directory, write and execute make sdl-release (optionally, you can use ./all compile -r when you're in xonotic directory but IT'S NOT RECOMMENDED, since it compiles all contents and is slow to check the results of your code in the engine) NOTE: about make sdl-release = xonotic-sdl sv-release = xonotic-dedicated You can compile graphical with glx or sdl interface or non graphical dedicated good for servers without a windowing system. There are differences: make sdl-release uses sdl2-config (in my system is version 2.0.12) (uses -ljpeg) - USE THIS COMMAND IN xonotic/darkplaces DIRECTORY - ./all compile sdl uses xonotic/misc/builddeps/win64/sdl/bin/sdl2-config (version 2.0.10) (doesn't use -ljpeg) - USE THIS COMMAND IN xonotic DIRECTORY - You can see more info in the makefile 6. After compiled successfully, go to xonotic directory and run the game with ./all run 7. Press Shift + Esc, use calc command and ENJOY!! |