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 (http://forum.vc-mp.org/?topic=387.0).
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
looks nice i will try it
nice work thanx
Nice work, but its a bit easy, try making onEchoChat XD, that would be more useful(I guess)
not working
Quote from: QW.jester on Apr 03, 2017, 03:51 AMnot working
You need to use this (http://forum.vc-mp.org/?topic=387.0) plugin from the Plugins board (http://forum.vc-mp.org/?board=13.0)
i did but not working correctly,or i might have posted in wrong sections