Results 1 to 9 of 9

Thread: Script documentation

  1. #1
    Global Mossaderator Mitch's Avatar
    Join Date
    Nov 2012
    Posts
    627
    Thanks
    196
    Thanked 424 Times in 286 Posts

    Script documentation

    Documentation about all Call of Duty 2 functions and also about libcod functions (Jun 16, 2017).

    Web (mirror #1): http://m-itch.github.io/codscriptdoc/
    Web (mirror #2): https://znation.nl/cod2script/
    GitHub: https://github.com/M-itch/codscriptdoc

    The latest libcod function list is available at: https://github.com/voron00/libcod/blob/master/gsc.cpp

    Player collision: https://killtube.org/showthread.php?...ight=collision

    Manymaps: https://killtube.org/showthread.php?...ll=1#post13435
    Uses fs_library as of https://github.com/voron00/libcod/co...e9acf49b64b4d0

    Callbacks
    CodeCallback_PlayerCommand
    https://killtube.org/showthread.php?...r-Builtin-B3!)
    https://killtube.org/showthread.php?...ChatArgs(args)

    CodeCallback_RemoteCommand
    https://killtube.org/showthread.php?3153-callback-RCON

    CodeCallback_UserInfoChanged
    https://killtube.org/showthread.php?...ll=1#post16506

    Search this forum for more examples and additional information.

    Web (old version): https://znation.nl/cod4script/

    Last update thanks to Lonsofore: https://killtube.org/showthread.php?...ll=1#post16334

    13-1-2019: Merged the two documentation threads and added new link to cod2 script documentation.
    Last edited by Mitch; 27th April 2020 at 14:49. Reason: updated links and removed outdated information

  2. The Following 3 Users Say Thank You to Mitch For This Useful Post:

    kung foo man (15th March 2014),Ni3ls (15th March 2014),RobsoN (15th March 2014)

  3. #2
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,616
    Thanks
    17
    Thanked 957 Times in 599 Posts
    Here are a few docs on functions i made:

    msyql_async_create_query:
    Adds a mysql query to the async query handler queue. Will not return anything. Result will be stored. Will return a referencing ID which is 32-bit signed.
    Returns undefined if not called correctly.
    Should be used with the wrapper functions for async mysql
    Usage: mysql_async_create_query(query);
    mysql_async_create_query("SELECT YO_MAMA FROM fatzos");

    msyql_async_create_query_nosave:
    Adds a mysql query to the async query handler queue. Will not return anything and the result will not be stored. Will return a referencing ID which is 32-bit signed.
    Returns undefined if not called correctly.
    Should be used with the wrapper functions for async mysql
    Usage: mysql_async_create_query_nosave(query);
    mysql_async_create_query_nosave("INSERT mah_dick INTO YO_MAMA");

    mysql_async_getdone_list:
    Returns a list of completed query-ids (see the unique ID in mysql_async_create_query and mysql_async_create_query). Should be combined with a mysql_async_getresult_and_free() for each id returned.
    Returns an array of integers.
    Should be used with the wrapper functions for async mysql
    Usage: mysql_async_getdone_list();

    mysql_async_getresult_and_free:
    Returns the result of an async query and frees the internal pointer so the same id will not be put on the mysql_async_getdone_list(). Returns 0 for nosave queries (mysql_async_create_query_nosave), and the mysql_store_result(connection) for save queries (mysql_async_create_query)
    Usage: mysqsl_async_getresult_and_free(async_id);

    mysql_async_initializer:
    Sets up the async mysql module. Only needs to be called once per server-start, will not do anything if called subsequently.
    Usage: mysql_async_initializer(hostname, username, pasword, database, port_is_int, connectioncount);
    Advise: Use a relatively low connectioncount (eg 4) for normal usage, go up to 10 if your server is busy (30+ players or a lot of queries) or located far from the mysql server.

    mysql_reuse_connection:
    When calling the mysql_real_connect for the first time, this connection will be stored in a global (libcod) variable. This function retrieves said variable (or undefined if no connection has been set up yet).
    Very useful when trying to keep mysql connections to a minimum.
    Usage: level.mysql = mysql_reuse_connection();

    add_language:
    Adds a allowed language to the language engine. Has to be a 2-character, uppercase string.
    Usage: add_language(language)
    add_language("EN");

    load_languages:
    Scans a file for a predetermined format of language items, very similar to CoD2 localized strings (.str files). These files should look like this:
    Code:
    REFERENCE blackjack_starting
    LANG_EN "Starting a game of blackjack"
    LANG_DE "Eine neue Runde Blackjack wird gestartet"
    LANG_HU "Blackjack jatek kezdese"
    LANG_CZ "Spousteni hry blackjack"
    LANG_HR "Igra blackjack-a pocinje"
    
    REFERENCE blackjack_help_1
    LANG_EN "Play blackjack"
    LANG_DE "Starte Blackjack"
    LANG_HU "Jatssz a blackjakkel"
    LANG_CZ "Hrat BlackJack"
    LANG_HR "Igranje blackjack-a"
    and can be stored as any file, any extension. Call add_languages with the path+filename of said file. Second input is a force-reload flag which in the future might reduce loading times by a few milliseconds. For now, not-reloading is bugged and the force-reload flag should always be set to 1.
    Usage: load_languages(path_and_filename, force_reload);
    load_languages(getcvar("fs_homepath") + "/" + getcvar("fs_game") + "/translations/JH_b3.txt", 1);
    Can be called for multiple files.

    get_language_item:
    Uses the language engine to find a certain item. Returns a string. Language should be a 2-character uppercase string.
    Usage: get_language_item(language, item);
    get_language_item("EN", "blackjack_starting");
    get_language_item("HU", "blackjack_starting");

    sprintf:
    See http://www.cplusplus.com/reference/cstdio/sprintf/
    Exception: no buffer/stringpointer is required for sprintf, returns the string to stack instead.
    Usage: sprintf(format, additional_arguments)
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

    Sending me a private message makes me want to help you LESS.

  4. The Following 2 Users Say Thank You to IzNoGoD For This Useful Post:

    kung foo man (30th December 2014),Mitch (30th December 2014)

  5. #3
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,616
    Thanks
    17
    Thanked 957 Times in 599 Posts
    And here are the async mysql helper functions:
    PHP Code:

    init_async_mysql
    ()
    {
        
    host getcvar("mysql_host");
        
    user getcvar("mysql_user");
        
    port getcvarint("mysql_port");
        
    pass getcvar("mysql_password");
        
    db getcvar("mysql_database");
        
    mysql_async_initializer(hostuserpassdbport4);
        
    level.mysql_async = [];
        while(
    true)
        {
            list = 
    mysql_async_getdone_list();
            for(
    0< list.sizei++)
            {
                
    result mysql_async_getresult_and_free(list[i]);
                if(!
    isdefined(result))
                    continue;
                if(
    result == 0)
                    
    result undefined;
                
    level.mysql_async["" + list[i]];
                if(
    isdefined(f))
                {
                    if(
    isdefined(f.function))
                        
    thread [[f.function]](resultf.args);
                    else if(
    isdefined(result))
                        
    mysql_free_result(result);
                    
    undefined;
                }
                
    level.mysql_async["" + list[i]] = undefined;
            }
            
    wait .05;
        }
    }

    add_async_query_nosave(q, function, args)
    {
        if(
    getcvarint("show_mysql") == 1)
            
    printf("mysql_query async nosave:" "\n");
        
    id mysql_async_create_query_nosave(q);
        
    spawnstruct();
        
    f.query q;
        
    f.function = function;
        
    f.args args;
        
    level.mysql_async["" id] = f;
    }

    add_async_query(q, function, args)
    {
        if(
    getcvarint("show_mysql") == 1)
            
    printf("mysql_query async:" "\n");
        
    id mysql_async_create_query(q);
        
    spawnstruct();
        
    f.query q;
        
    f.function = function;
        
    f.args args;
        
    level.mysql_async["" id] = f;

    Yes, it is stored as a string-indexed array as i had trouble with high-int indexed arrays in cod2 in the past.
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

    Sending me a private message makes me want to help you LESS.

  6. The Following User Says Thank You to IzNoGoD For This Useful Post:

    Mitch (30th December 2014)

  7. #4
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,616
    Thanks
    17
    Thanked 957 Times in 599 Posts
    Some minor changes i propose:

    Clientcommand(): should be added that libcod checks for CodeCallback_PlayerCommand(args) in maps\mp\gametypes\_callbacksetup.gsc every mapchange, but it will stop checking for it once it does not find it ONCE. So changing shit there might require you to fully restart your server.

    disableGlobalPlayerCollision(): does NOT disable the global player collision, it just stops the game from setting contents on all players at the end of each frame, allowing for a custom setcontents() on spawn.

    free_slot(): Only works for bots, not for normal players (something bad happened to me when i tried it on a player - probably a servercrash)

    getClientState(): can never return free or zombie due to the fact that it has to be called on a player, not a slot (free slot = undefined player = cannot call function on undefined)

    mysql_real_escape_string(): has mysql_free_result header, and it should NOT be called on the entire query but should instead just be called on a string you want to escape with ' in your query. In the example query on the manpage, it should be used to escape the 'name' thingy, so query = select stuff from somewhere where name = '" + mysql_real_escape_string(mysql, "hello world") + "' ";

    setalive(): afaik setalive is used on non-player entities only, resulting in a notify("damage", amount) once they get shot at.

    On a semi-related note: the libcod-list seems to be non-alphabetical
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

    Sending me a private message makes me want to help you LESS.

  8. The Following 2 Users Say Thank You to IzNoGoD For This Useful Post:

    kung foo man (4th January 2015),Mitch (4th January 2015)

  9. #5
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,616
    Thanks
    17
    Thanked 957 Times in 599 Posts
    More updates:

    printf supports more than one argument, in the form of printf("Hello %\n", "world"); and as such supports all types of secondary arguments. All % will be replaced by additional input arguments. If no arguments are given, the % will be removed. To print a % to console, use printf("this works 100%%");

    sprintf has been updated to this type of input too, but returns the string instead. Also sprintf does not yet support any type of input except: string, float, vector, int

    Multi-input for both functions is also supported:
    printf("hello % foo % test %", "world", "bar", 42);
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

    Sending me a private message makes me want to help you LESS.

  10. #6
    Global Mossaderator Mitch's Avatar
    Join Date
    Nov 2012
    Posts
    627
    Thanks
    196
    Thanked 424 Times in 286 Posts
    Changing a map on your server with Cmd_ExecuteString or connectionlessPacket will crash your server.

    PHP Code:
    Cmd_ExecuteString("map " newmap);
    self connectionlessPacket("rcon " getcvar("rcon_password") + " map " newmap); 

  11. #7
    Private Lonsofore's Avatar
    Join Date
    Oct 2016
    Posts
    84
    Thanks
    81
    Thanked 37 Times in 24 Posts

    Post Script documentation #2

    Hello Killtube. You could see the old thread with documentation, but it's too old. Some functions no longer exist, some of them changed their name and also a lot of new. But there is a Git repo, so I decided to fork it and make new domentation.

    Web: http://script.cod2.ru
    GitHub: https://github.com/Lonsofore/codscriptdoc

    There is a lot of changes:
    - All files are sorted now with folders
    - Separated stock and libcod
    - Added categories for libcod (like you could see in VoroN's libcod repo)
    - Removed nonexistent libcod functions
    - Fixed some functions (e.g. some of them has the different name now)
    - Added a lot of new functions (but not all yet!)
    - As soon as libcod doesn't support CoD1 and CoD4, I want to make this documentation only for CoD2

    But more needs to be done and I want to ask Killtube about it:
    - As you could read above, I want to make this documentation only for CoD2, so I want to ask you - which functions from this list don't exist in CoD2?
    - I also found some unknown functions in Mitch's repo. Can somebody tell me about them? link
    - And if somebody wants to support this idea - you're welcome! Here you can find almost all libcod functions. Write about missing in this thread and I'll add it :)
    Fully completed categories: Bots, Entity, Exec. In other categories you can find something and describe. It's very good opportunity to learn more in libcod :)

  12. The Following 3 Users Say Thank You to Lonsofore For This Useful Post:

    IzNoGoD (10th June 2017),kung foo man (9th June 2017),YuriJurek (10th June 2017)

  13. #8
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,616
    Thanks
    17
    Thanked 957 Times in 599 Posts
    - ADSaim doesnt make a bot "aim at visible players". All it does is simulate a right mouse-click, probably without the toggle functionality (aka keep it set to true until you want the bot to zoom out again)
    - async_create_nosave also can have a callback, like async_create. It just doesn't pass the result from the command into the callback.
    - Might wanna add to memset() that it's expecting an integer, so you need at least 4 bytes to be memset'd
    - In clientUserInfoChanged it states that "The existance of CodeCallback_UserInfoChanged is checked once on start." Might wanna clarify that that's server-start not map-start. Same for clientcommand()
    - Connectionlesspacket fakes a packet from the client to the server, not the other way around
    - float() can take float, int and string as argument, not just string.
    - Gettype lacks list of possible responses
    - Please dont link to the sprintf() c-implementation for sprintf. It's just a fancy way of replacing % with arguments. The c-implementation is far more fancy.

    Overall, the returned types seem to be missing. For example, getvelocity() returns a vector.
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

    Sending me a private message makes me want to help you LESS.

  14. The Following 3 Users Say Thank You to IzNoGoD For This Useful Post:

    kung foo man (10th June 2017),Lonsofore (10th June 2017),YuriJurek (10th June 2017)

  15. #9
    Private Lonsofore's Avatar
    Join Date
    Oct 2016
    Posts
    84
    Thanks
    81
    Thanked 37 Times in 24 Posts
    Thank you, IzNoGoD. Fixed all of this list (except return types).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •