I have thought about different methods of fully modifying onPlayerCommand function in the past,
Sadly I have been dealing with a lot and kind of brain stumped. And can't really concentrate in scripting at this time
The concept is something like
function onPlayerCommand( player, cmd, text )
{
local argument = split(text, " ");
local text1 = argument[0];
local text2 = argument[1];
onAdminCommands( player, cmd, text1, text2);
}
function onAdminCommands( player, cmd, text1, text2)
{
//blah blah
}
Can someone point me in a direction where I will not be wasting my time with building and interesting command system that I can implement In a server project I am taking part on
You can store function pointers, why not take advantage of that?
Well that really was not the answer I was looking for Murdock,
But with creating a simple Ini system I was capable of running some test, When I get time to Correct the system, Maybe add much more to it I will perfect it, For now I am far to busy, If anyone has suggestions it would be highly thanked!
function onPlayerCommand( player, cmd, text )
{
local text1 = GetTok( text, " ", 1 ), text2 = GetTok( text, " ", 2 );
ProcessAdminCommands( player, cmd, text1, text2);
}
function ProcessAdminCommands( player, cmd, text1, text2)
{
if (cmd == "setadmin") {
if (!Astats[ player.ID ].Admin) {
MessagePlayer( "Unknown command!", player);
return true;
}
local num = text1.tostring(), iPlayer = GetPlayer( num ), bool = text2;
if (!text1 || !text2) {
MessagePlayer( "Usage: /setadmin [player.ID] [bool]", player );
return true;
}
if (!iPlayer) {
MessagePlayer( "This player is not connected", player);
return true;
}
if (!bool) {
MessagePlayer( "Usage: /setadmin [player.ID] [bool]", player);
return true;
}
if ( text2 == "true" || text2 == "false")
{
if (text2 == "true") bool = true;
else if (text2 == "false") bool = false;
Astats[ iPlayer.ID ].Admin = bool;
Message( "Administrator " + player.Name + " has set " + iPlayer.Name + " admin level to " +bool);
WriteIniBool( "Accounts.ini", player.Name, "Admin", Astats[ player.ID ].Admin);
}
else MessagePlayer( "Usage: /setadmin [player.ID] [bool]", player );
return true;
}
}
What's wrong with passing an array? For commands that require a longer text (Like a kick reason) your system will fail, whilst you can easily do an array.slice if you use an array.
I'm trying to remember how 'slice' works.
From what I remember using in the past was private messaging players,
And that output would be something like
local arguments = split(text, " ");
text = text.slice(arguments[0].len() + 1);
Maybe this is what you are referring to, If so I really do not see where this would be helpful,
I also really do not know how the system would fail?
I have created a few more commands and haven't really had issues so far
if (cmd == "skin")
{
if (!Pstats[ player.ID ].Vip)
{
MessagePlayer( "This command is for Vip accounts only!", player);
return true;
}
if (!text1)
{
MessagePlayer( "Skin: /skin [0-194]", player);
return true;
}
local num = text1.tointeger();
if (num < 0 || num > 194)
{
MessagePlayer( "Skin: /skin [0-194]", player);
return true;
}
MessagePlayer( "Skin: " + num, player);
player.Skin = num;
return true;
}
So if you could explain a little
@Thijn that would be helpful, I have a feeling you have a valid reason to this.
You have 2 text variables. There's no need for that.
The arguments that make the most sense are player, command, and arguments. That's all :P