« [Release] Vehicle Damage Meter
[Release] Animated Announcement
[Release] Speed-o-Meter »

Anik

  • Sr. Member
  • Posts: 355
[Release] Animated Announcement
« on March 25th, 2017, 11:18 AM »Last edited on April 7th, 2017, 04:59 PM
Credits :-

Animated Announcement

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

Check the code here :-
(click to show/hide)
Server Side :-
Code: [Select]
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:-

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" ) 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);
}
}

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

  • Sr. Member
  • Posts: 406

Anik

  • Sr. Member
  • Posts: 355

kennedyarz

  • Sr. Member
  • Making American Great Again
  • Posts: 334
[Release] Re: Animated Announcement
« Reply #3, on March 25th, 2017, 05:06 PM »Last edited on March 25th, 2017, 05:22 PM
the command have a error LOL

Code: [Select]
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

  • Sr. Member
  • Posts: 355
[Release] Re: Animated Announcement
« Reply #4, on March 25th, 2017, 05:45 PM »
Quote from kennedyarz on March 25th, 2017, 05:06 PM
the command have a error LOL

Code: [Select]
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

  • Wiki Contributor
  • Posts: 3,346
[Release] Re: Animated Announcement
« Reply #5, on March 25th, 2017, 05:58 PM »
 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
You can contact me using Discord, at Developers.CPP( check off-board to find the invite link )
Github: https://github.com/theKAKAN

kennedyarz

  • Sr. Member
  • Making American Great Again
  • Posts: 334
[Release] Re: Animated Announcement
« Reply #6, on March 25th, 2017, 06:42 PM »Last edited on March 25th, 2017, 06:45 PM
and

Line

Code: [Select]
if( plr.tolower() == "all" ) 3DAnnounceAll( text )
 else if( FindPlayer( plr ) ) 3DAnnounce( plr, text );

KAKAN

  • Wiki Contributor
  • Posts: 3,346
[Release] Re: Animated Announcement
« Reply #7, on March 25th, 2017, 07:11 PM »
Put a semicolon after the if block and try.
:edit: You forgot it while copy-pasting. His code has it.
You can contact me using Discord, at Developers.CPP( check off-board to find the invite link )
Github: https://github.com/theKAKAN

kennedyarz

  • Sr. Member
  • Making American Great Again
  • Posts: 334
[Release] Re: Animated Announcement
« Reply #8, on March 25th, 2017, 07:45 PM »
Quote from KAKAN on March 25th, 2017, 07:11 PM
Put 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

  • Jr. Member
  • [KoF]Killer
  • Posts: 67
[Release] Re: Animated Announcement
« Reply #9, on March 25th, 2017, 08:12 PM »
The Error We Got From 3DAnnounce Or 3DAnnounceAll Just Rename It And It Works !! As I do ...
Code: [Select]
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 ...
Code: [Select]
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

  • Sr. Member
  • Posts: 355
[Release] Re: Animated Announcement
« Reply #10, on March 26th, 2017, 08:51 AM »
Quote from KAKAN on March 25th, 2017, 05:58 PM
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
Yeah :P.. I didn't test the example.. @kennedyarz check it.

kennedyarz

  • Sr. Member
  • Making American Great Again
  • Posts: 334
[Release] Re: Animated Announcement
« Reply #11, on March 26th, 2017, 04:54 PM »
Quote from Anik on March 26th, 2017, 08:51 AM
Quote from KAKAN on March 25th, 2017, 05:58 PM
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
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

« [Release] Vehicle Damage Meter
[Release] Speed-o-Meter »