add cod4x io builtins

This commit is contained in:
ineed bots 2023-12-01 14:27:20 -06:00
parent 21949a47da
commit dc58bf328a
2 changed files with 75 additions and 1 deletions

View File

@ -129,6 +129,54 @@ BotBuiltinIsBot()
return false;
}
/*
Opens the file
*/
BotBuiltinFileOpen( file, mode )
{
if ( isDefined( level.bot_builtins ) && isDefined( level.bot_builtins["fs_fopen"] ) )
{
return [[ level.bot_builtins["fs_fopen" ]]]( file, mode );
}
return 0;
}
/*
Closes the file
*/
BotBuiltinFileClose( fh )
{
if ( isDefined( level.bot_builtins ) && isDefined( level.bot_builtins["fs_fclose"] ) )
{
[[ level.bot_builtins["fs_fclose" ]]]( fh );
}
}
/*
Closes the file
*/
BotBuiltinReadLine( fh )
{
if ( isDefined( level.bot_builtins ) && isDefined( level.bot_builtins["fs_readline"] ) )
{
return [[ level.bot_builtins["fs_readline" ]]]( fh );
}
return undefined;
}
/*
Closes the file
*/
BotBuiltinWriteLine( fh, contents )
{
if ( isDefined( level.bot_builtins ) && isDefined( level.bot_builtins["fs_writeline"] ) )
{
[[ level.bot_builtins["fs_writeline" ]]]( fh, contents );
}
}
/*
Returns if player is the host
*/

View File

@ -9,6 +9,10 @@ init()
level.bot_builtins["botmovement"] = ::do_botmovement;
level.bot_builtins["botmoveto"] = ::do_botmoveto;
level.bot_builtins["isbot"] = ::do_isbot;
level.bot_builtins["fs_fopen"] = ::do_fs_fopen;
level.bot_builtins["fs_fclose"] = ::do_fs_fclose;
level.bot_builtins["fs_readline"] = ::do_fs_readline;
level.bot_builtins["fs_writeline"] = ::do_fs_writeline;
}
do_printconsole( s )
@ -24,7 +28,7 @@ do_filewrite( file, contents, mode )
// always adds newline, strip from contents
if ( contents[contents.size - 1] == "\n" )
{
contents = getsubstr(contents, 0, contents.size - 1);
contents = getsubstr( contents, 0, contents.size - 1 );
}
FS_WriteLine( f, contents );
@ -79,3 +83,25 @@ do_isbot()
{
return self.isbot;
}
do_fs_fopen( file, mode )
{
file = "scriptdata/" + file;
return FS_FOpen( file, mode );
}
do_fs_fclose( file )
{
file = "scriptdata/" + file;
FS_FClose( file );
}
do_fs_readline( fh )
{
return FS_ReadLine( fh );
}
do_fs_writeline( fh, contents )
{
FS_WriteLine( fh, contents );
}