Vice City: Multiplayer

Server Development => Scripting and Server Management => Snippet Showroom => Topic started by: vcmptr on Jul 22, 2015, 11:14 AM

Title: [Temporary] Print Slicer
Post by: vcmptr on Jul 22, 2015, 11:14 AM
This bug (http://forum.vc-mp.org/?topic=353.0) still not fixed. I can't wait for fix. I created temporary print function.

function PrintSlicer()
{
local PrintBackup = print;
print <- function(string)
{
if(string!=null)
{
string = ""+string+""
if(string.len()>512)
{
  local x = string.len()/512;
  local cpt = 0;
  for(local i = 0; i != x; i++)
{
   cpt += 512;
   PrintBackup(string.slice(cpt-512, cpt));
}
  PrintBackup(string.slice(cpt, (cpt+(string.len()%512))));
  PrintBackup("Sliced prints ("+(x+1)+" slices) ");
}
 else PrintBackup(string);
}
}
}
How to apply?
Just call function in onScriptLoad.
Title: Re: [Temporary] Print Slicer
Post by: . on Jul 22, 2015, 11:30 AM
You guys know you can backup the original print and overwrite it with your own without needing to change everything in your script to use `print2`. Like this example:
local PrintBackup = print;
print <- function(msg)
{
    PrintBackup("Now calling the actual print");
    PrintBackup(msg);
}

print("Testing overwrite");

Thus, allowing you to implement a fragmented print function.
local PrintBackup = print;
print <- function( msg )
{
    for (local n = 0, m = msg.len(); n < m; n += 512)
    {
        if ( (n + 512) > m )
            PrintBackup( msg.slice( n ) );
        else
            PrintBackup( msg.slice( n, (n + 512) ) );
    }
}

In case the issue is unbearable. I never had to deal with strings that long tbh :-\
Title: Re: [Temporary] Print Slicer
Post by: vcmptr on Jul 22, 2015, 01:10 PM
Quote from: S.L.C on Jul 22, 2015, 11:30 AMYou guys know you can backup the original print and overwrite it with your own without needing to change everything in your script to use `print2`. Like this example:
local PrintBackup = print;
print <- function(msg)
{
    PrintBackup("Now calling the actual print");
    PrintBackup(msg);
}

print("Testing overwrite");

Thus, allowing you to implement a fragmented print function.
local PrintBackup = print;
print <- function( msg )
{
    for (local n = 0, m = msg.len(); n < m; n += 512)
    {
        if ( (n + 512) > m )
            PrintBackup( msg.slice( n ) );
        else
            PrintBackup( msg.slice( n, (n + 512) ) );
    }
}

In case the issue is unbearable. I never had to deal with strings that long tbh :-\
You are man! :D Thanks!  I will update script. :)
Title: Re: [Temporary] Print Slicer
Post by: . on Jul 22, 2015, 01:17 PM
Quote from: vcmptr on Jul 22, 2015, 01:10 PMYou are man! :D

But that's what it says on my profile, doesn't it? :-\

(https://forum.vc-mp.org/proxy.php?request=http%3A%2F%2Fs3.postimg.org%2Fdyads6g7n%2FScreenshot_1.png&hash=15c6cd1c8bfaaab2aad919a9653e21a99580e938)
Title: Re: [Temporary] Print Slicer
Post by: vcmptr on Jul 22, 2015, 01:19 PM
Quote from: S.L.C on Jul 22, 2015, 01:17 PM
Quote from: vcmptr on Jul 22, 2015, 01:10 PMYou are man! :D

But that's what it says on my profile, doesn't it? :-\

(https://forum.vc-mp.org/proxy.php?request=http%3A%2F%2Fs3.postimg.org%2Fdyads6g7n%2FScreenshot_1.png&hash=15c6cd1c8bfaaab2aad919a9653e21a99580e938)
Hmm okay... ???