Walking System (now tommy can walk like a civilian)

Started by Mohamed Boubekri, Jul 14, 2023, 09:10 PM

Previous topic - Next topic

Mohamed Boubekri

Hey everyone, i have made this simple script for roleplay servers especially, have fun!

How to use: if you want to walk keep pressing alt, and stop pressing it if you want to stop.
Server-side:
enum StreamType
{
    a1 = 0x01
    a2 = 0x02
}

function onClientScriptData( player )
{
    local stream = Stream.ReadByte();
    switch ( stream )
    {
        case StreamType.a1:
        {
        if (player.Vehicle) return;
        player.SetAnim(0,0);       
        }
        break;   
        case StreamType.a2:
        {
        if (player.Vehicle) return;
        player.SetAnim(0,2);       
        }
        break;               
    }
}
Client-side:
enum StreamType
{
    a1 = 0x01
    a2 = 0x02
}
alt <- KeyBind( 0x12 );
local walking=false;

function Script::ScriptProcess()
{
if (walking == true) {
SendDataToServer(StreamType.a1);
}
}
function KeyBind::OnDown(key)
{
if (key == alt )
{
walking = true;
}
}
function KeyBind::OnUp(key)
{
if (key == alt )
{
walking = false;
SendDataToServer(StreamType.a2);
}
}
function SendDataToServer( ... )
{
    if( vargv[0] )
    {
        local  byte = vargv[0],
                len = vargv.len();
               
        if( 1 > len ) Console.Print( "ToClent <" + byte + "> No params specified." );
        else
        {
            local pftStream = Stream();
            pftStream.WriteByte( byte );

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

Preview:


The system now is clean without any lag.
| What now ? | Not yet ! |
Morrocan:- [ 🇲🇦 ].

habi


H.a.S.a.N

Wow bro cool system
 :)   ;)

Mohamed Boubekri

Thank you friends, but I think that NewTimer Func cause lag in the server especially if the server fraught of players, so we all need to make effort to make the player capable to walk with a simple repeatedly function.
| What now ? | Not yet ! |
Morrocan:- [ 🇲🇦 ].

Mohamed Boubekri

#4
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.
| What now ? | Not yet ! |
Morrocan:- [ 🇲🇦 ].

PSL