[Include] od_stdio.inc - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Filterscripts (
https://sampforum.blast.hk/forumdisplay.php?fid=17)
+---- Forum: Includes (
https://sampforum.blast.hk/forumdisplay.php?fid=83)
+---- Thread: [Include] od_stdio.inc (
/showthread.php?tid=624229)
od_stdio.inc - Write and type in the console (even on Linux). -
OneDay - 13.12.2016
PHP код:
#if defined _INC_od_stdio
#endinput
#endif
#define _INC_od_stdio
new File:stdin;
new File:stdout;
#define OD_STDIO_Flush IO_Flush
#define OD_STDIO_CarriageReturn IO_CarriageReturn
#define OD_STDIO_NewLine IO_NewLine
#define OD_STDIO_Write IO_Write
#define OD_STDIO_Read IO_Read
public OnGameModeInit()
{
stdin = fopen("CON", io_read);
stdout = fopen("CON", io_write);
#if defined OD_STDIO_OnGameModeInit
OD_STDIO_OnGameModeInit();
#endif
return 1;
}
#if defined _ALS_OnGameModeInit
#undef OnGameModeInit
#else
#define _ALS_OnGameModeInit
#endif
#define OnGameModeInit OD_STDIO_OnGameModeInit
#if defined OD_STDIO_OnGameModeInit
forward OD_STDIO_OnGameModeInit();
#endif
public OnGameModeExit()
{
fclose(stdin);
fclose(stdout);
#if defined OD_STDIO_OnGameModeExit
OD_STDIO_OnGameModeExit();
#endif
return 1;
}
#if defined _ALS_OnGameModeExit
#undef OnGameModeExit
#else
#define _ALS_OnGameModeExit
#endif
#define OnGameModeExit OD_STDIO_OnGameModeExit
#if defined OD_STDIO_OnGameModeExit
forward OD_STDIO_OnGameModeExit();
#endif
stock IO_Flush() {
fclose(stdout);
stdout = fopen("CON", io_write);
}
stock IO_CarriageReturn() {
fwrite(stdout, "\r");
}
stock IO_NewLine() {
fwrite(stdout, "\n");
}
stock IO_Write(str[]) {
fwrite(stdout, str);
}
stock IO_Read(str[], size = sizeof (str)) {
// Press enter first.
fread(stdin, str, size);
}
To make work on Linux type:
PHP код:
ln -s /dev/tty ./scriptfiles/CON
It can write on the console without making another line and can be typed in the console.
Password for server example:
http://forum.sa-mp.com/showthread.ph...24#post3812624
Moving progress bar example:
http://forum.sa-mp.com/showthread.ph...29#post3812629
Scrolling text example:
http://forum.sa-mp.com/showthread.ph...87#post3812687
Re: od_stdio.inc -
Swedky - 13.12.2016
How this works? Some example script? I don't understand at all...
Re: od_stdio.inc -
OneDay - 13.12.2016
I made two more out of this:
http://forum.sa-mp.com/showthread.ph...29#post3812629
http://forum.sa-mp.com/showthread.ph...24#post3812624
Re: od_stdio.inc -
OstGot - 13.12.2016
Well done! I really like it
But in order to be able to use the functions by default, simply by connecting include, you should hook the default public OnGameModeInit and OnGameModeExit like this:
PHP код:
public OD_STDIO_OnGameModeInit()
{
stdin = fopen("CON", io_read);
stdout = fopen("CON", io_write);
#if defined OD_STDIO_OnGameModeInit
return OD_STDIO_OnGameModeInit();
#else
return 1;
#endif
}
#if defined _ALS_OnGameModeInit
#undef OnGameModeInit
#else
#define _ALS_OnGameModeInit
#endif
#define OnGameModeInit OD_STDIO_OnGameModeInit
#if defined OD_STDIO_OnGameModeInit
forward OD_STDIO_OnGameModeInit();
#endif
public OD_STDIO_OnGameModeExit()
{
fclose(stdin);
fclose(stdout);
#if defined OD_STDIO_OnGameModeExit
return OD_STDIO_OnGameModeExit();
#else
return 1;
#endif
}
#if defined _ALS_OnGameModeExit
#undef OnGameModeExit
#else
#define _ALS_OnGameModeExit
#endif
#define OnGameModeExit OD_STDIO_OnGameModeExit
#if defined OD_STDIO_OnGameModeExit
forward OD_STDIO_OnGameModeExit();
#endif
Re: od_stdio.inc -
OneDay - 14.12.2016
Re: od_stdio.inc -
SyS - 14.12.2016
Good work
Re: od_stdio.inc -
OstGot - 14.12.2016
Quote:
Originally Posted by OneDay
|
The first error came just because name of the hooked public coincides with the name of "OD_STDIO_OnGameModeInit" function (however I had in mind that hook can completely replace this function). So if you want to keep the function, you can replace "OD_STDIO_OnGameModeInit" and "OD_STDIO_OnGameModeExit " in hook code on something else.
Second warning shown because you should place "return 1;" in the end of almost every default public.
Re: od_stdio.inc -
OneDay - 04.04.2017
updated with fixed hooks
nice functions names
works on Linux with:
PHP код:
ln -s /dev/tty ./scriptfiles/CON
Re: od_stdio.inc -
ZiGGi - 12.04.2017
We can just add
output 1 into the server.cfg and use print/printf for this feature.
https://sampwiki.blast.hk/wiki/Server.cfg