•  
Welcome, Guest. Please login or register.

News:


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.


Topics - Anik

Pages: [1]
1
Scripting / [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.

2
Credits :-
  • Anik

Anik's Registration System

You may need sqlite, hashing and squirrel plugin for it.

Codes Here :-

[spoiler]
Server Side :-

Code: [Select]
class PlayerStats
{
Password = null;
Level = 0;
UID = null;
IP = null;
AutoLogin = false;
LoggedIn = false;
Registered = false;
}

function onScriptLoad( )
{
DB <- ConnectSQL( "Registration.db" );
status <- array( GetMaxPlayers(), null );
QuerySQL ( DB , "CREATE TABLE IF NOT EXISTS Accounts ( Name TEXT , LowerName TEXT , Password VARCHAR(255) , Level NUMERIC , TimeRegistered VARCHAR(255), UID VARCHAR(255), IP VARCHAR(255), AutoLogin TEXT ) " );
print( "Loaded GUI Registration system By Anik." );
}

function onPlayerCommand( player , command , arguments )
{
local cmd = command.tolower();
if( cmd == "exec" )
{
if ( !arguments || arguments == "" ) ErrorSyntax("/" + cmd + " ( Code )",player)
else if ( status[ player.ID ].Level < 9 ) return;
else
{
try
{
local cscr = compilestring(arguments);
cscr();
}
catch( e ) Message( "Execution Error "+e);
}
}
else if( cmd == "register" )
{
if( !status[ player.ID ].Registered )
{
SendDataToClient( player.ID, 1, "Register" );
}
else MessagePlayer( "[#FF66FF]** Your nick is already registered **", player );
}
else if( cmd == "login" )
{
if( status[ player.ID ].Registered && !status[ player.ID ].LoggedIn )
{
SendDataToClient( player.ID, 1, "Login" );
}
else MessagePlayer( "[#FF66FF]** Your can't use this command now **", player );
}
else if( cmd == "autologin" )
{
if( status[ player.ID ].Registered && status[ player.ID ].LoggedIn )
{
if ( status[ player.ID ].AutoLogin ) status[ player.ID ].AutoLogin = false;
else status[ player.ID ].AutoLogin = true;
MessagePlayer( "[#FF66FF]** Auto Login Status : "+status[ player.ID ].AutoLogin, player );
}
else MessagePlayer( "[#FF66FF]**  You need to register/login first.", player );
}
}

function onPlayerJoin( player )
{
Message( "[#FF66FF]** Player "+player+" has established connection to the server **" );
status[ player.ID ] = PlayerStats( );
AccInfo( player );
}

function onPlayerPart( player, reason )
{
if( status[ player.ID ].LoggedIn ) SaveStats( player );
Message( "[#FF66FF]** Player "+player.Name+" has left the server **" );
}

function SaveStats( player )
{
QuerySQL(DB,
    format(@"UPDATE [Accounts] SET
        [Level]='%s',
        [UID]='%s',
        [IP]='%s',
        [AutoLogin]='%s'
        WHERE [Name]='%s' AND [LowerName]='%s';",
        status[ player.ID ].Level.tostring(),
        status[ player.ID ].UID.tostring(),
        status[ player.ID ].IP.tostring(),
        status[ player.ID ].AutoLogin.tostring(),
        player.Name,
        player.Name.tolower()
    )
);
}

function AccInfo( player )
{
local q = QuerySQL( DB, "SELECT * FROM Accounts WHERE Name = '" + escapeSQLString( player.Name ) + "'" );
if( q )
{
status[ player.ID ].Password = GetSQLColumnData( q, 2 );
status[ player.ID ].Level = GetSQLColumnData( q, 3 );
status[ player.ID ].UID = GetSQLColumnData( q, 5 );
status[ player.ID ].IP = GetSQLColumnData( q, 6 );
status[ player.ID ].AutoLogin = GetSQLColumnData( q, 7 );
status[ player.ID ].Registered = true;
if( ( player.UID == status[ player.ID ].UID ) || ( player.IP == status[ player.ID ].IP ) )
{
if( status[ player.ID ].AutoLogin == "true" )
{
MessagePlayer( "[#CCFF66]** Welcome back to the server." , player );
MessagePlayer( "[#CCFF66]** You've been auto logged in, to disable this, type /autologin [ Toggles automatically ]" , player );
status[ player.ID ].LoggedIn = true;
}
else
{
MessagePlayer( "[#CCFF66]** Welcome back to the server." , player );
MessagePlayer( "[#CCFF66]** Your nick is registered. Please login in order to access services." , player );
}
}
else
{
MessagePlayer( "[#CCFF66]** Welcome back to the server." , player );
MessagePlayer( "[#CCFF66]** Your nick is registered. Please login in order to access services." , player );
}
}
else
{
MessagePlayer( "[#CCFF66]** Welcome to the server." , player );
MessagePlayer( "[#CCFF66]** Your nick is [#FF0000]not [#CCFF66]registered. Please register in order to access services." , player );
}
FreeSQLQuery( q );
}

function onClientScriptData( player )
{
local int = Stream.ReadInt( ),
string = Stream.ReadString ( );
switch( int.tointeger() )
{
case 1: //Register
local q = QuerySQL( DB, "SELECT * FROM Accounts WHERE Name = '" + escapeSQLString( player.Name ) + "'" );
if( !q ) QuerySQL( DB, "INSERT INTO Accounts ( Name, LowerName, Password , Level, TimeRegistered, UID, IP, AutoLogin ) VALUES ( '" + escapeSQLString( player.Name ) + "', '" + escapeSQLString( player.Name.tolower() ) + "', '" + SHA256( string ) + "', '1', '" + time( ) + "', '" + player.UID + "', '" + player.IP + "', 'true' )");
status[ player.ID ].Password = SHA256( string );
status[ player.ID ].Level = 1;
status[ player.ID ].UID = player.UID;
status[ player.ID ].IP = player.IP;
status[ player.ID ].AutoLogin = true;
status[ player.ID ].Registered = true;
status[ player.ID ].LoggedIn = true;
MessagePlayer( "[#CCFF66]** Successfully Registered." , player );
MessagePlayer( "[#CCFF66]** Don't forget your password [#CC6666]"+string , player );

break;

case 2: //Login

if( status[ player.ID ].Password == SHA256( string ) )
{
MessagePlayer( "[#CCFF66]** Successfully Logged in." , player );
status[ player.ID ].LoggedIn = true;
status[ player.ID ].UID = player.UID;
status[ player.ID ].IP = player.IP;
SendDataToClient( player.ID, 3, "" );
}
else SendDataToClient( player.ID, 2, "Wrong Password" );

break;
}
}

function onPlayerRequestSpawn( player )
{
if( !status[ player.ID ].Registered )  MessagePlayer( "[#CCFF66]** Please Register First." , player );
else if( !status[ player.ID ].LoggedIn )  MessagePlayer( "[#CCFF66]** Please Login First." , player );
else return 1;
}

function SendDataToClient( player, integer, string )
{

if ( FindPlayer( player ) )
{

Stream.StartWrite( );
Stream.WriteInt( integer );
if ( string != null ) Stream.WriteString( string );
Stream.SendStream( FindPlayer( player ) );

}

}

Client Side :-

Code: [Select]
function Server::ServerData( stream )
{
local StreamReadInt = stream.ReadInt( ),
StreamReadString = stream.ReadString( );
switch( StreamReadInt.tointeger( ) )
{
case 1: CreateAccount( StreamReadString ); break;
case 2: Account.ErrorLabel.Text = StreamReadString; break;
case 3: DelAccount( ); break;
}
}

Account <-
{
Window = null
Editbox = null
Selected = null
Label = null
ErrorLabel = null
}

function DelAccount( )
{
Account.Window = null;
Account.Editbox = null;
Account.Selected = null;
Account.Label = null;
Account.ErrorLabel = null;
GUI.SetMouseEnabled( false );
}

function CreateAccount( strread )
{
local scr = GUI.GetScreenSize( ),
plr = World.FindLocalPlayer();

Account.Window = GUIWindow( );
Account.Window.Size = VectorScreen( 300, 150 );
Account.Window.Colour = Colour( 0, 0, 20, 180 );
Account.Window.Pos = VectorScreen( 170, 30 );
Account.Window.Text = strread;
Account.Window.FontFlags = ( GUI_FFLAG_BOLD | GUI_FFLAG_ULINE );
Account.Window.RemoveFlags( GUI_FLAG_WINDOW_RESIZABLE );

Account.Label = GUILabel( );
Account.Label.Text = "Input your password in the text box to "+strread;
Account.Label.Pos = VectorScreen( 1, 5 );
Account.Label.FontSize = 11;
Account.Label.TextColour = Colour( 255, 255, 255 );
Account.Label.FontFlags = ( GUI_FFLAG_BOLD );

Account.ErrorLabel = GUILabel( );
Account.ErrorLabel.Text = ""
Account.ErrorLabel.Pos = VectorScreen( 1, 70 );
Account.ErrorLabel.FontSize = 12;
Account.ErrorLabel.TextColour = Colour( 255, 0, 0 );
Account.ErrorLabel.FontFlags = ( GUI_FFLAG_ULINE );

Account.Editbox = GUIEditbox( VectorScreen( 50, 30 ), VectorScreen( 200, 40 ), Colour( 152, 152, 152 ), "", GUI_FLAG_EDITBOX_MASKINPUT );

Account.Selected = strread;

Account.Window.AddChild( Account.Editbox );
Account.Window.AddChild( Account.Label );
Account.Window.AddChild( Account.ErrorLabel );

GUI.SetFocusedElement( Account.Editbox );
GUI.SetMouseEnabled( true );
}


function GUI::ElementClick(element, mouseX, mouseY)
{
switch( element )
{
case Account.CloseButton: DelAccount( ); break;
}
}
function GUI::InputReturn(editbox)
{
switch( editbox )
{
case Account.Editbox:

if( Account.Selected == "Register" )
{
if( Account.Editbox.Text.len() > 3 )
{
if( Account.Editbox.Text.len() < 50 )
{
SendDataToServer( Account.Editbox.Text, 1 );
DelAccount( );
GUI.SetMouseEnabled( false );
}
else Account.ErrorLabel.Text = "Your password cant contain more than 50 characters.";
}
else Account.ErrorLabel.Text = "Your password must contain more than 3 characters.";
}
else
{
if( Account.Editbox.Text.len() > 3 )
{
if( Account.Editbox.Text.len() < 50 )
{
SendDataToServer( Account.Editbox.Text, 2 );
}
else Account.ErrorLabel.Text = "Wrong Password.";
}
else Account.ErrorLabel.Text = "Wrong Password.";
}

break;
}
}

function SendDataToServer( str, int )
{
local message = Stream();
message.WriteInt(int.tointeger());
message.WriteString(str);
Server.SendData(message);
}

[/spoiler]

This is how it looks :-



3
Scripting / [Release-Squirrel] Anik's GUI Editor ( 04rel004 )
« on: May 13, 2017, 06:57:59 pm »
GUI Editor - Vice City Multiplayer

Hello guys, I am presenting you my GUI Editor. Which gives you the opportunity to edit GUIElements in game. Which will save a lot of time.
This gui editor will also output the code so you can easily copy and paste them into your script!

Interaction with Editor

Its easy make sure you read this carefully, the editor is really user-friendly and takes you no time to learn.

You can move your element by holding CTRL key and moving your mouse. And hold RMB and move mouse to resize your element.

Everything updates instantly to other players. So many players can edit a project at a time


Project Management:-
  • newproject [ Name ] - Creates a new project with the name provided
  • saveproject - Saves the currently opened project.
  • loadproject [ Name ] - Loads a map
  • exportproject - Export the project, outputs code on /scripts/Client Script/.
  • closeproject - Close any opened project
  • project - Tells you which map is currently being worked on.
  • elements - Tells you all elements created on current project.

Elements Management:-
  • addlabel [ name ] [ text ] - Creates a label
  • addwindow[ name ] [ text ] - Creates a Window
  • addbutton[ name ] [ text ] - Creates a button

Player Keys:-
  • C - Switch between R|G|B while colour mode is on.
  • PAGE UP | PAGE DOWN - Increase | Decrease Font Size - Change R | G | B
  • CTRL - Enable positioning mode! Hold CTRL and move mouse to change positon of your element
  • RMB- Enable Resize mode! Hold RMB and move mouse to change size of your element
  • Backspace / Click any where in the game - Stop controlling an element.
  • Element can be selected by clicking it once.

Outputs:-
Once finished creating a project and its time for you to use it. You can use the export command as mentioned above. After you see the message that the map has been outputted successfully, you can go into /scripts/Client Script/ and here you will find a .nut file with the same name as your project with all the codes inside.

Credits:-
  • Doom_Kill3R - Map Editor

Download Latest Version:-



[Spoiler=ARCHIVE - OLD VERSIONS]
v1.0


v1.1

[/Spoiler]

Changelog:-

Code: [Select]
-    Changelog - v1.1
-    ► Fixed AddChild bug.
-    ► Fixed the game crash while adding child.

The Video explains everything. How to use it :-


How to install the editor :-


~ Happy Editing!
~ Regards, Anik!

Pages: [1]