[Include] od_stdio.inc
#1

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(stdoutstr);
}
stock IO_Read(str[], size sizeof (str)) {
    
// Press enter first.
    
fread(stdinstrsize);

To make work on Linux type:

PHP код:
ln -/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
Reply
#2

How this works? Some example script? I don't understand at all...
Reply
#3

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
Reply
#4

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 
Reply
#5

Reply
#6

Good work
Reply
#7

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.
Reply
#8

updated with fixed hooks
nice functions names
works on Linux with:

PHP код:
ln -/dev/tty ./scriptfiles/CON 
Reply
#9

We can just add output 1 into the server.cfg and use print/printf for this feature.
https://sampwiki.blast.hk/wiki/Server.cfg
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)