Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - Mohamed Boubekri

#1
Hey everyone, just a simple animated announcement system, type word by word.


Server-Side

enum StreamType
{
    Announce = 0x1
}
function onPlayerCommand( player, cmd, text )
{
if (cmd=="announce")
{
if (!text) return MessagePlayer("[#ff0000]Please use /announce <text>",player);
 for(local i = 0; i < GetMaxPlayers(); ++i)
 {
    local plr = FindPlayer(i);
    if(!plr) continue;

    SendDataToClient(plr, StreamType.Announce, text);
 }
}
else MessagePlayer("[#ff0000]Invalid cmd",player);
}
function onClientScriptData( player )
{
    local stream = Stream.ReadByte();
    switch ( stream )
    {
        case StreamType.Announce:
          for(local i = 0; i < GetMaxPlayers(); ++i)
          {
            local plr = FindPlayer(i);
            if(!plr) continue;
 
            PlaySound(plr.World, 50003, plr.Pos);
          }
    break;
    }

function SendDataToClient( player, ... )
{
    if( vargv[0] )
    {
        local    byte = vargv[0],
                len = vargv.len();
               
        if( 1 > len ) devprint( "ToClent <" + byte + "> No params specified." );
        else
        {
            Stream.StartWrite();
            Stream.WriteByte( byte );

            for( local i = 1; i < len; i++ )
            {
                switch( typeof( vargv[i] ) )
                {
                    case "integer": Stream.WriteInt( vargv[i] ); break;
                    case "string": Stream.WriteString( vargv[i] ); break;
                    case "float": Stream.WriteFloat( vargv[i] ); break;
                }
            }
           
            if( player == null ) Stream.SendStream( null );
            else if( typeof( player ) == "instance" ) Stream.SendStream( player );
            else devprint( "ToClient <" + byte + "> Player is not online." );
        }
    }
    else devprint( "ToClient: Even the byte wasn't specified..." );
}

Client-Side

enum StreamType
{
    Announce = 0x1
}

screenX <- GUI.GetScreenSize().X;
screenY <- GUI.GetScreenSize().Y;

local announceQueue = [0,1], typedChars = 0, typingTimer, announceSprite, announceLabel;

Timer <- {
 Timers = {}

 function Create(environment, listener, interval, repeat, ...)
 {
  vargv.insert(0, environment);

  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);
  Timers.rawset(hash, TimerInfo);

  return hash;
 }

 function Destroy(hash)
 {
  if (Timers.rawin(hash))
  {
  Timers.rawdelete(hash);
  }
 }

 function Exists(hash)
 {
  return Timers.rawin(hash);
 }

 function Fetch(hash)
 {
  return Timers.rawget(hash);
 }

 function Clear()
 {
  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);
    }
  }
  }
 }
};

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

function Server::ServerData( stream )
{
    local type = stream.ReadByte();

    switch( type )
    {
        case StreamType.Announce:
        {
            local announceText = stream.ReadString();

            if (typingTimer == null)
            {
                if ( announceText.len() > 90 )
                    return Console.Print("You can't announce more than 90 characters");

                typingTimer = "lock";

                Console.Print("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");

                announceQueue.insert(0,announceText);

                local centerY = screenY / 2, startY = centerY * 0.3;

                announceSprite = GUISprite( "ann.png", VectorScreen( screenX / 2, startY ) );
                announceSprite.Size = VectorScreen( screenX * 0.05, screenY * 0.06 );
                announceSprite.Alpha = 255;

                SendDataToServer(StreamType.Announce);   

                Timer.Create( this, MoveAnnouncementUp, 50, 15 );       
                Timer.Create( this, CreateAnnouncementLabel, 750, 1 );
                Timer.Create( this, StartHorizontalMovement, 750, 1 );
            }
            else Console.Print("Wait until the first announcement disappears");
        }
        break;
    }
}

function MoveAnnouncementUp()
{
    local offset = screenY * -0.009;
    announceSprite.Pos.Y += offset;   
}

function StartHorizontalMovement()
{
    Timer.Create( this, MoveAnnouncementLeft, 40, 15 );
}

function MoveAnnouncementLeft()
{
    local offset = screenX * -0.032;
    announceSprite.Pos.X += offset;   
}

function CreateAnnouncementLabel()
{
    announceLabel = GUILabel(VectorScreen( screenX * 0.047, screenY * 0.013 ), Colour( 0, 0, 0 ), "");
    announceLabel.FontSize = screenY * 0.02;

    announceSprite.AddChild(announceLabel);

    typingTimer = Timer.Create( this, TypewriterEffect, 90, announceQueue[0].len() );
    Timer.Create( this, DestroyAnnouncement, 10000, 1 );
}

function TypewriterEffect()
{
    local pos = typedChars += 1, prev = pos-1, text = announceQueue[0];
    announceLabel.Text += text.slice(prev,pos);

    local shakeX = screenX * 0.002; // shake effect when typing
    local shakeY = screenY * 0.002;

    if (pos % 2 == 0)
    {
        announceSprite.Pos.X += shakeX;
        announceSprite.Pos.Y += shakeY;
    }
    else
    {
        announceSprite.Pos.X -= shakeX;
        announceSprite.Pos.Y -= shakeY;
    }
}

function DestroyAnnouncement()
{
 announceQueue.clear();
 announceLabel = null;
 announceSprite = null;
 typedChars = 0;

 Timer.Destroy(typingTimer);
 typingTimer = null;
}

function SendDataToServer( ... )
{
    if( vargv[0] )
    {
        local byte = vargv[0],
        len = vargv.len();
               
        if( 1 > len ) Console.Print( "ToClient <" + byte + "> No params specified." );
        else
        {
            local stream = Stream();
            stream.WriteByte( byte );

            for( local i = 1; i < len; i++ )
            {
                switch( typeof( vargv[i] ) )
                {
                    case "integer": stream.WriteInt( vargv[i] ); break;
                    case "string": stream.WriteString( vargv[i] ); break;
                    case "float": stream.WriteFloat( vargv[i] ); break;
                }
            }
           
            Server.SendData( stream );
        }
    }
    else Console.Print( "ToClient: Not even the byte was specified..." );
}

Download sound and sprite from here and put them in store folder. Enjoy !

Credits:
ysc3839 - Client Timers
#2
Script Showroom / Re: BindKey Process System
Mar 18, 2024, 10:22 AM
Setting the time during a key press is a very useful feature to prevent occasional hacking or delays in some scripts.
good job.
#3
Quote from: gamingpro on Jan 28, 2024, 07:54 AMHi bro, Can you tell me how you port forward please ?, because i try it but not success please tell me, Are port forward show server in masterlist or not ?

Hey, just add announce plugin in server.cfg
And try to port forward the port number you have in server.cfg by your router.
#4
Script Showroom / Re: Ban & echo,system
Mar 13, 2024, 01:40 PM
You need to create database, store player informations into it, for example: name, id, ip, uid, ban (true, false)... And simply you can select any row from database by one of the informations and change 'ban' with values true or false.
There are many examples in the forum, just search you will be fine.
#5
Note: The system has been updated you can see that above.
We are using now client-function which is ScriptProcess(), because NewTimer func cause lag in the server.
Don't delete this one "player.SetAnim(0,2)" because it's necessary to stop the walking animation.
#6
Quote from: Gulk on Oct 01, 2023, 03:23 PMTry setting the vehicle weight very high when its unoccupied.
It's seems a good idea :p
But i think it's not real, i will be like the person who will be laugh at the players indirectly.
#7
Quote from: 2b2ttianxiu on Oct 01, 2023, 12:50 PMwhen newX, newY or newZ == 0, bool is false and the vehicle can move. but is so less problem
I have created the system & it's working great.
But it's somehow a little bit laggy, test it: https://forum.vc-mp.org/index.php?topic=9337.0
And if you have any ideas to improve lag, please share it with us.
#8
Videos & Screenshots / New announcement style
Sep 27, 2023, 10:24 AM
Simple one, but it's looks like the console is printing the text character by character.

#9
Alright, thank you
#10
Quote from: vitovc on Sep 16, 2023, 03:48 PMwell you can look into ctf's clientside scripts. its GUI_FLAG_3D_ENTITY flag + Position3D Rotation3D values (in ctf its hardcoded, to calculate them you need to google some math or just playing with different values manually)
Alright, but those lignes & columns have been created by DecUI ?
#11
Those labels are not moving.
its just, like a wall or object contains labels.
#12
#13
Scripting and Server Management / Question !
Sep 15, 2023, 02:28 PM
Hey everyone, i want to know if there any-way to put a label on a wall (object) or (custom object) ?
#14
local Array=[0,1];
Array.insert(0,vehicle.Pos.x), Array.insert(1,vehicle.Pos.y);
Message("here is your x: "+Array[0]+" and your y: "+Array[1]);
Its done now, anyway thanks.
#15
Quote from: habi on Sep 10, 2023, 07:04 AMwill that work datablob.writenstring because that is not listed in squirrel's reference.
https://developer.electricimp.com/squirrel/blob/writestring
Quote from: habi on Sep 10, 2023, 07:04 AMTo write float,
I need to write a string, if there is no way to insert string into blob, then how i can insert string into array ?
local Array = [0];
Array.insert(0, "+vehicle.Pos.x+");
Message("here is your x: "+Array.find(0));