[Console]Commands

Started by Xmair, Sep 14, 2015, 09:09 AM

Previous topic - Next topic

Xmair

Hey guys, Today I'm releasing a console commands snippet.
This is will be edited in the future.
First you need the console plugin by ysc.
Then, In your script add this.
function onConsoleInput( cmd, text )
{
if ( cmd == "chat")// Put this to onPlayerChat print(player.Name+" : "+text) so you can see messages from game and than answer them.
{
if (!text) print(cmd+" <Message>")
else
{
Message("[#00ff00]Console Admin :-[#ffffff]"+text)
EchoMessage("Console Admin :- "+text)//You may remove it if you don't have an echo.
print("Console Admin :- "+text)
}
}
else if ( cmd == "close" )
{
if ( !text ) print(cmd+" <Yes/No>")//For mistype.
else if ( text == "Yes" )
{
print("Shutting down server was successful!")
Message("[#00ff00]Server : [#ffffff]Server shutting down.")
ShutdownServer();
}
else if ( text == "No" )
{
print("Shutting down server was stopped.")
}
else print(cmd+" <Yes/No>")
}
else if ( cmd == "kick" )
{
if (!text) print("/kick <Name> <Reason>")
else
{
local plr = GetPlayer(GetTok(text, " ", 1 ) )
local reason = GetTok( text, " ", 2 NumTok( text, " " ) );
if (!plr) print("Player was not found.")
if (!reason) print("No reason was put in.")
else
{
Message("[#00ff00]Kick : [#ffffff]Console admin has kicked "+plr.Name+" from the server. Reason : "+reason)
plr.Kick()
EchoMessage("Console admin has kicked "+plr.Name+" from the server. Reason : "+reason)//You may remove it if you don't have an echo.
}
}
}
else if ( cmd == "exe")
{
if ( !text ) print("Usage /exe <code>" );
else
{
    try
{
local script = compilestring( text );
if(script)
{
print("Compiled "+text+"!")
script();
}
}
catch(e) print("Error:"+ e );
}
}
else if ( cmd == "cmds")
{
print("exe, chat, close, kick")
}
else print("Unknown command, Type cmds for commands.")
}
Functions.
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();
}
function GetPlayer( plr )
{
    if ( plr )
    {
        if ( IsNum( plr ) )
        {
            plr = FindPlayer( plr.tointeger() );
            if ( plr ) return plr;
            else return false;
        }
    else
        {     
            plr = FindPlayer( plr );
            if ( plr ) return plr;
            else return false;
        }
    }
    else return false;
}
That's all.
If you find any bug, Report that bug to me. But it's 100% tested.
Enjoy ;D

Credits to Boystang!

VU Full Member | VCDC 6 Coordinator & Scripter | EG A/D Contributor | Developer of VCCNR | Developer of KTB | Ex-Scripter of EAD

:P

looks nice i will try it
SLC is a good scripter but he always use bad words for abusing players :P

FinchDon

For any help and support Join #s-s at IRC for Help in Scripting
( For Newbies )

:P

#3
nice work thanx
SLC is a good scripter but he always use bad words for abusing players :P

Drake

Quote from: FinchDon on Sep 14, 2015, 11:04 AM
Quote from: xxkillerxx on Sep 14, 2015, 11:00 AMlooks nice i will try it

FacePalm.
Do you know the meaning of "facepalm"? lmao
*facepalm* again

KAKAN

Nice work, but its a bit easy, try making onEchoChat XD, that would be more useful(I guess)
oh no

luchgox

Strength does not come from wining.Your struggles develop your strengths.

KAKAN

oh no

luchgox

i did but not working correctly,or i might have posted in wrong sections
Strength does not come from wining.Your struggles develop your strengths.