Author Topic: Need some help with a couple more things  (Read 1076 times)

Sorry about multiple topics, I really want to learn TS.
1. How do I add admin checks to functions? Something like if(%client.isAdmin ==1); return; ?
2. Can someone give me an example of a function in a package? Like, some useless code to show how I'm supposed to use packages?
3. Are there any client-sided variables for the computer specs at the top of console.log?
4. Say I wanted a servercmd to use the variable %client and then use %client.name.
How can I use announce(); to say the client's name, then some custom words after it, and set the entire thing, including the client's name, to a color?
5. What function or command brings up that little color chart for codes like /c1 for example? It says 0123456 but all of the numbers are in different colors?
6. Is there a list for all of blockland's default functions lying around somewhere?
7. How can I create loops in functions? Can I somehow stop the loop?
8. How do I properly use schedule(); ?

if(%client.isAdmin)
If the %client.isAdmin == 1 (If you don't put anything it automatically checks if it's 1) then run the code.


package example
{
   function exampleFunction()
   {
      doExampleThings();
   }
};
activatePackage(example);

Activating the package is optional, but it will not activate by itself, so you don't have to put that there.

function serverCmdExample(%client)
{
   announce("\c6" @ %client.name @ "\c3example message.");
}

I'm guessing you know how to use \c but if you don't type /colortest ingame and use \cNumberHere. Any text after that is the color that you selected. <color:aaaaaa> works as well. %client is automatically defined as the player who uses the serverCmd so in this case you don't have to define it so someone.

serverCmdColorTest

function ball()
{
    cancel($ballSchedule);
    echo("ball");
    $ballSchedule = schedule(1000, 0, "ball");
}

If you put the schedule in a global variable you can use cancel($variableNameHere); to stop it later on in a different function or whenever. Schedule is used like this
schedule(time, scheduleID, "function to call");
Most people just use 0 as the ID.

Answered the ones I could, I dunno about 3 and 6.

1. if(!%client.isAdmin) return; - return if the client is NOT (!) an admin.
2. An easy example of this and a commonly used one is parenting and package GameConnection::onDeath, like so:

package deathOverride {

function GameConnection::onDeath(%killed, %killerPlayer, %killer, %damageType, %a)
{
    Parent::onDeath(%killed, %killerPlayer, %killer, %damageType, %a);
    echo(%killer.getPlayerName() SPC "killed" SPC %killed.getPlayerName());
}

};

activatePackage(deathOverride);

3. No idea
4. You could use a serverCmd with a bunch of arguments and to get the person's name use %client.getPlayerName(), and then loop through all of the arguments and work from there.
5. serverCmdColortest. Also, it's \c1, \c2, etc. - not /c1.
6. dumpConsoleFunctions(); with no extra addons running.
7. You can use for loops or while loops: http://docs.garagegames.com/torque-3d/official/content/documentation/Scripting/Simple/Loops.html
8. For scheduling something normally with arguments:
schedule(time, ID, function, argument, argument, argument, ...); - I believe in most cases you would want to use 0 for the ID.
And as for calling a schedule on an object (like fxDTSBrick::setColor - changing a brick's color):
%brick.schedule(time, function, argument, argument, ...);

%client is automatically defined as the player who uses the serverCmd so in this case you don't have to define it so someone.
False - the client is the client, not the player. To get the player you have to use %client.player;.
« Last Edit: September 03, 2014, 10:01:52 PM by Cruxeis »

schedule(time, scheduleID, "function to call");
Most people just use 0 as the ID.

I believe the second variable will continue the schedule if an object exists, for example
schedule(100,serverConnection,disconnect);

Also, just type in get and keep hitting tab in the console, there are different functions for those.
Like getOSLong, getOSShort, getCPUMHz, getCPUName, getProfilePath, etc.

Schedules aren't loops, wtf are you talking about?
edit to fix that, meant schedule.
« Last Edit: September 03, 2014, 10:04:39 PM by Pah1023 »

I believe the second variable will continue the loop if an object exists, for example
schedule(100,serverConnection,disconnect);

Also, just type in get and keep hitting tab in the console, there are different functions for those.
Like getOSLong, getOSShort, getCPUMHz, getCPUName, getProfilePath, etc.
Schedules aren't loops, wtf are you talking about?

[/tt]False - the client is the client, not the player. To get the player you have to use %client.player;.
I didn't mean he was the actual player object, I just meant it was the guy who used the command.

I didn't mean he was the actual player object, I just meant it was the guy who used the command.
I know that you know that - I was clarifying for Setro because there's a player and a client, and that the client that called the command isn't the player object.

1. How do I add admin checks to functions? Something like if(%client.isAdmin ==1); return; ?
Really close. Like this:
Code: [Select]
function serverCmdDoThis(%client)
{
    if(!%client.isAdmin)
    {
        return;
    }

    talk("Client is admin.");
}
This server command can now only be used by admins. The ! before %client.isAdmin checks if the variable is false. If you want it to be super admin only, just use %client.isSuperAdmin. Keep in mind that a super admin will have both variables set to 1.
2. Can someone give me an example of a function in a package? Like, some useless code to show how I'm supposed to use packages?
Code: [Select]
function doStuff()
{
    echo("I'm so awesome");
}
Code: [Select]
package MyAwesomePackage
{
    function doStuff()
    {
        parent::doStuff();

        echo("And no one else is.");
    }
};
activatePackage(MyAwesomePackage);
3. Are there any client-sided variables for the computer specs at the top of console.log?
Don't think so. You can use the isWindows(); function to find out if the client is running a windows computer or not though.
4. Say I wanted a servercmd to use the variable %client and then use %client.name.
How can I use announce(); to say the client's name, then some custom words after it, and set the entire thing, including the client's name, to a color?
There are connectors you can use to insert a variable into a message.
@ Is just a plain connector.
SPC Connects the variable, with a space.
TAB Connects the variable, with a tab.
NL Connects the variable with a new line.

So announce(%client.name SPC "is cool."); Would end up as "jes00 is cool.". announce(%client.name @ "is the best"); would end up as "jes00is the best". announce(%client.name TAB "is awesome"); would end up as "jes00   is awesome". And announce(%client.name NL "is a poodle"); would be "jes00
is a poodle". You can also insert the variable into the middle of the message and use two different connectors like this: announce("This guy:" SPC %client.name @ ". Has 30 dolla dolla bills"); would end up as "This guy: jes00. Has 30 dolla dolla bills".
5. What function or command brings up that little color chart for codes like /c1 for example? It says 0123456 but all of the numbers are in different colors?
Just say /colorTest on any server you're an admin on.
6. Is there a list for all of blockland's default functions lying around somewhere?
Put dumpConsoleFunctions(); in the console.
7. How can I create loops in functions? Can I somehow stop the loop?
What kind of loops? What do you mean?
8. How do I properly use schedule(); ?
I've now given up on this post, as other people replied to the topic while I was typing. Who knows though. Maybe you'll get something out of this post the other didn't mention.

Sorry about multiple topics, I really want to learn TS.
1. How do I add admin checks to functions? Something like if(%client.isAdmin ==1); return; ?
if(%client.isAdmin() || %client.isSuperAdmin) { do stuff }
2. Can someone give me an example of a function in a package? Like, some useless code to show how I'm supposed to use packages?
packages are used to add code to functions without overwriting them. for example, if i want to say hi to the player when they join, I can do

package joinPkg {
  function GameConnection::AutoAdminCheck(%this) // called when the client joins the server
  {
    messageClient(%client,'',"Hi!");
  }
};
activatePackage(joinPkg);

3. Are there any client-sided variables for the computer specs at the top of console.log?
im pretty sure there's functions to get information about the client's computer
4. Say I wanted a servercmd to use the variable %client and then use %client.name.
How can I use announce(); to say the client's name, then some custom words after it, and set the entire thing, including the client's name, to a color?
you can do this by concatenating strings. @ is the concatenation operator
for example,
announce(%client.name @ " is cool.");

5. What function or command brings up that little color chart for codes like /c1 for example? It says 0123456 but all of the numbers are in different colors?
there probably is one but i dont know it off the top of my head. try putting this in console:
NewChatSO.AddLine("\c00\c11\c22\c33\c44\c55\c66");

6. Is there a list for all of blockland's default functions lying around somewhere?
http://bldocs.nullable.se/html/
7. How can I create loops in functions? Can I somehow stop the loop?

for(%i=0;%i<10;%i++) {
  echo(%i); // %i is the number of iterations
  if(%i == 5) { // if the number of iterations is 5
    break; // exit the loop
  }
}

8. How do I properly use schedule(); ?
schedule(1500,0,announce,"message");
schedule(time,0 unless you're calling from an object,function,arg1,arg2);


mfw 6 new replys have been posted

i spent like 20 minutes typing this ._.

Don't think so. You can use the isWindows(); function to find out if the client is running a windows computer or not though.
Code: [Select]
echo("Blockland v" @ $Version @ " build " @ getBuildNumber());
echo("Module Directory: " @ getModuleDirectory());
echo("Profile Path: " @ getProfilePath());
echo("Total Ram: " @ getTotalRam() @ " MB");
echo("OS: " @ getOSLong());
echo("");
Actual yes, they do exist.