[Release] Animated Announcement

Started by Anik, Mar 25, 2017, 11:18 AM

Previous topic - Next topic

Anik

Credits :-

Animated Announcement

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

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

function 3DAnnounceAll( 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:-

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 :-

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" ) 3DAnnounceAll( text );
else
{
local p = FindPlayer( plr );
if( p ) 3DAnnounce( 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
https://www.youtube.com/watch?v=aRR69mHuTEo#

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

vito


Anik

Quote from: vito on Mar 25, 2017, 11:53 AMwhere is 3d?
Did I write 3D?? Oh! Yes :P... It is only animated announcement.

kennedyarz

#3
the command have a error LOL

else 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
   {     
[b]    if( plr.tolower() == "all" ) 3DAnnounce( text )
    else if( FindPlayer( plr ) ) 3DAnnounceAll( plr, text );
    else MessagePlayer("[#00EE00]( ERROR ) [#FFFFFF] Unknown Player." , player);[/b]
   }
  }
  else MessagePlayer("[#00EE00]( SYNTAX ) [#FFFFFF]/"+cmd+" <plr/all> <text>" , player);
 }

Anik

Quote from: kennedyarz on Mar 25, 2017, 05:06 PMthe command have a error LOL

else 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
   {     
[b]    if( plr.tolower() == "all" ) 3DAnnounce( text )
    else if( FindPlayer( plr ) ) 3DAnnounceAll( plr, text );
    else MessagePlayer("[#00EE00]( ERROR ) [#FFFFFF] Unknown Player." , player);[/b]
   }
  }
  else MessagePlayer("[#00EE00]( SYNTAX ) [#FFFFFF]/"+cmd+" <plr/all> <text>" , player);
 }
What error??

KAKAN

 if( plr.tolower() == "all" ) 3DAnnounce( text )
    else if( FindPlayer( plr ) ) 3DAnnounceAll( plr, text );

You did the opposite thing, at least that's what it seems like when seeing the function name :p
oh no

kennedyarz

#6
and

Line

if( plr.tolower() == "all" ) 3DAnnounceAll( text )
 else if( FindPlayer( plr ) ) 3DAnnounce( plr, text );

KAKAN

Put a semicolon after the if block and try.
:edit: You forgot it while copy-pasting. His code has it.
oh no

kennedyarz

Quote from: KAKAN on Mar 25, 2017, 07:11 PMPut a semicolon after the if block and try.
:edit: You forgot it while copy-pasting. His code has it.

:edit: Does not change at all, same error continues

Saiyan Attack

The Error We Got From 3DAnnounce Or 3DAnnounceAll Just Rename It And It Works !! As I do ...
function Movable( plr, text )
{
local data = Stream();
data.StartWrite();
data.WriteInt( 1 );
data.WriteString( text );
data.SendStream( plr );
}

function MovableAll( text )
{
local data = Stream();
data.StartWrite();
data.WriteInt( 1 );
data.WriteString( text );
data.SendStream( null );
}

Cmd ...
if ( cmd == "movable" )
{
if ( !text ) MessagePlayer("[#00EE00]SYNTAX: [#FFFFFF]/"+cmd+" <plr/all> <text>",player);
else {
local plr = GetTok(text," ", 1), msgs = GetTok(text," ",2,NumTok(text," "));
if ( msgs.len() > 50 ) return MessagePlayer("[#00EE00]ERROR [#FFFFFF]You announcement is too long." , player);
else {
if( plr.tolower() == "all" ) Movable( plr, msgs );
else if( FindPlayer( plr ) ) MovableAll( msgs );
else { MessagePlayer("[#00EE00]ERROR [#FFFFFF] Unknown Player.",player); }
}
}
}

Anik

Quote from: KAKAN on Mar 25, 2017, 05:58 PMif( plr.tolower() == "all" ) 3DAnnounce( text )
    else if( FindPlayer( plr ) ) 3DAnnounceAll( plr, text );

You did the opposite thing, at least that's what it seems like when seeing the function name :p
Yeah :P.. I didn't test the example.. @kennedyarz check it.

kennedyarz

Quote from: Anik on Mar 26, 2017, 07:51 AM
Quote from: KAKAN on Mar 25, 2017, 05:58 PMif( plr.tolower() == "all" ) 3DAnnounce( text )
    else if( FindPlayer( plr ) ) 3DAnnounceAll( plr, text );

You did the opposite thing, at least that's what it seems like when seeing the function name :p
Yeah :P.. I didn't test the example.. @kennedyarz check it.

I think you should know that if you are going to upload something, it must be correct