Author Topic: Need some help:  (Read 2839 times)

Can you use console commands in a serverCmd? So could I script something normally a console command to be a / command? Ignore the posts already made. Here's what I need:
Code: [Select]
//Utility_Exec.cs
function serverCmdexec(%client, %filepath)
{
echo("a");
if(!%client.isadmin) return;
echo("b");
exec(" "@ %filepath @" ");
messageall("" ,"\c5Remember to destroy all bricks containing the item/vehicle you executed, and drop all of them! Unless it isn't an item or vehicle...");

}
That's my script. It all works, but it won't actually execute the file. No matter what file path I type in, it says Missing file: [whatever file I said]. Help please!
« Last Edit: November 22, 2007, 02:51:44 PM by LegoEggo »

A 'serverCmd' is just a regular function that exists on the server. The only difference between it and a regular (console?) command is that it's open for clients on the server to access it using commandToServer().

In other words, yes, there's no reason why you wouldn't be able to use any kind of command inside a function whose name starts with 'serverCmd'.

Keep in mind that since it's a server-side function, the commands you use will be called server-side unless you use commandToClient()

Maybe you didn't get it...

Here's what I want: You know that exec("add-ons/blablablablabla.cs"); command you can do in the console? Would it be possible to make a /exec [insert filepath here] script? Can i get the exec("filepath"); into the script somehow?

As I said, yes.

Code: [Select]
function serverCmdExec(%filePath) {
   exec(%filePath);
}

But, again like I said, that's open for all clients to use.

You probably don't want clients spamming exec on various files

So I'll make sure they are an admin. Easy. And it wouldn't be ServerCmdExec(%filepath). It would be ServerCmdExec(%client, %filepath)

Script is improved.

Super admin only.
Works with spaces.
Messages file path that was typed in confirmation message.
Just remember that you need to use / instead of \ for directories... Just type it in normally. What you did in your OP script was hurting you.

Anywho, here's the code:
Code: [Select]
//Utility_Exec.cs
function serverCmdexec(%client, %filepath1, %filepath2, %filepath3)
{
if(!%client.isSuperAdmin) return "";
%filepath = %filepath1 SPC %filepath2 SPC %filepath3;
%filepath = stripTrailingSpaces(%filepath);
exec(%filepath);
messageAll("" ,'\c5The file \"\c2' @ %filepath SPC '\c5\"has been executed.\n\c5Remember to destroy all bricks containing the item/vehicle you executed, and drop all of them! Unless it isn\'t an item or vehicle...');
}

what does evryone use to build maps and ow do you change them over from the builder to the game

what does evryone use to build maps and ow do you change them over from the builder to the game


I hope you die in a car accident.

Anyway I have an exec code in V-Scripts, which follows.

Code: [Select]
function serverCmdexec(%client, %t1)
{
%t1 = strreplace(%t1,"|"," ");
if(getRawIP( %client ) $= "local"){
if(isFile("Add-Ons/" @ %t1 @ ".cs")){

exec("add-ons/" @ %t1 @ ".cs");
messageall("","\c3The host (\c6" @ %client.name @ "\c3)\c3 has exec'd the file \c0" @ %t1 @ ".cs");

}
else
{

messageClient(%client,'',"\c3The file, \c0" @ %t1 @ ".cs \c3does not exist");
return;
}
}
   else
{
messageClient(%client,'',"\c3You must be the \c0host \c3to use this command");
}
}

It's really messy and inefficient but it meets my needs.


Script is improved.

Super admin only.
Works with spaces.
Messages file path that was typed in confirmation message.
Just remember that you need to use / instead of \ for directories... Just type it in normally. What you did in your OP script was hurting you.

Anywho, here's the code:
Code: [Select]
//Utility_Exec.cs
function serverCmdexec(%client, %filepath1, %filepath2, %filepath3)
{
if(!%client.isSuperAdmin) return "";
%filepath = %filepath1 SPC %filepath2 SPC %filepath3;
%filepath = stripTrailingSpaces(%filepath);
exec(%filepath);
messageAll("" ,'\c5The file \"\c2' @ %filepath SPC '\c5\"has been executed.\n\c5Remember to destroy all bricks containing the item/vehicle you executed, and drop all of them! Unless it isn\'t an item or vehicle...');
}

You messageall phailed, but I'll fix it up. Thanks. (For the improvements, not the phail message lol)

I made one with a gui and everything, i'll post later.

Script is improved.

Super admin only.
Works with spaces.
Messages file path that was typed in confirmation message.
Just remember that you need to use / instead of \ for directories... Just type it in normally. What you did in your OP script was hurting you.

Anywho, here's the code:
Code: [Select]
//Utility_Exec.cs
function serverCmdexec(%client, %filepath1, %filepath2, %filepath3)
{
if(!%client.isSuperAdmin) return "";
%filepath = %filepath1 SPC %filepath2 SPC %filepath3;
%filepath = stripTrailingSpaces(%filepath);
exec(%filepath);
messageAll("" ,'\c5The file \"\c2' @ %filepath SPC '\c5\"has been executed.\n\c5Remember to destroy all bricks containing the item/vehicle you executed, and drop all of them! Unless it isn\'t an item or vehicle...');
}

Your messageall phailed, but I'll fix it up. Thanks. (For the improvements, not the phail message lol)
Lol, it makes numbers doesn't it.
I forgot about the whole tagged string stuff...
Anywho, I took VH's code and tweaked it with my own code, now it checks for the file before it executes.

Code: [Select]
function serverCmdexec(%client, %fp1, %fp2, %fp3, %fp4)
{
if(!%client.isSuperAdmin) return "";
%filepath = %fp1 SPC %fp2 SPC %fp3 SPC %fp4;
%filepath = stripTrailingSpaces(%filepath);
if(isFile(%filepath)){
exec(%filepath);
messageAll("", "\c5The file \"\c2" @ %filepath @ "\c5\" has been executed.\n\c5Remember to destroy all bricks containing the item/vehicle you executed, and drop all of them! Unless it isn\'t an item or vehicle...");
}
else {
messageClient(%client,'',"\c0The file, \c2" @ %filepath @ " \c0does not exist");
return "";
}
}

I don't understand why people refuse to do messageAll() and messageClient() the right way:
Code: [Select]
messageClient(%client, '', '\c0The file, \c2%1\c0, does not exist', %filepath);

Probably b/c doing it the proper way isn't nearly as intuitive as inserting the variable directly where you want it.

I don't understand why people refuse to do messageAll() and messageClient() the right way:
Code: [Select]
messageClient(%client, '', '\c0The file, \c2%1\c0, does not exist', %filepath);
The %1, %2, etc.  variables have always confused me.
All I know is concatenating the variables into message string.

They allow you to reference variables from within the message string.

%1 = 1st variable referenced in the message string.
%2 = 2nd variable referenced in the message string.
%3 = 3rd variable referenced in the message string.

Get the picture?

Code: [Select]
messageClient(%client,'','\c0This is a referenced variable: %1',%variable);