•  
Welcome, Guest. Please login or register.

News:


Author Topic: [Release-Squirrel] Animated Announcement ( 04rel004 )  (Read 6767 times)

Offline Anik

  • Newbie
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
[Release-Squirrel] Animated Announcement ( 04rel004 )
« on: May 13, 2017, 06:59:33 pm »
Credits :-
  • ysc3839 - Timer function of client side.
  • Anik

Animated Announcement

This is a new kind of announcement which is better than the boring one.

Check the code here :-
[spoiler]
Server Side :-
Code: [Select]
function AnimatedAnnounce( plr, text )
{
Stream.StartWrite();
Stream.WriteInt( 1 );
Stream.WriteString( text );
Stream.SendStream( plr );
}

function AnimatedAnnounceAll( text )
{
Stream.StartWrite();
Stream.WriteInt( 1 );
Stream.WriteString( text );
Stream.SendStream( null );
}

function GetTok(string, separator, n, ...)
{
local m = vargv.len() > 0 ? vargv[0] : n,
  tokenized = split(string, separator),
  text = "";

if (n > tokenized.len() || n < 1) return null;
for (; n <= m; n++)
{
text += text == "" ? tokenized[n-1] : separator + tokenized[n-1];
}
return text;
}

function NumTok(string, separator)
{
local tokenized = split(string, separator);
return tokenized.len();
}

Now this goes to Client side:-

Code: [Select]
Timer <- {
Timers = {}

function Create(environment, listener, interval, repeat, ...)
{
// Prepare the arguments pack
vargv.insert(0, environment);

// Store timer information into a table
local TimerInfo = {
Environment = environment,
Listener = listener,
Interval = interval,
Repeat = repeat,
Args = vargv,
LastCall = Script.GetTicks(),
CallCount = 0
};

local hash = split(TimerInfo.tostring(), ":")[1].slice(3, -1).tointeger(16);

// Store the timer information
Timers.rawset(hash, TimerInfo);

// Return the hash that identifies this timer
return hash;
}

function Destroy(hash)
{
// See if the specified timer exists
if (Timers.rawin(hash))
{
// Remove the timer information
Timers.rawdelete(hash);
}
}

function Exists(hash)
{
// See if the specified timer exists
return Timers.rawin(hash);
}

function Fetch(hash)
{
// Return the timer information
return Timers.rawget(hash);
}

function Clear()
{
// Clear existing timers
Timers.clear();
}

function Process()
{
local CurrTime = Script.GetTicks();
foreach (hash, tm in Timers)
{
if (tm != null)
{
if (CurrTime - tm.LastCall >= tm.Interval)
{
tm.CallCount++;
tm.LastCall = CurrTime;

tm.Listener.pacall(tm.Args);

if (tm.Repeat != 0 && tm.CallCount >= tm.Repeat)
Timers.rawdelete(hash);
}
}
}
}
};

ThreeD <-
{
text = null
Label = null
style = null
R = null
G = null
B = null
Timer = null
}

function VScreen( pos_x, pos_y )//Credits goes to Doom_Kill3R for this function
{
local
    screenSize = GUI.GetScreenSize( ),
    x = floor( pos_x * screenSize.X / 1920 ),
    y = floor( pos_y * screenSize.Y / 1080 );

return VectorScreen( x, y );
}

function Server::ServerData( stream )
{
local StreamReadInt = stream.ReadInt( ),
StreamReadString = stream.ReadString( );
switch( StreamReadInt.tointeger( ) )
{
case 1: Create3DAnnouncement( StreamReadString ); break;
}
}

function Script::ScriptProcess( )
{
Timer.Process();
}

function Create3DAnnouncement( strread )
{
if ( ThreeD.Label ) Timer.Destroy( ThreeD.Timer );

ThreeD.text = strread;
ThreeD.style = rand()%10;

ThreeD.R = rand()%255;
ThreeD.G = rand()%255;
ThreeD.B = rand()%255;

ThreeD.Label = GUILabel( VScreen(800,500),Colour( ThreeD.R, ThreeD.G, ThreeD.B ), ThreeD.text );
ThreeD.Label.TextAlignment = GUI_ALIGN_CENTER;
ThreeD.Label.FontFlags = GUI_FFLAG_BOLD | GUI_FFLAG_OUTLINE;
ThreeD.Label.FontSize = 18;

ThreeD.Timer = Timer.Create( this, Update3DAnnouncement, 0.1, 128);
}

function Update3DAnnouncement( )
{
if ( ThreeD.Label )
{
switch( ThreeD.style )
{
case 1:
ThreeD.Label.Pos.X -= 1;
ThreeD.Label.Pos.Y -= 1;
break;
case 2:
ThreeD.Label.Pos.X += 1;
ThreeD.Label.Pos.Y += 1;
break;
case 3:
ThreeD.Label.Pos.X -= 1;
ThreeD.Label.Pos.Y += 1;
break;
case 4:
ThreeD.Label.Pos.X += 1;
ThreeD.Label.Pos.Y -= 1;
break;
case 5:
ThreeD.Label.Pos.X -= 1;
break;
case 6:
ThreeD.Label.Pos.Y -= 1;
break;
case 7:
ThreeD.Label.Pos.X += 1;
break;
case 8:
ThreeD.Label.Pos.Y += 1;
break;
default:
ThreeD.Label.Pos.X -= 2;
ThreeD.Label.Pos.Y += 1;
break;
}
ThreeD.Label.Alpha -=2;
if ( ThreeD.Label.Alpha < 2 )
{
Timer.Destroy( ThreeD.Timer );
ThreeD.Label = null;
}
}
}

Example :-

Code: [Select]
function onPlayerCommand( player , command , arguments )
{
local cmd = command.tolower();
if ( cmd == "ann" )
{
if ( arguments )
{
local plr = GetTok( arguments, " ", 1), text = GetTok( arguments, " ", 2 , NumTok ( arguments , " " ) );
if ( arguments.len() > 50 ) return MessagePlayer("[#00EE00]( ERROR ) [#FFFFFF]You announcement is too long." , player);
else
{
if( plr.tolower() == "all" ) AnimatedAnnounceAll( text );
else
{
local p = FindPlayer( plr );
if( p ) AnimatedAnnounce( p, text );
else MessagePlayer("[#00EE00]( ERROR ) [#FFFFFF] Unknown Player." , player);
}
}
}
else MessagePlayer("[#00EE00]( SYNTAX ) [#FFFFFF]/"+cmd+" <plr/all> <text>" , player);
}
}
[/spoiler]

This is how it looks


NOTE : I have made the style and color random. There are 8 styles. You can modify it according to your choice.