AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   [CSGO] Why MY Repeat Timer Stop PrintMessage (https://forums.alliedmods.net/showthread.php?t=327831)

bklol 10-12-2020 10:29

[CSGO] Why MY Repeat Timer Stop PrintMessage
 
PHP Code:

#include <sourcemod>

int n 0;
int Lines;

public 
void OnPluginStart()
{
    
RegConsoleCmd("sm_test"Command_t);
}

public 
Action Command_t(int client,int args)
{
    
CreateTimer(0.1TIMER,client,TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
}

public 
Action TIMER(Handle timerany client)
{
    
char lineBuffer[1024];
    
Handle fileHandle OpenFile("addons/sourcemod/configs/badapple.text","r");
    
Lines 1;
    while(!
IsEndOfFile(fileHandle) && ReadFileLine(fileHandlelineBuffersizeof(lineBuffer)))
    {
        for(
int line 1;line <59line++)
        {
            if(
Lines == line n*60)
                
PrintToConsole(client,"%s",lineBuffer);
        }
        
Lines++;
    }
    
n++;


And Here is text file :https://github.com/bklol/badapple-in...r/badapple.txt
Can anyone tell me why timer stop work,thanks a lot!

Marttt 10-12-2020 13:12

Re: [CSGO] Why MY Repeat Timer Stop PrintMessage
 
you should add "return Plugin_Continue;" in the last line (after n++) if you want that to repeat.

Dragokas 10-16-2020 15:06

Re: [CSGO] Why MY Repeat Timer Stop PrintMessage
 
At least, because you have handles leak.
You need to close fileHandle.

Also, your file is just too large. It could be disk overloading /and/or console buffer overflow in constant calling PrintToConsole(). Need to check.
I would read it just once in a huge array and always access to that array only.

Never pass client id in timers, use UserId (retrieved by GetClientUserId()).

PS. Your math is a mind crack. There is surely something wrong.

Marttt, it is Plugin_Continue by default.

Marttt 10-16-2020 21:57

Re: [CSGO] Why MY Repeat Timer Stop PrintMessage
 
Thanks I really dont know where is this in the SM documentation, as an ex Java/DotNet developer is really weird make "Actions" calls without returns

Psyk0tik 10-17-2020 01:58

Re: [CSGO] Why MY Repeat Timer Stop PrintMessage
 
I would imagine that the timer isn't the only thing that stops working on your server. With 10 handles being leaked every second and the constant buffer overflow from PrintToConsole, you could cause the server and all the players on it to crash/disconnect.

Please read about Handles and Timers before attempting to do something like this. It may seem like "simple code" but it's enough to cause issues for anyone using that plugin along with that large ass file. My browser can't even load the entire page without freezing.

Bacardi 10-17-2020 05:21

Re: [CSGO] Why MY Repeat Timer Stop PrintMessage
 
PHP Code:



#include <sdktools>

File myfile;

public 
void OnPluginStart()
{
    
char path[PLATFORM_MAX_PATH];
    
BuildPath(Path_SMpathsizeof(path), "configs/badapple.txt");
    
    if(!
FileExists(path)) SetFailState("Fail: %s"path);
    
    
myfile OpenFile(path"r");
    
    if(
myfile == nullSetFailState("Fail! File is null");


    
RegConsoleCmd("sm_test"test);
}

public 
Action test(int clientint args)
{

    if(
client != 0) return Plugin_Handled;

    if(
myfile.EndOfFile())
    {
        
myfile.Seek(0,0);
    }

    
CreateTimer(0.01delayclientTIMER_REPEAT);

    return 
Plugin_Handled;
}


public 
Action delay(Handle timerint client)
{

    if(
myfile.EndOfFile()) return Plugin_Stop;

    
char line[9000];
    
char buffer[9000];
    
int a 0;

    for(
int x 060x++)
    {
        
myfile.ReadLine(linesizeof(line));
        
strlen(line);
        
        if(
0line[a-1]='\0';
        
        
PrintToServer(line);
    }
    
    

    
    
    return 
Plugin_Continue;


Sending to player console will cause buffer overflow errors.

Dragokas 10-17-2020 09:05

Re: [CSGO] Why MY Repeat Timer Stop PrintMessage
 
Quote:

Originally Posted by Marttt (Post 2721577)
Thanks I really dont know where is this in the SM documentation, as an ex Java/DotNet developer is really weird make "Actions" calls without returns

That is by default, return 0, which is Plugin_Continue equals.
Actually, I am always wondering, why compiler does not throw error about missed return.

Quote:

Originally Posted by Crasher_3637 (Post 2721583)
... and the constant buffer overflow from PrintToConsole, you could cause the server and all the players on it to crash/disconnect.

This is looks like some kind of animated graphics, thing the author is trying to implement.
I remember I done similar plugin for animated chat dedicated to the last New Year, and wanted to share.
But I found inexplicable leak somewhere in game engine related to PrintToChat() command,
causing this function is totally broken and displaying a garbage every time.

bklol 10-19-2020 06:05

Re: [CSGO] Why MY Repeat Timer Stop PrintMessage
 
it works great!thank you


All times are GMT -4. The time now is 06:02.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.