PDA

View Full Version : Script documentation



Mitch
15th March 2014, 19:36
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://script.cod2.ru/
Web (mirror #3): 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?3137-disable-playercollision-Voron-s-libcod&highlight=collision

Manymaps: https://killtube.org/showthread.php?2471-generating-an-empty-iwd-with-the-tool&p=13435&viewfull=1#post13435
Uses fs_library as of https://github.com/voron00/libcod/commit/dced904cd71b67326bce3b7f8e27636c0121f33b#diff-54e1f81ff07579b02ae9acf49b64b4d0

Callbacks
CodeCallback_PlayerCommand
https://killtube.org/showthread.php?1201-Extension-Player-Command-Control-(includes-CHAT-Control-for-Builtin-B3!)
https://killtube.org/showthread.php?2494-fixChatArgs(args)

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

CodeCallback_UserInfoChanged
https://killtube.org/showthread.php?2952-Prevent-duplicated-names&p=16506&viewfull=1#post16506

Search this forum for more examples and additional information.

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

Libcod coding:
[Tutorial] Add libcod support for your cod version. (https://killtube.org/showthread.php?2084-Tutorial-Add-libcod-support-for-your-cod-version)
Convert IDA HexRays Decompiler source to working C source (https://killtube.org/showthread.php?2224-Convert-IDA-HexRays-Decompiler-source-to-working-C-source)

Last update thanks to Lonsofore: https://killtube.org/showthread.php?1869-Script-documentation&p=16334&viewfull=1#post16334

13-1-2019: Merged the two documentation threads and added new link to cod2 script documentation.

IzNoGoD
30th December 2014, 00:57
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:


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)

IzNoGoD
30th December 2014, 00:58
And here are the async mysql helper functions:



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(host, user, pass, db, port, 4);
level.mysql_async = [];
while(true)
{
list = mysql_async_getdone_list();
for(i = 0; i < list.size; i++)
{
result = mysql_async_getresult_and_free(list[i]);
if(!isdefined(result))
continue;
if(result == 0)
result = undefined;
f = level.mysql_async["" + list[i]];
if(isdefined(f))
{
if(isdefined(f.function))
thread [[f.function]](result, f.args);
else if(isdefined(result))
mysql_free_result(result);
f = 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:" + q + "\n");
id = mysql_async_create_query_nosave(q);
f = 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:" + q + "\n");
id = mysql_async_create_query(q);
f = 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.

IzNoGoD
4th January 2015, 18:29
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

IzNoGoD
7th January 2015, 15:23
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);

Mitch
24th January 2015, 13:02
Changing a map on your server with Cmd_ExecuteString or connectionlessPacket will crash your server.



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

Lonsofore
9th June 2017, 23:19
Hello Killtube. You could see the old thread (https://killtube.org/showthread.php?1869-Script-documentation) 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 (https://github.com/voron00/libcod))
- 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 (https://github.com/Lonsofore/codscriptdoc/tree/master/unknown)
- And if somebody wants to support this idea - you're welcome! Here (https://github.com/voron00/libcod/blob/master/gsc.cpp) 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 :)

IzNoGoD
10th June 2017, 03:12
- 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.

Lonsofore
10th June 2017, 09:39
Thank you, IzNoGoD. Fixed all of this list (except return types).