Blockland Forums > Modification Help

Server commands

Pages: << < (2/3) > >>

phflack:


--- Code: ---function serverCMDquack(%a, %b, %c, %d, %e)
{
echo(quack);
}

--- End code ---
and

--- Code: ---function serverCMDquack()
{
echo(quack);
}

--- End code ---
would do the same thing, /quack would echo quack, so would /quack 1 2 3 4 5

takato14:

I realize this. I meant,


--- Code: ---function blahblah(%whatever)
{
      if(--What do I put in here...--)
      {
      }
}

--- End code ---
...to check what has been typed after /nuke? (I.E.: "/nuke yes")

I tried experimenting myself, and did this:

--- Code: ---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!");
}
}

--- End code ---
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?

Headcrab Zombie:

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: ---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!");
}
}

--- End code ---

Or you could make it toggle between on and off just by doing /nuke :

--- Code: ---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!");
}
}

--- End code ---


takato14:

Thanks, that works.

Now, by using that function, I should be able to control this:

--- Code: ---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);

}


--- End code ---
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.

Destiny/Zack0Wack0:


--- Quote ---if(!$nukesAllowed = 1)

--- End quote ---
This is setting the variable, rather then checking it. If you want to check if it's off just use

--- Code: ---if(!$nukesAllowed)

--- End code ---
or

--- Code: ---if($nukesAllowed == 0)

--- End code ---
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);

--- End quote ---
unMountImage takes a mount slot, not an image. So it should be

--- Code: ---%obj.unMountImage(0);

--- End code ---
to unmount the image in the hand.

Pages: << < (2/3) > >>

Go to full version