Author Topic: Server commands  (Read 603 times)

Would this be the proper syntax to create a server command? Please note I am somewhat new to scripting.That means dont be a prick, just tell me if Im doing it wrong.

Code: [Select]
function ServerCMDNuke(%this, %slot, %obj)
{
if(%obj.client.issuperadmin)
{
case yes
{
%NukesAllowed = 1;
messageAll('',"\c2Nukes are now allowed.");
}
case no
{
%NukesAllowed = 0;
messageAll('',"Nukes are no longer allowed.");
}
}
else
{
%obj.messageClient('',"\c2Only SuperAdmins may use this command!");
}
}

Note that I am almost entirely guessing this is how I would do it(I've taken JavaScript before, so I have some of an idea of what Im doing.)

EDIT: Tested, and I failed. So, how would one do this correctly?
« Last Edit: January 02, 2011, 12:35:04 AM by takato14 »

not sure how the case yes/no would work, i'd just have a nested if

not sure how the case yes/no would work, i'd just have a nested if
Thats what I was going to do, but I didnt know what I needed to put into the parenthesis. Do you?
« Last Edit: January 02, 2011, 12:51:07 AM by takato14 »

well, for a server command, i think you can put anything in them :D

well, for a server command, i think you can put anything in them :D
What's something that always returns true? x_x

Also, could you give an example? Remember, Im sorta new to this.
« Last Edit: January 02, 2011, 12:53:56 AM by takato14 »

Code: [Select]
function serverCMDquack(%a, %b, %c, %d, %e)
{
echo(quack);
}
and
Code: [Select]
function serverCMDquack()
{
echo(quack);
}
would do the same thing, /quack would echo quack, so would /quack 1 2 3 4 5

I realize this. I meant,

Code: [Select]
function blahblah(%whatever)
{
      if(--What do I put in here...--)
      {
      }
}
...to check what has been typed after /nuke? (I.E.: "/nuke yes")

I tried experimenting myself, and did this:
Code: [Select]
function ServerCMDNuke(%this, %slot, %obj, %item)
{
if(%obj.client.issuperadmin)
{
if(%item == "yes")
{
%NukesAllowed = 1;
messageAll('',"\c2Nukes are now allowed.");
}
if(%item == "no")
{
%NukesAllowed = 0;
messageAll('',"Nukes are no longer allowed.");
}
}
else
{
%obj.messageClient('',"\c2Only SuperAdmins may use this command!");
}
}
Which doesnt error out, but also doesnt work when I say /nuke yes(or no). It doesn't change %nukesAllowed, and it doesnt messageAll. Help?
« Last Edit: January 02, 2011, 01:12:07 AM by takato14 »

The first argument for a serverCmd is always the client calling it, the next are specified by the next words when the client calls it in chat
For comparing strings, use $=, not ==
variables beginning with % are local variables, and are only used within that function and are gone once the function returns. If you want a variable to be accessible from any function or after the function returns, use a global variable, beginning with $

Code: [Select]
function serverCmdNuke(%client,%var)
{
if(%client.isSuperAdmin)
{
if(%var $= "yes")
{
$NukesAllowed = 1;
messageAll('',"\c2Nukes are now allowed.");
}
if(%var $= "no")
{
$NukesAllowed = 0;
messageAll('',"Nukes are no longer allowed.");
}
}
else
{
messageClient(%client,'',"\c2Only SuperAdmins may use this command!");
}
}

Or you could make it toggle between on and off just by doing /nuke :
Code: [Select]
function serverCmdNuke(%client)
{
if(%client.isSuperAdmin)
{
if($NukesAllowed)
{
$NukesAllowed = 0;
messageAll('','\c2Nukes are no longer allowed.");
}
else
{
$NukesAllowed = 1;
messageAll('','\c2Nukes are now allowed.");
}
}
else
{
messageClient(%client,'',"\c2Only SuperAdmins may use this command!");
}
}

Thanks, that works.

Now, by using that function, I should be able to control this:
Code: [Select]
function DoomNukeImage::onMount(%this, %obj, %slot)
{
$nukesAllowed = 1; //1 for yes, 0 for no, changeable by below server command

if(!%obj.client.issuperadmin)
{
  messageclient(%obj.client,"","\c2You are not SuperAdmin!");
%obj.unMountImage(DoomNukeImage);

return;
    }
else
{
if(!$nukesAllowed = 1)
{
%obj.unmountImage(DoomNukeImage);
%obj.mountImage(1, FlopNukeImage);
}
}
Parent::onMount(%this, %obj, %slot);

}

by using the NukesAllowed variable, correct? If so, then I have a problem, because the script doesn't work as-is. (The "doomNukeImage" doesnt unmount) Also, if order matters, this script comes BEFORE the server command on the code line.

Quote
if(!$nukesAllowed = 1)
This is setting the variable, rather then checking it. If you want to check if it's off just use
Code: [Select]
if(!$nukesAllowed)
or
Code: [Select]
if($nukesAllowed == 0)
Also at the start you are setting $nukesAllowed to 1. Why? You're going to turn nukesAllowed on every time someone mounts the doomnukeimage. Remove that line.
Also,
Quote
%obj.unMountImage(DoomNukeImage);
unMountImage takes a mount slot, not an image. So it should be
Code: [Select]
%obj.unMountImage(0);
to unmount the image in the hand.

Ohhhh

Thanks. I hadnt noticed that I missed the second =. I already removed the other line, thinking it was causing it, but it wasn't, so yea.

EDIT: it was already == (I changed it earlier hoping to find the problem),  but changing it to !$NukesAllowed worked. Thanks for all the help, guys.
« Last Edit: January 02, 2011, 02:50:15 AM by takato14 »