Advertisement
MasamuneDate

[English] COD:MW Extended Scripting Tutorial by TYR / MasamuneDate ( codmod.inc )

May 12th, 2022 (edited)
754
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 101 Basic, HOW TO CODE COD CLASS / PERK - By TYR or you can call me MasamuneDate
  2.  
  3. *This is a translated version of the original guide i wrote on my native language ( Indonesian ), if you are a Indonesian, you can check the guide i wrote here : https://pastebin.com/CWS8MFni
  4.  
  5. Steam : https://steamcommunity.com/id/MasamuneDate901/
  6. Github : https://github.com/MasamuneDate99/Cs-1.6-COD-MW-Mod ( Your toy box )
  7. Discord : TYR#1759
  8.  
  9. *DISCLAIMER : This guide is create based on MY personal experience working with AMXX Studio and PAWN Language for the New Codmod. This guide is created for beginner, that doesn''t even understand programming at all, and to help those who have knowledge about programming to write a script for new class or perk for the mod.
  10.  
  11. **DISCLAIMER : The first time myself become a mod developer for Cod mod, i have zero knowledge or clue on what im doing nor zero experience on programming. I learn everything by googling, or browisng forum like allied modder and amxx.pl, honorable mention to my old mentor Eki, that help me a lot with bugs and my question, and a lot of thanks from the amxx.pl forum that also help to answer or even solve my problems ! ( You can see it on the Class / Perk discussion section on this forum. )
  12.  
  13. ***Disclaimer : All plugin that exist on the github SHOULD be free plugin ( Pls reply or DM to me if i violated any intelectual property rights ( yeah my High School self is a little bit dumb about copyright ).
  14.  
  15. ****Disclaimer : This guide is not perfect nor bad. Its just a mediocore guide that i created using my limited knowledge of scripting and english. If you found any mistake or misleading please do forgive me and you can go to amxx.pl on Multilingual section and reply to me there.
  16.  
  17. //////////////////////////////////////////////////////////////////////////////////////////
  18. Update list ( Last Updated : 5/31/2022 ) :
  19. Update 6/6/2022
  20. - Added 2 new link for Readme !
  21. - Small Announcement : I''m cleaning my Github now. Estimate done UNKNOWN, should be more cleaner and tidy after I cleaned my repository.
  22.  
  23. Update 5/31/2022 ( Finally, translation are done ! )
  24. - Rework IV.K Include & Native Function + Codmod.inc
  25. - Chapter IV Advanced Lesson Done
  26. - Rename Debugging sub chapter into Debugging / Finding Error
  27.  
  28. Update 5/30/2022
  29. - Chapter IV Advanced Lesson WIP ( 9 / 12 Done )
  30. - Added 1 new sub-chapter for Advanced Lesson : Intelligence & Cod_inflict_damage
  31.  
  32. Update 5/25/2022
  33. - Chapter IV Advanced Lesson WIP ( 5 / 11 Done )
  34.  
  35. Update 5/20/2022
  36. - Chapter IV Advanced Lesson WIP ( IV.C WIP ) ( 3 / 11 Done )
  37.  
  38. Update 5/19/2022
  39. - Done Chapter III translation
  40.  
  41. Update 5/18/2022
  42. - Chapter II done translation
  43. - Chapter III 50% translation
  44. - Update readme content ( add CS 1.6 Wpn code link )
  45. - Add CS 1.6 Wpn Code on README
  46.  
  47. Update 5/15/2022 :
  48. - Chapter I done translate
  49.  
  50. Update 5/12/2022 :
  51. - Initial translation
  52. //////////////////////////////////////////////////////////////////////////////////////////
  53.  
  54. //////////////////////////////////////////////////////////////////////////////////////////
  55. README SECTION
  56. //////////////////////////////////////////////////////////////////////////////////////////
  57. READ THIS !
  58. /*
  59.     ENGLISH IS NOT MY NATIVE LANGUAGE, SO IF YOU SEE SOME WEIRD GRAMMAR / TRANSLATION FROM ME, IM SORRY, SINCE I TRANSLATE THIS BY MYSELF
  60. */
  61.  
  62. ** AMX Mod X Documentation                  : https://www.amxmodx.org/doc/
  63. ** AMX Mod X Plugin API Documentation       : https://www.amxmodx.org/api/
  64. ** CoD Mod Documentation                    : https://codmod_ozone.amxx.pl/cod ( Note this is a documentation for the old Cod. But almost all of the function still work the same as the new Cod, just a little bit different on name and the parameter. )
  65. ** CoD MW Github by TYR                     : https://github.com/MasamuneDate99/Cs-1.6-COD-MW-Mod
  66. ** AMXX Compiler.rar                        : https://drive.google.com/file/d/1tTk1vbOfLnrB6IE8IKUKrY8L_5WU4bxN/view?usp=sharing  ( Also available on the Github )
  67. ** AMXX                                     : https://drive.google.com/file/d/12E1Lhu2UReVOiX8kp1eMFBpOmV8qwYAn/view?usp=sharing
  68. ** Class Generator ( Should be usefull )    : https://amxx.pl/generator-klas/
  69. ** Translator                               : https://www.deepl.com/
  70. ** CS 1.6 Weapon Code                       : https://forums.alliedmods.net/archive/index.php/t-59003.html
  71. ** C/PAWN String Formatting                 : http://cplusplus.com/reference/ctime/strftime/
  72. ** AMXX Admin Flag                          : https://forums.alliedmods.net/showthread.php?t=314332
  73.  
  74. ** NOTE : If you still confused after reading the cod.inc documentation, just open the codmod.inc on a notepad. There are noted available there, you just need to translate it into english. Use https://deepl.com for a better translation.
  75. ** NOTE : If you see '' being used redundantly, its to avoid the syntax highlighting since i use '' for some cases. ( '' is used on PAWN along with "" )
  76. //////////////////////////////////////////////////////////////////////////////////////////
  77.  
  78. ** Table of Content
  79.     * For navigation, just search the keyword on the Table Of Content below. It should help a lot.
  80.     1. Basic Knowledge Scripting ( Very Basic )
  81.         I.A - Public Knowledge
  82.         I.B - Library & Dependency
  83.         I.C - Include
  84.         I.D - Compiler
  85.         I.E - Integrated Development Environment
  86.     2. Class Parameter
  87.         II.A - Data Types ( Number, Char, Boolean )
  88.         II.B - COD "Required" Parameter
  89.     3. Initializing Function & Enabling Task / Function
  90.         III.A - Function
  91.         III.B - Custom Task / Function
  92.         III.C - Initializing Function ( "Main" Function )
  93.         III.D - Enabling / Disabling Class & Perk
  94.     4. Advanced Lesson
  95.         IV.A - Random Number Generator
  96.         IV.B - Define + Function Part 2
  97.         IV.C - Logical Statement ( If, Else, And, Or )
  98.         IV.D - Loading Bar & Class Skill Function ( For Skill )
  99.         IV.E - Access Restriction
  100.         IV.F - Importing Custom Model & Sound ( W/ Precaching )
  101.         IV.G - Stat on Class & Perk + Get Stat Function     // Part of "Cod Function"
  102.         IV.H - Intelligence Damage & Cod_inflict_damage     // Part of "Cod Function"
  103.         IV.I - Giving & Taking Weapon + Get User Wpn        // Part of "Cod Function"
  104.         IV.J - "Porting" Plugin
  105.         IV.K - Include & Native Function + Codmod.inc ( The one that i regularly used )
  106.         IV.L - Debugging / Finding Error
  107.         IV.M - More ?
  108. ** End of Table of Content
  109.  
  110. I. Chapter I : Include
  111.     Welcome to the first section of the Guide ! First, lets see the note below, and after you read the note we can proceed into the first part of chapter one
  112.  
  113. I.A Public Knowledge
  114.     Counter Strike 1.6 modding is based on PAWN language. CS 1.6 Modding uses AMXX Studio IDE ( although you can use anything ), and PAWN language to execute the script that you create. PAWN language is very similar with C programming language, so if you have knowledge about C language, that''s a very good start.
  115.  
  116.     Before we begin our scripting journey, there are some things that i want to remind you. I have made it into several points.
  117. * When we create or naming a variable or function, make sure you named it clearly, don''t just randomly named like function a, variable b, or something like that. Named it clearly like function BonusDamage, or variable flag_validator, and etc. The purpose is to avoid confusion for you and somebody else when inspecting or learning the code.
  118. * Always end the line with semicolon ( ; ).
  119. * Never give space when naming things, use _ or something similiar. If you give space when naming things, example : function User Validator, the compiler will confuse with the Validator since its out of bound. Either seperate it with symbol like underscore, or capital letter.
  120. * Never and never ever you take someone else plugin and rename it as yourself. ( I have seen someone named "Fajar" just blatantly taking all of the perk and class and rename the author to him. Always keep the credit to original author, even tough it will be compiled and no one will know.
  121. * Pawn language used procedural system, which it will run your code from top to bottom.
  122.  
  123. I.B Library & Dependency
  124.     What is Library and Dependency ? Why is it so important on ouy scripting and modding activity ? Library is a compilation of function or action for a specific task, that can be called when we needed. Dependency is a Library that we imported and used in our scripting project, meaning that we need that library of function to execute our script. ( Forgive me for my bad explanation lol )
  125.  
  126. I.C Include
  127.     We already know about Library and Dependency from the above sub-chapter, now we will learn a bit on how to importing a library into our script code. To import a Library, we need to "Include" it first on our script.
  128.  
  129. /*  Include format
  130. #include <library name>
  131. // Note : We need to use the symbol # for the include command.
  132. */ End of Include format
  133.  
  134.     Now, we already know how to import a library into our script code. The next part is to figuring out how do we know the library name, which library we need in our project, and is there any consequence when we import a library which we never used ? To figuring out the library name, you can go to your AMXX Compiler folder. There should be a folder named "include" inside, open that folder, and you will see a bunch of file with .inc extension. All of that file is the "Library" named that you need to type in the script ( The name is CASE SENSITIVE ). If you need another library that you found on the internet or you created yourself, just put the .inc file inside the include folder, and you''re good to go. Next, if you need to know which library you need on your script, you can go into the include folder, and see the .inc file ( Just open it with a notepad, there should be the list of function ( with note usually ) ), or you can go to the documentation of the library ( if exist ). You will also noticed if you try to compiled a script that missing a required library, it will shown an error on the compiler. Lastly, what will happen if you imported a library that you don''t use ? It doesn''t do anything to be honest. It only add a "Code Smell" ( you can google it ).
  135.  
  136. I. D Compiler
  137.     Now you''re wondering what is a compiler ? Why do we need a compiler ? Compiler is a "Translator" that translate your script code into a language that the machine or computer knows. Without a compiler, the script that we wrote will be meaningless, since the computer doesn''t understand human language. Also, by compiling our script, it will obscuring our source code into a format that cannot be undo into the original source code, making it save from piracy ( if you know what i mean ). You can go to README section on the top to see the Github or the google drive link that i provide.
  138.  
  139. I. E Integrated Development Environment
  140.     The "Official" IDE for AMXX Scripting is AMXX Studio. But, to be honest, you can do the scripting with any IDE or text editor you can found. For example, you can write your AMXX source code on a Notepad, or a Notepad++ it doesn''t make any difference. The only "minor" problem is without a specific IDE, you may not get syntax highlighting, auto complete function, etc. If you ask my preference, i use Visual Studio Code for most my scripting. Visual Studio has marketplace extension for PAWN language.
  141.  
  142. II. Chapter II : Class Parameter
  143.     On this chapter, we will talk about the "Required" parameter for a Class and Perk on Cod mod.Let us proceed to the first sub-chapter.
  144.  
  145. II.A Data Type ( You can skip this if you already know )
  146.     II.A-1 Number
  147.     Exactly as the name imply, this data type generally stored numbers as it data type. Usually, you need to specify the data type when creating a new variables, with a exception regular number doesn''t need a data type declaration. Number can be divided by 2, Integer and Float.
  148.     Integer : Our regular number, only consist round number without decimal. Example : 1, 2, 3, 4, 5, etc
  149.     Float   : Number data type, but specific for decimal number. Example : 10.0, 420.69, 69.69, 100.50, etc
  150.  
  151.     *There are other type of number like long or bigint, but we will not talk about it on this tutorial, and we don''t use it on our scripting work.
  152.  
  153.     II.A-2 Char / Character
  154.     Same like before, the name already tell you the data type. This type store "Character" and "String". Although the 2 seems similar, it''s a little bit different. Char data type only store 1 character / symbol / or number only, while string stores a collection of character.
  155.  
  156.     Char    : Data type that only stored 1 character from any input ( It accepted alphabet, symbol, and even number ).
  157.     String  : A collection of character. Several character joint into one array, for example all of this is a string : "This is a example of string", "Numbers like 12345 can also be a string", "Symbols like 20 + 30 = 50 can also be a string", "177013", etc.
  158.  
  159.     A collection of character are described as a "Array" of Character. Array is one of data type, that store data in a multiple container. For example, Char data type only store 1 character information, while a array of character still store the same 1 character data type, but its a collection of several char together like forming a chain. ( You can google Array for more information )
  160.  
  161.     II.A-3 Boolean
  162.     Boolean is a very simple data type. This data type only store 2 value of data, only TRUE / FALSE. Boolean generally used as a validator to check condition, or etc.
  163.  
  164. II.B COD "Required" Parameter
  165.     For a Class / Perk to work properly on a Cod script, there are several parameter they required to be called in a script. The required parameter are shown below :
  166.  
  167. ** Start of Required Parameter
  168.     1. Class / Perk Variables :
  169.         Class Name, Description, Weapon, Stats ( Hp, Spd, Int, Str )
  170.     2. Main & Required Function
  171.         Main Function ( plugin_init ), Class Enableld & Class Disabled
  172.     3. Custom Function ( You can go to next section if your class / perk doesn''t use special function or task that need to be called on a new function.
  173. ** End of Required Parameter
  174.  
  175.     Now, I will explained the content of the Variables, Main & Required Function, and the custom one, first we will have a quick look on the code format, don''t forget to read the slash or comment noted ( // )
  176.  
  177. ** Start of Code Format
  178.     #include <amxmodx>
  179.     #include <codmod>
  180.     // Generally, the very basic one you need is "amxmodx" and "codmod" for a very simple class. It''s up to you to know yourself, when to used a library. You need to know what you want to do with said library, for instance you can see the documentation to understand it, or you see by learning the available code, and see which function need which library.
  181. ** End of Code Format
  182.  
  183.     new const ClassName[] = "Dummy Class";
  184.     new const Description[] = "This is class description section";
  185.     // new means you are creating something new ( To be honest i don''t know that much, i just learning from seeing other people code )
  186.     // const ( i don''t know maybe constant ? ), just say its new variable. Unlike C language, sometimes in PAWN you don''t need to define a data type, but sometimes you do. For the variable class like name and stat, we don''t need to declare the data type.
  187.     // The [] symbol is for a array. Usually, on C you need to specify the size of array, but there we don''t specify the size of array. Because, it will automatically reserved the required space fitting the name length and size.
  188.     // When you write a string, you need to use a " " as a scope where the string start and end.
  189.     new const weapon = 1<<CSW_M249 | 1<<CSW_USP | 1<<CSW_M4A1;
  190.     // This is the format for more than one weapon, you separated it with | symbol, for weapon code see the README section or copy paste this link https://forums.alliedmods.net/archive/index.php/t-59003.html.
  191.     new const hp = 20;
  192.     new const spd = 50;
  193.     new const int = 10;
  194.     new const str = 20;
  195.     // Note that you don''t need ' ' or " " for integer data type.
  196.    
  197.     new bool:classId[33];
  198.     // Note the boolean for class enabled / disabled with value TRUE / FALSE
  199.     // Its 33 because max player for CS is 32 ( idk why i wrote 33, i just followed the old code i learned )
  200.  
  201.     // Now we move to the plugin_init or the main function, and the enabled / disabled section
  202.     public plugin_init(){ // You can search plugin_init on AMXX API Documentation
  203.         register_plugin(name, "1", "TYR");
  204.         cod_register_class(ClassName, Description, hp, spd, int, str);
  205.         // The 2 main task that need to be called on plugin_init is register_plugin and cod_register_class. Register_plugin has 3 parameter, the first one is the plugin name ( you can use a variable as substituted, it doesn''t have to be a string. The second one plugin version, and the third one plugin author.
  206.         // TECHNICALLY, you can write a class without the variable we made on the top, you can just write the hard number on the cod_register_class function. But that would made it a little bit cramped doesn''t it ?
  207.         // Cod_register_class has parameter ( from left to right ) : class name, class description, class weapon, hp, spd, int, and str. Filled the parameter required by using the variable you just created. The variable name could be different from what i created at top, just as long the format of which you put is the same as the parameter, it will not be a problem.
  208.         // For cod_perk_enabled, the format is perk name, perk description, number min, and number max. Number min and max is not required, but optional.
  209.         // For information about the perk value Min or Max, see the section : Random Number Generator on advanced lesson.
  210.  
  211.     public cod_class_enabled(id){ // or cod_perk_enabled(id)
  212.         classId[id] = true;
  213.     }
  214.     public cod_class_disabled(id){ // or cod_perk_disabled(id)
  215.         classId[id] = false;
  216.     }
  217.     // The id is the player Id that using the current class. There should be 32 different id for each player.
  218.     // When Enabling / Disabling a class, don''t forget disabled the perk / class ability there. For example, stats item on perk usually give the benefit on cod_perk_enabled, and removed the bonus on cod_perk_disabled.
  219.     // Class skill with its Validator also given on class_enabled, and removed on class_disabled
  220.     // And don''t forget, you CAN named VARIABLE anything you want, as long it fits the parameter that the function requirement it will not be a problem.
  221.     }
  222.  
  223.     // The very distinct difference of perk and class is the number of variables.
  224.     // A class need class name, desc, weapon, and stats. While perk only need name, and description, and the optional value min and max.
  225.     // For more explanation see the section : Enabling / Disabling Class & Perk section.
  226. ** End of Code Format
  227.  
  228. III Chapter III : Initializing plugin & Enabling Task / Function
  229.     Now, you may be still a little bit confused. What is a function ? What is a parameter ? Now, after you see the code format above, we will talk about the function and the etc on here.
  230.  
  231. III.A Function
  232.     What is a function ? A function act as a job that will be called when the function is called. What job does the function do ? It depends on you, what task or job that you assign to the function ? So generally, a function is designed to do a specific job, or maybe even called another function to accomplish the task it given.
  233.  
  234.     Not all function are template from library. You can create your own function, which can do a specific job you scripted and etc. Just make sure, don''t put space on your function name else it will return an error.
  235.  
  236.     Function can have a required PARAMETER to be called, or you can just called it without a PARAMETER. Parameter as the named imply, is a specific requirement that must be filled in order to called the said function. Usually, the parameter contain data that need to be passed to the function, so the function can used the data to execute its task.
  237.  
  238. III.B Custom Task / Function
  239.     Before you read this sub-chapter, please not we will just talk this topic from outer layer. We will not talk about this topic to deep, I will just explain how to create a custom plugin without a task to be run.
  240.  
  241.     Now, custom task. We already talk about function on the top. Custom task is basically the same as regular function. The difference is just we are the one who created the function. Its not a requirement to always have a custom function on your code ( but certainly you will have custom function if you create a complicated class effect ).
  242.  
  243.     Usually, i myself put the custom task on below everything. That means, i write it after i write the class required parameter, then i wrote my custom function. Custom task example :
  244.  
  245. ** Custom Function / Task
  246.     // All of our "Required" Parameter
  247.     public newTask(){
  248.         new const NumA = 10;
  249.         newTaskB();
  250.     }
  251.    
  252.     public newTaskB(){
  253.         new const NumB = 20;
  254.     }
  255. ** End of Custom Function / Task
  256.    
  257.     As you can see, i have 2 function that i just created. One is newTask function, and the other one is newTaskB function. The code flow for C and PAWN language is the same, it used the "Procedural" principles, as such it will execute the program from the top to bottom. Because the nature of the procedural procedure, one cannot execute a code from top to called a variable or something from bottom that has not been declared yet. For example, on the top you see a variable NumA and NumB. I cannot called a function on newTask to called the number from NumB, since the program has not arrived at the bottom function. But, newTaskB can called the function newTask including using the NumA variable from the newTask function.
  258.  
  259.     The procedural limitation also happen to our "include". You need to put all the required include library on the top ( that''s why the #include <library> is always on the top, and didn''t exist on the bottom. If you have encounter an error, check your procedural step, sometimes a small placement of code can cause an error when compiling.
  260.  
  261. III.C Initializing Function ( "Main Function" )
  262.     On C language, a "Main" class need to be initialized, in order for the program to work and execute properly. Same goes for PAWN, but on AMXMODX you need a plugin_init function in order for the plugin to work properly.
  263.  
  264.     What should we put or include on plugin_init ? How should we know about what we need to put on there ?
  265.  
  266.     plugin_init is usually used to declare cvars, registering a "forward", commands, or other things that need to be declared, you can check the documentation for more information. What is a cvar ? Cvar like a variable for class, but the difference is cvars is used by the server, not only just the class. And, this cvar is like a settings and can be edit. Usually, cvar define a value for plugins to work. For example, cvar on the regular CS server include : friendly_fire 1 or 0, mp_buytime 5, and etc. If your class doesn''t have any cvar value, then just left it with cod_register_class and register_plugin .
  267.  
  268.     On regular COD class, there are 2 function that need to be declared on plugin_init. The first one is register_plugin(PluginName, PluginVersion, AuthorName); and the last one is cod_register_class(name, desc, wpn, hp, spd, int, str); . Also don''t forget, if you don''t want make a variable to store the data, you can filled it directly on the plugin parameter. Just don''t forget to use " " for string.
  269.  
  270.     Here''s a example of class that i created long time ago, that has a specific function that need to be called on specific time. ( Just search register_event on the AMXX Api References )
  271.  
  272. https://github.com/MasamuneDate99/Cs-1.6-COD-MW-Mod/blob/main/Original%20Work/Class%20Rebalance/21%20April%202020/Source/codclass_fearlessmind.sma
  273.  
  274. IV.D Enabling / Disabling Class & Perk
  275.     Now, let us continue our review from the top. If you have play COD mod before, you should be know that player can change class as they please, although the change will be effective after the next round. If you notice, when you''re changing class, the old class effect or bonus doesn''t get carried over to the new class you''re using. That is the purpose why we need to enable or disabling a class.
  276.  
  277.     For Enabling / Disabling class or perk, the only difference is the function name. For class you will be using cod_enable_class(id){ } , and for perk you will be using cod_enable_perk(id){ } . Other that that, there are no difference on how class / perk enabling or disabling its function.
  278.  
  279.     The required thing that must present when enabling a class is the boolean variable we just created. We need to change it into true, so the mod validator will allow us to used the selected class with its properties. The format :
  280.  
  281. ** Enabling Class / Perk
  282.     public cod_class_enabled(id){
  283.         ClassId[id] = true;
  284.         // You can give other function or setting up a task here to.
  285.         // For example if your class is a skilled based :
  286.         resetSkill[id] = true;
  287.         // This is a Flag that only will be reset each round.
  288.         ColorChat(id, RED, "Created by TYR", testClass);
  289.         cod_set_user_bonus_health(id, cod_get_user_health(id, 0, 0)+50);
  290.     }
  291. ** End of Enabling Class / Perk
  292.  
  293.     From the code above, you can see when the class is enabled, it will called ClassId equals true. This alone maybe doesn''t useful, so usually we put the validator on the other part of the code. For example somewhere on the code i will place a validator like this :
  294.  
  295. ** Validator Example
  296.     if(ClassId[id] == false) return COD_STOP;
  297.     if(ClassId[id] == true) return COD_CONTINUE;
  298. ** End of Validator Example
  299.  
  300.     It will only proceed to the other part of the code only if the class flag validator is true. Else, it will stop the current function, and see if there are any other job to do.
  301.  
  302.     Now, the ColorChat on enabled class will sent us a message to player on each round, when the class is enabled. And lastly, you can give stats bonus ( although its usually on perk ) on class enabled. Just don''t forget to deleted the stat bonus by reducing the same amount you give on the disable class.
  303.  
  304.     Now, let''s see the class disabled format.
  305.  
  306. ** Disabling Class / Perk
  307.     public cod_class_disabled(id){
  308.         ClassId[id] = false;
  309.         resetSkill[id] = false;
  310.         // Disabling the flag
  311.         cod_set_user_bonus_health(id, cod_get_user_health(id, 0, 0)-50);
  312.         // Taking the bonus stat that we give before
  313.     }
  314. ** End of Disabling Class / Perk
  315.  
  316.     For disabling class, just forget to undo or take everything that you give. On the above example, since the user will not use this class anymore, we should disable the class validator, invalid the skill usage, deleting the color chat, and taking the bonus stat.
  317.  
  318. IV. Chapter IV : Advanced Lesson
  319. IV.A Random Number Generator
  320.     Ah yes, the "Classic" old RNG factor when playing games. RNG or Random Number Generator is a mechanism in which the system giving a random number, as a determined factor for a event to occur. Now, let us see how to applied a RNG on a code.
  321.  
  322.     Before we begin, there are 2 RNG on COD. The first one is the RNG that used from the AMXX library, and the other one is from pre-defined perk parameter on COD.
  323.  
  324. ** Code Snippet AMXX
  325.     // If from 1 - 10, the random number equals 1, then proceed to the argument
  326.     // Else, if from 1 - 10 the random number result are not 1, then proceed without executing the statement.
  327.     if(random_num(1,10) == 1){
  328.         cod_inflict_damage(idattacker, this, float(get_user_health(this))-damage+1.0, 0.0, idinflictor, damagebits);
  329.     }
  330. ** End of Code Snippet AMXX
  331.  
  332. Now, let''s see the COD Native RNG
  333.  
  334. ** Code Snippet COD Native
  335.     new const perk_desc[] = "+LW Damage, and for every kill you recover 50 HP";
  336.     // plugin_init
  337.     cod_register_perk(perk_name, perk_desc, 18, 35);
  338.     // cod_perk_enabled(id, wartosc){
  339.     perkValue[id] = wartosc;
  340.     // If you confuse where "wartosc" come from, wartosc is a variable from the native include codmod file. It exist as the value that you can call, to get a perk value from perk.
  341.  
  342.     // TakeDamage function
  343.     cod_inflict_damage(idattacker, this, float(perkValue[idattacker]), 0.0, idinflictor, damagebits);
  344. ** End of Code Snippet COD Native
  345.  
  346.     Since the AMXX one very clear, i will just explained a little bit on the COD Native ones. The full parameter of cod_register_perk has 2 required parameter, and 2 optional parameter which i already write on the Enabling / Disabling section. So it should be like this :
  347.  
  348.     cod_register_perk(perkName, perkDesc, minValue, maxValue);
  349.  
  350.     The LW on the description, in C programming language its like this :
  351.  
  352. printf("This is %d number printed not hard-code", numA);
  353.  
  354.     On C, you can print a string on a console, and you can include a float, or integer like example above. It will print the %d or it will print the integer value on variable numA. The same as COD, the LW will print the end result of RNG from the COD Native. The system will determined a random value between the minimal value, and the maximal value. Each time a player get this perk, the system will first randomized the value, the if a player typing /perk for the perk information, it will show the randomize value instead of LW.
  355.  
  356.     If the function being called without value min or value max, the native include library will set it to 0 as the default value.
  357.  
  358. IV.B Define + Function Part 2
  359.     // Please note for this section I''m not to sure myself. Because when i''m creating a C program, i rarely use #define, and it work a little bit different with PAWN
  360.  
  361.     Instead of creating a new variable, sometimes we can do it with the "DEFINE" command. Please not that DEFINE sometimes cannot replace the new creation of variable. Which means you still need to create a variable instead on relying DEFINE.
  362.  
  363.     As the name suggest, DEFINE means we are declaring a value for a variables. Why would we need to use a define ? If you noticed, you can ONLY called a variable within the function you create it. If you want to called or used said variables, you need to import it through calling the variable from the function parameter. Example :
  364.  
  365. ** Example Function
  366.     // This should be right IF I''m not making any mistake
  367.     public newFunction(){
  368.         new const numA = 10;
  369.     }
  370.  
  371.     public newFunctionB(numA){
  372.         new const numB = numA;
  373.     }
  374. ** End of Example Function
  375.  
  376.     The () after the function name is for the Parameter you want to include on the function. I almost forgot, on C programming language, you often need to use "return" function. Different from PAWN, many function didn''t need a return value. You can just proceed without returning any values. BUT, return still exist on PAWN, just rarely being used. Also, COD has 2 return value, return COD_CONTINUE, and return COD_STOP. This 2 return can be used to continue or stop a function example :
  377.  
  378. ** Return COD function Example
  379.     public returnExample(){
  380.         new const Name[] = "Name"
  381.         if((!equal(Name, "Name"){
  382.             return COD_STOP;
  383.             // COD Stop will immediately stop all the plugin function, which means if the condition above didn''t fulfill, the plugin will stop and didn''t continue its rest of the task.
  384.             // For context, this is a class plugin, if the if statement return COD_STOP, you will not able to use the class.
  385.         }
  386.         else return COD_CONTINUE;
  387.     }
  388. ** End of Return COD function Example
  389.  
  390.     Now, let''s talk about define. Define is used with the #define command. You can assign a string, number, float, or etc value you want. Example :
  391.  
  392. ** Define Example
  393.     #define PLUGIN "Testing Define"
  394.     #define VERSION 1.0
  395.     #define AUTHOR "TYR"
  396.  
  397.     // plugin_init
  398.     register_plugin(PLUGIN, VERSION, AUTHOR);
  399. ** End of Define Example
  400.  
  401. IV.C Logical Statement
  402.     The base of programming are mathematical stuff. Especially, logical statement. In mathematics, there are a thing called "Truth Table". It''s almost the same with exception the logical statement we used on scripting is much more simpler. The example with the explanation are shown below.
  403.  
  404. ** Start of Used Symbol on Logical Statement
  405.     !   : Not Equals ( if(!Number = 10) ) > If number not equals 10
  406.     >   : More than
  407.     <   : Less than
  408.     !=  : Not Equals ( Same as ! )
  409.     >=  : More than or equals
  410.     <=  : Less than or equals
  411.     &&  : And operator ( Will only return TRUE if ALL condition is true )
  412.     ||  : Or operator ( Will return TRUE if ONE OF THE condition is true )
  413.     ==  : Equals
  414.    
  415.     *Note : Other symbol like Modulo(%), Accretion, Subtraction, and other can be used also for logical statement.
  416. ** End of Used Symbol on Logical Statement
  417.  
  418.     Now, I will show you a simple example when using this logical statement.
  419. ** Logical Statement Example
  420.     new const numA = 10;
  421.     new const numB = 20;
  422.     new const numC = 10;
  423.  
  424.     if((numA && numC) == 10){ return ColorChat(id, GREEN, "numA and numC is 10", "Example A"); }
  425.     if((numA || numB) == 10){ return ColorChat(id, GREEN, "Either numA OR numB has values equals to 10", "Example B"); }
  426.     if(numA > numB){ return ColorChat(id, GREEN, "This return will never shows up because numA is smaller than numB", "Example C"); }
  427.     if(!is_user_connected){ return ColorChat(id, GREEN, "If is_user_connected(negative) it means user is not connected", "Example D"); }
  428.     if(is_user_connected && (numA == 10)) { ColorChat(id, GREEN, "Will return true if user connected to server and numA is equals to 10", "Example E"); }
  429. ** End of Logical Statement Example
  430.  
  431. IV.D Loading Bar & Class Skill Function
  432.     Now, we will move to cod_class_skill_used function. A brief introduction, all class on COD are able to used skill, if the function is implemented. To use a skill class, the default button is E ( I forgot on how to change, IIRC you need to change the button binding from the core mod ). The skills is various, either it will give a buff, instant skill like damage, or duration and etc.
  433.  
  434.     To implemented the skill, you first need to call the function of cod_class_skill_used(id) { }. Fun fact, you can also implemented the function on a perk. But, the key binding will follow the perk slot, the binding will either be Z or X ( radio1 or radio2 IIRC ).
  435.  
  436. ** cod_class_skill_used(id) example
  437.     public cod_class_skill_used(id){
  438.  
  439.         if(task_exists(id+43)){
  440.             return PLUGIN_CONTINUE;
  441.             // If task exist, continue the plugin while skipping the function
  442.         }
  443.    
  444.         if(!uzycia_skilla[id]){
  445.             ColorChat(id, RED, "Active skill can only be used once per round !");
  446.             return PLUGIN_CONTINUE
  447.             // If skill flag equals false, display error message
  448.             // Then continue the plugin while skipping the function
  449.         }
  450.        
  451.         uzycia_skilla[id]--
  452.         // Skill == False
  453.  
  454.         czas = 10;  // Duration
  455.         dmg_multi = 1.0;
  456.    
  457.         set_task(1.0, "QuadDamage", id+43, _, _, "a",czas); // Task that need to be done
  458.         set_task(10, "Wylacz", id);                         // Task that need to be done
  459.         message_begin(MSG_ONE,108,{0,0,0},id)               // Loading Bar
  460.         write_short(czas)                                   // Display loading bar
  461.         message_end()                                       // Delete loading bar from player view
  462.  
  463.         return PLUGIN_CONTINUE
  464.     }
  465. ** End of cod_class_skill_used(id) Example
  466.  
  467.     From above, its a code from my old class "Claes of Dawn". I forgot if the class already fixed or still buggy, the repository is a little bit old. ( Yeah, some of my newest code are actually lost because i forgot where do i put it, or if i already delete it. ) As you can see on the comment from above, we have 2 validator to check the skill used. If the skill task already exist, it will return to PLUGIN_CONTINUE, which will skip the function, and continue to the other function on the code. Same as the skill, if the skill flag already false, it will return error message and continue.
  468.  
  469.     The uzycia_skilla[id] is a boolean value for the skill. If the first 2 validator check passed, the next it will change the value of the boolean from true to false. For the explanation of the function set_task purpose, you can check it on the documentation ( link above on README section ).
  470.  
  471. IV.E Access Restriction
  472.     There are 2 type of access restriction that I know. The first one we can limited it from player access, and the second one, we can limit it from the name. If you wondering why using name restriction on CS 1.6, because on my old COD server, there are login verification that you need to do. Basically, when you login with your nickname for the first time, you need to register it with a password. Then, the next time you login you need to enter the password you just set in order to use the nickname. Now, I will explain the admin / player access restriction first.
  473.  
  474. ** Admin Level Restriction
  475.     public cod_class_enabled(id){
  476.     if(!(get_user_flags(id) & ADMIN_LEVEL_B))
  477.     // If user flag dosen''t have flag B
  478.     {
  479.         client_print(id, print_chat, "[Required Admin Level B Authorization]")
  480.         return COD_STOP;
  481.     }
  482.     // class enabled : id
  483.     return COD_CONTINUE;
  484.     }
  485. ** End of Admin Level Restriction
  486.  
  487.     The logical statement from above if user doesn''t have "B" access, then return COD_STOP. COD_STOP is like a break on a loop. But, instead of stopping the loop, COD_STOP will stop the whole plugin. Since the code doesn''t progress through the boolean of class enabled, the user can''t use the class. COD_CONTINUE is the same as PLUGIN_CONTINUE.
  488.  
  489.     Now, let''s see the second code example, this time it will be the name restriction.
  490.  
  491. ** Name Validator Restriction
  492.     new PlayerName[33];
  493.     // Just a simple array list of string
  494.  
  495.     public cod_class_enabled(id)
  496.     {
  497.     get_user_name(id, PlayerName, 32);
  498.     if(!equal(PlayerName, "The Magician") && !equal(PlayerName, "Whistle*") && !equal(PlayerName, "Electronic_Arts.-"))
  499.     {
  500.         client_print(id, print_chat, "[ELITE] Do not have permission to use this class.")
  501.         return COD_STOP;
  502.     }
  503.     ma_klase[id] = true;
  504.     return COD_CONTINUE;
  505. }
  506. ** End of Name Validator Restriction
  507.  
  508.     For the code above, you can see, that we used the "get_user_name" function to get the player name, and store all of it on the array we just created. If a user try to use the class but doesn''t have the proper whitelist name, they will get an error message and can''t use the class.
  509.  
  510. IV.F Importing Custom Model & Sound ( With Precaching )
  511.     The first thing we need to do, when about to importing a custom model and sound is to call the function plugin_precache ( See AMXX Documentation for more information ). All of our custom either a model, sprite, or sound need to be "precache" first in this function. After that, then you can specify the model you want to use on the later part of the class code. This function doesn''t require a return value, so just write everything you need, the close it. NOTE : This function is a "forward", therefore we need to register it on the plugin_init function, to apply the change.
  512.  
  513.     There are 2 main precache that we will used regularly. The first one is precache_model, and the other one is precache_sound. As the name implies, the precache_sound is used to precache all the sound files, either BGM, sound effect, etc. The precache_model is used to precache all model, including sprite, player skin, weapon skin, etc.
  514.  
  515. ** Plugin_precache Example + Define Example ( Again )
  516.     #define SKIN_AK47   "models/v_ak47_law.mdl"
  517.     #define SHOOT_SOUND "weapons/law_shoot.wav"
  518.    
  519.     // Initialization
  520.     public plugin_init(){
  521.         // register_event("Event Name", "Function for event", "Flags", "Condition to occur");
  522.         register_event("ChangeWpnSkin", "Weapon_Skin", "be", "1=1");
  523.         // The flag explanation are available on the documentation. For the be flag
  524.         // B = Event sent to SINGLE client ( not the whole server )
  525.         // E = WILL and only WILL be called when client is alive
  526.     }
  527.    
  528.     // Precaching
  529.     public plugin_precache(){
  530.         // precache_sound("Path to file");
  531.         // precache_model("Path to file");
  532.         // The path to file start from /cstrike , so you don''t need to include /cstrike
  533.  
  534.         precache_sound(SHOOT_SOUND);
  535.         precache_model(SKIN_AK47);
  536.     }
  537.  
  538.     // Using the model / sound
  539.     public Weapon_Skin(id){
  540.         if(!is_user_alive(id)){
  541.             return PLUGIN_CONTINUE;
  542.         }
  543.  
  544.         if(get_user_weapon(id) == CSW_AK47){
  545.             if(law_class[id]){
  546.                 // If class = true
  547.                 set_pev(id, pev_viewmodel2, SKIN_AK47)
  548.                 // Set preview to this model
  549.             }
  550.         }
  551.     }
  552.  
  553.     // Cod_class_skill_used
  554.     emit_sound(id, CHAN_WEAPON, SHOOT_SOUND, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
  555. ** End of Plugin_precache Example + Define Example ( Again )
  556.  
  557.     *Note   : The Weapon_Skin is a custom function. You can rename it whatever you want.
  558.  
  559. IV.G Stat Bonus on Class & Perk
  560.     Before we start, there are 4 MAIN stats on COD. Health, Condition ( Idk why everybody mentioning speed as this ), Strength, and Intelligence.
  561.  
  562.     Health      : User BONUS health, not starting health. ( If user Health = 0, then user HP will be 100 )
  563.     Condition   : User BONUS speed, not starting speed. ( IIRC, there are movement speed limit ? The point is, past a certain threshold, more movement speed will give less speed. )
  564.     Strength    : User damage resistance. The more strength, the more dmg resistance user have. ( Dmg resistance doesn''t reduce skill damage. 300 / 400 ? Strength immune to knife stab IIRC )
  565.     Inteligence : No effect on its own. Usually, pairs with perk / class skill. Each bonus Intelligence add bonus damage to skill damage / item damage.
  566.  
  567.     Now, let''s see the stat function that available on COD.
  568.  
  569. ** COD Stat Function
  570.     cod_get_user_health(id, 0, 0);              = Return TOTAL user health point ( stat )
  571.     cod_set_user_bonus_health(id, health);      = Set user current BONUS health point to X number
  572.     // Alternative for Health
  573.     get_user_health(id);                        = Return user current health
  574.     set_user_health(id, health);                = Set user CURRENT health to X number
  575.     cod_get_user_intelligence(id, 0, 0);        = Return TOTAL user Intelligence point ( stat )
  576.     cod_set_user_bonus_intelligence(id, int);   = Set user current Int to X number
  577.     cod_get_user_trim(id, 0, 0);                = Return TOTAL user Speed point ( stat )
  578.     cod_set_user_bonus_trim(id, spd);           = Set user current Speed to X number
  579.     cod_get_user_stamina(id, 0, 0);             = Return TOTAL user Strength point ( stat )
  580.     cod_set_user_bonus_stamina(id, str);        = Set user current Strength to X number
  581. ** End of COD Stat Function
  582.  
  583.     *NOTE : The function of cod_get_user_health and get_user_health is a little bit different. When cod_get_user_health, it will return the total of BONUS Health point the user got from lvl stats, while the get_user_health function return user CURRENT Health point. The same as cod_set_user and set_user function. Cod_set_user health will alter the user TOTAL max HP points, while the set_user_health will alter the user CURRENT health.
  584.  
  585.     For more information, see the AMX cod.inc documentation above, OR see the include folder, and see the codmod.inc on your own. There should be some explanation and note on the .inc file. The variable name on above ( health, int, spd, str ), are custom made, you can name it whatever you want. Now, let''s see the function example on a perk that give stat.
  586.  
  587.  
  588. ** Perk Code Snippet
  589.     public cod_perk_enabled(id){
  590.         cod_set_user_bonus_trim(id, cod_get_user_trim(id, 0, 0)+50);
  591.         cod_set_user_bonus_intelligence(id, cod_get_user_intelligence(id, 0, 0)+50);
  592.         cod_set_user_bonus_health(id, cod_get_user_health(id, 0, 0)+50);
  593.         cod_set_user_bonus_stamina(id, cod_get_user_stamina(id, 0, 0)+50);
  594.         ma_perk[id] = true;
  595.     }
  596.  
  597.     public cod_perk_disabled(id){
  598.         cod_set_user_bonus_trim(id, cod_get_user_trim(id, 0, 0)-50);
  599.         cod_set_user_bonus_intelligence(id, cod_get_user_intelligence(id, 0, 0)-50);
  600.         cod_set_user_bonus_health(id, cod_get_user_health(id, 0, 0)-50);
  601.         cod_set_user_bonus_stamina(id, cod_get_user_stamina(id, 0, 0)-50);
  602.         ma_perk[id] = false;
  603.     }
  604. ** End of Perk Code Snippet
  605.  
  606.     The important thing when giving stat on a perk is, that you mus not forget to reduce the stat bonus IF the user drop the perk. As you know, the function for cod_set_user_bonus stat will set the amount equals to X number you set. So, in order to add the bonus number properly, we can call the function of cod_get_user stat function. As shown above, the parameter is cod_set_user_bonus_stat(id, "Number"); . We can alter the number with calling the get stat function, and add the bonus later. As long the value is still integer.
  607.  
  608. IV.H Intelligence & Cod_inflict_damage
  609.     *NOTE : The original guide merge this part as one section with the Stat Bonus on Class & Perk section. I decided to move this into a separated section.
  610.  
  611.     Now, we will talk about the Intelligence Stat a little bit more. Intelligence doesn''t have any effect on its own. Instead, some class Skill or Perk usually have a % damage from the total point of your Intelligence.
  612.  
  613.     The function are : cod_inflict_damage(id, victimId, baseDamage, intelligenceFactor, dmgToEntity, extraFlag); . The id is your id on the server victimId is the id of your opponent you currently shoot, baseDamage is the flat amount of damage that the function WILL deal everytime the condition fulfill, the intFactor you can set to deal how much damage base on the user intelligence ( You can fill it with a float number, because it''s a float ), dmgToEntity is entity damage like object on map, etc, and the last is extra flag.
  614.  
  615.     You can just leave the extra flag and entity damage on its default function ( The native has already a default value which is 0 ). You can modified the baseDamage parameter, with your liking. For example, if i want to make that the base damage will deal 10% of user current health, then it will be :
  616.  
  617. ** 10% Current Hp as Max Damage
  618.     cod_inflict_damage(idattacker, this, (get_user_health(id)/10), 0.0, idinflictor, damagebits);
  619. ** End of 10% Current Hp as Max Damage
  620.  
  621.     You can modified the paramater with your creativity ! For example, this one will instant killed an opponent when proc / called.
  622.  
  623. ** Instant Kill
  624.     cod_inflict_damage(idattacker, this, get_user_health(id), 0.0, idinflictor, damagebits);
  625. ** End of Instant Kill
  626.  
  627.     For the damage with Intelligence stat will be :
  628. ** Intelligence as Damage
  629.     cod_inflict_damage(idattacker, this, 0.0, 1.0, idinflictor, damagebits);
  630. ** End of Intelligence as Damage
  631.  
  632.     *Note : you can even use other stat as parameter, just put it on the "baseDamage" parameter.
  633.  
  634. IV.I Giving / Taking Weapon + Get User Weapon
  635.     The point of this function is pretty straightforward. On Cod, you can''t pick up a weapon that your class doesn''t give. For example, your class give you M4A1 and a USP. You can drop both of them and pick it up yourself, but if you see a Scout / AWP on ground, you cannot pick it up.
  636.  
  637.     This is where the give weapon function come in handy ! Now, let''s see the function parameter and the explanation.
  638.  
  639. ** Weapon Function
  640.     cod_give_weapon(id_player, weapon_name);
  641.     // Give weapon X to player with the specific Id
  642.     cod_take_weapon(id_player, weapon_name);
  643.     // Removing weapon X from player with the specific Id
  644.     get_user_weapon(id);
  645.     // Return the current weapon name that user hold in hand
  646. ** End of Weapon Function
  647.  
  648.     Now, let''s see the example of the function used on a class or perk.
  649. ** Weapon Code Example
  650.     new weapon = get_user_weapon(idattacker);
  651.     // Get user current weapon
  652.  
  653.     if(weapon == CSW_P90){
  654.         cod_inflict_damage(idattacker, this, 20.0, 0.0, idinflictor, damagebits);
  655.         // If user current weapon equals to P90, additional 20 bonus damage
  656.     }
  657.  
  658.     public cod_perk_enabled(id){
  659.         cod_give_weapon(id, CSW_P90);
  660.         // When class enabled, give P90
  661.     }
  662.  
  663.     public cod_perk_disabled(id){
  664.         cod_take_weapon(id, CSW_P90);
  665.         // When class disabled, remove P90
  666.     }
  667. ** End of Weapon Code Example
  668.  
  669. IV.J "Porting" Plugin
  670.     Let''s say, you have a weapon plugin from Zombie Plague that you want to port it into Cod. It''s not that hard actually, you don''t need to re-code all of them from scratch. You just need to remove some function that is not relevant to the target mod you''re porting it. For example, if the mod is on ZombiePlague, remove everything that related to ZombiePlague. The technical step by step should be like this :
  671.  
  672.     1. First, read the code carefully and scan through the entire code for "Foreign" function that usually does''t exist on Normal vanilla CS. The first step on porting a plugin is we need to port from a specific modded plugin, into a plugin that can run on Vanilla AMX MODX server. For example, if you take the plugin from ZP, just search the keyword like : "Zombie" "Human" "Zp", etc, then just erased all of the function.
  673.    
  674.     Before erasing, re-checked first the function or argument you''re about to delete. You only need to delete function that has relation to ZP / other mod. And not all the zp keyword can be deleted. Just check if the function related or not, if related to zp the deleted it.
  675.  
  676.     The example of zp function, zp_team, zp_register_item, etc. Also, don''t forget to create a backup file before reworking.
  677.  
  678.     2. After you finished cleaning the file from other mod function & include, the next step is to add the Cod include, and all its required function into the plugin. Like cod_register_class or perk, perk or class enabled and disabled, etc.
  679.  
  680.     3. Thirdly, we need to ensure the Cod ALLOWED the said weapon. For Class, you can enable it on weapon variable, while on perk, you need to use the cod_give_weapon(id, wpnName); function. How to know which weapon to be given ? Check the plugin that you are porting.
  681.    
  682.     4. Lastly, we need to "Give" the weapon from the plugin. Usually there should be the give weapon function to obtain the special weapon from the plugin. Call the function on class or perk enabled function. The same as removing it, take the weapon first with the remove weapon function from the plugin, the don'' forget to called the cod_take_weapon function if its perk.
  683.  
  684.     That''s it ! If nothing goes wrong, porting a plugin can be as simple as that.
  685.  
  686. IV.K Include & Native Function + Codmod.inc
  687.     The original guide only consist of 2 function, the Player Visibility, and ColorChat. I decide to rework this section, because i just realized that i have use more than just 2 of CS native / AMXX native.
  688.  
  689.     In this section, I''m explaining the "regularly" used function and what include need to be use. I also include some of Codmod.inc function that i haven''t explain yet.
  690.  
  691. ** amxmisc.inc
  692.     is_user_admin(id);      = Will return 1 if user has any admin flag
  693.     register_menu
  694. ** End of amxmisc.inc
  695.  
  696. ** amxmodx.inc
  697.     get_user_health(id);                                        = Return player with specific id health
  698.     client_print_color(id, colorValue, message, otherVariable); OR
  699.     client_print_color(id, sendTo, message, otherVariable);     = The sendTo can be send to team, or individual client.
  700.     // ColorChat is the same as client_print_color
  701.     get_user_weapon(id, ammoWpn, bpAmmo);                       = Return user weapon currently hold. ammoWpn record the current wpn ammo clip ( Optional ), bpAmmo record the current backpack ammo the user with said Id has ( Optional )
  702.     set_task(timeFloat, functionToExecute, userId, parameterToBePassed, dataSize, flag, repeat);
  703.     // Flag : a = repeat X time ( repeat value = total repeat )
  704.     // b = Loop forever until timer runs out
  705.     // c Time interval is treated as absolute after the map start
  706.     // d Time interval is treated as absolute before map change
  707.     // Set task will execute the task after X time has passed, or will execute it according to the flag the code assign.
  708. ** End of amxmodx.inc
  709.  
  710. ** codmod.inc
  711.     cod_get_user_level(id);                 = Return the current user level with the class.
  712.     cod_set_user_xp(id, value);             = Set user Xp to X value.
  713.     cod_get_user_class(id);                 = Return user current class name
  714.     cod_set_user_class(id, class ,value);   = Set user class to X, if value 1, change instantly
  715.     cod_get_user_perk(id, value, slot);     = Return perk info of X player Id, the value is the perk value ( 1 - X ), if slot equals 0 it means first perk slot, if 1 it means the second perk slot
  716.     // Perk value default is 0
  717.     cod_set_user_perk(id, perkId, perkValue, showInfo, slot);       = Set user perk into perk Id, with X value, on slot 0 or 1
  718.     // If perkValue -1, it will be rando, if perkId -1 it will be random
  719.     cod_perk_used(id);                      = The equivalent function of cod_class_skill_used, except this is for perk only.
  720. ** End of codmod.inc
  721.  
  722. ** cstrike.inc
  723.     cs_get_user_money(id);                  = Return the total amount of money that player with specific ID currently has
  724.     cs_set_user_money(id, value, flash);    = Set user with specific id to X value, flash is 1 for True and 0 for False ( Flashing when money adds )
  725. ** End of cstrike.inc
  726.  
  727. ** fun.inc
  728.     set_user_gravity(id, value);    = 1 is normal gravity ( 800 ). The value accept Float value
  729.     // You can do it like this, for example i want 550 Gravity, so : 550/800
  730.     set_user_godmod(id, value);     = Value is 1 for True, 0 for False ( Godmode / Invincibility )
  731.     set_rendering(id, fx=kRenderFxNone, red, green, blue, render=kRenderNormal, amount);
  732.     // Also exist in fun, and on engine
  733.     set_user_noclip(id, value);     = Value is 1 for True, 0 for false ( Noclip )
  734.     set_user_footsteps(id, value)= Value is 1 for True, 0 for false ( Footsteps sound )
  735. ** End of fun.inc
  736.  
  737. ** engine.inc
  738.     set_rendering(id, fx=kRenderFxNone, red, green, blue, render=kRenderNormal, amount);
  739.     // I don''t know what is kRenderFxNone & kRenderNormal
  740.     // The R, G, B value range from 0 to 255, the amount is the "Opacity" 255 = visible, 1 = invisible ( Cannot 0 )
  741.  
  742.     entity_set_float(id, iKey, value);
  743.     // Almost same as set_user_gravity. The iKey is a variable / key value to what it will do
  744.     // Just use EV_FL_gravity for player. The value only accept between 0.1 - 1, accept Float
  745.     // You can do it like this, for example i want 550 Gravity, so : 550/800
  746. ** End of engine.inc
  747.  
  748. IV.L Debugging / Finding Error
  749.     Before we talk about debugging, there are some other things that we need to talk first. When you''re going to do a debugging, keep a calm, and cool head. Sometimes, on programming, a problem can suddenly appear although you didn''t even touch the code. So, keep a calm and cool head, and try to solve the problem slowly.
  750.    
  751.     There are several ways to do a debugging, but the first of all before we do a debugging is to make sure our code can be compiled on the compiler.
  752.  
  753.     When you''re trying to compile a code, if there''s an error, the compiler will show it to you the problematic line. All kinds of error, especially a fatal error that make the compiler cant compiled your code will always be shown. The first thing to do is immediately check the problematic line, and try to recompile it again until all error disappear. *Note : The compiler will only show fatal error that make the compiling progress impossible. It will not show logical error, or whatever the cause you''re plugin crashing when being loaded on server. If the compiler shown "Warning : Loose Identation", its just a spacing warning.
  754.  
  755.     Now, it''s time to do a debugging and finding error from server side. After loading your plugin in the setting / configs menu, open the server side console, reload the map, and wait for the result. Usually, the server will even record a crash log on server log folder. Pay attention to whatever shown up on the server console for example like : "Error : Missing Model test.mdl", or "Error : Run Time Error, Shutting down server", etc.
  756.  
  757.     Always read the server log to find the issue, see carefully on the server console what is the reason of crash and etc. After that, inspect your code closely on your IDE, then try to figure it on where to fixed the problematic code.
  758.  
  759.     Also note, sometimes, a error that we though a big problem can be as simple as typo on some symbol, or even typo on logical statement, or even typo on a name that make a Null pointer reference error. So, don''t feel bad when you''re facing a problem. That''s all from me !
  760.  
  761. IV.M More ?
  762.     // More things to write ?!?!
Advertisement
RAW Paste Data Copied
Advertisement