Author Topic: Is my packaging script/code correct?  (Read 1622 times)

Code: [Select]
package admincheck
{
    function gamemode::admincheck(%client)
{
if(%client.isHost ==1)
{
messageClient(%client, "\c8 You are the Host!")
}
else if(%client.isSuperAdmin == 1)
{
messageClient(%client, "\c3 You are a Super Admin!")
{
else if(%cleint.isAdmin == 1)
{
messageClient(%client, "\c5 You are a Admin!")
}
else
messageClient(%client, "\c2 You are a regular Blockhead!")
}
parent::gamemode::admincheck(%client)
}
activate admincheck()

When someone gets on, it runs admin check and messages the client what it stat on the server is? - I'm aiming for that, sorry I'm a newbie. School has started so it's hard to work on torque, but I don't want to stop xD.
« Last Edit: August 20, 2014, 11:47:42 PM by chubaka452 »

Ugh my spacing is weird for some reason, I'll try to fix it.

*EDIT*
I think it's fixed now.
« Last Edit: August 20, 2014, 11:48:16 PM by chubaka452 »

You have one instance where you have two opening brackets. Make sure when you have an opening bracket, you also have a closing bracket. Another thing, the correct syntax for activating a package is activatePackage(packagename);. The correct arguments for messageClient would be: messageClient(%client, '', "msg");. Lastly, it's gameConnection referring to the client, not gamemode. Be sure that when calling a function, you have ; at the end of it. The correct function is gameConnection::autoAdminCheck and you need to return the parent, notice how it's being done below:


The correct version would be this:

//probably shouldn't use such a generic package name..
package admincheck
{
    function gameConnection::autoAdminCheck(%client)
    {
      %p = parent::autoAdminCheck(%client);
      
      if(%client.isHost)
      {
         messageClient(%client,'', "\c8You are the Host!");
      }
      else if(%client.isSuperAdmin)
      {
         messageClient(%client,'', "\c3You are a Super Admin!");
      }
      else if(%client.isAdmin)
      {
         messageClient(%client,'', "\c5You are a Admin!");
      }
      else
         messageClient(%client,'', "\c2You are a regular Blockhead!");
         
      return %p;
   }
};
activatePackage(admincheck);


Don't just copy and paste, look at the differences between the two. If you don't understand anything, let us know, we can help. Here's a little formatting guide since yours in kinda wonky: http://forum.blockland.us/index.php?topic=192083.0
« Last Edit: August 20, 2014, 11:56:26 PM by elm »

1. function gamemode::admincheck should be function gameconnection::autoadmincheck
2. .isHost is not defined by the game by default. There's several things you need to check to cover all cases of host joining, I don't remember all of them
3. messageClient takes three arguments, add a blank string between the current two you have (messageClient(%client,'msg'); becomes messageclient(%client,'','msg');
4. autoadmincheck is the function that gives clients admin, you don't know if they're admin (at least by checking .isAdmin or .isSuperAdmin) before that. Fix this by moving the parent call to the very first line of the function
5. In the parent call, the class the method is called on is left out. The value returned by the parent needs to be stored, so it can later be returned. Remember you also need to change admincheck to autoadmincheck to reflect #1. After all these, it becomes %r = Parent::autoadmincheck(%client); at first line inside the function, and return %r; as the last line inside the function
6. The closing bracket of the package definition needs a semicolon at the end
7. the last line should be activatepackage(admincheck);

Don't just copy and paste, look at the differences between the two.
If you want him to do this, then don't give him code that he can copy and paste, give him a list of things to fix as I did
« Last Edit: August 21, 2014, 12:02:07 AM by Headcrab Zombie »

If you want him to do this, then don't give him code that he can copy and paste, give him a list of things to fix as I did

Yeah, I'm pretty sure he doesn't understand half of what you're saying.


1. Okay I understand that.
2. Where can I learn to do that?
3. Okay, will fix later on.
4. I was iffy on that one, but I do understand ( will fix ) what that means haha.
5. Okay I understand that.
6. Rookie mistake.
7. Will do.

Half the points are just "this should be this"
But yeah I guess there's no problem is using that if he's stuck, but he should at least try to use what I gave him

2. Where can I learn to do that?
As I said, I don't remember all the things you need to check. if(%client.bl_id == getNumKeyID()) will cover most cases, but won't work for LAN or singleplayer

EDIT: Use this, grabbed from here http://forum.blockland.us/index.php?topic=231354.msg6574826#msg6574826
if(%client.isLocalConnection() || ($Server::LAN && $Server::Dedicated) || %client.getBLID() $= getNumKeyID())
« Last Edit: August 21, 2014, 12:20:02 AM by Headcrab Zombie »


package mondaytits // Define the package name Protip: Don't use generic names as they can conflict I suggest doing NameofAdd-on_GenericNamehere
{
codehere
}
activatepackage(mondaytits); // Activate package

NameofAdd-on_GenericNamehere
{
codehere
}
activatepackage(mondaytits); // Activate package
Wont work, you forgot the ; on the closing bracket.

EDIT: Use this, grabbed from here http://forum.blockland.us/index.php?topic=231354.msg6574826#msg6574826
if(%client.isLocalConnection() || ($Server::LAN && $Server::Dedicated) || %client.getBLID() $= getNumKeyID())
Shouldn't this be

if(%client.isLocalConnection() || ($Server::LAN && $Server::Dedicated) || %client.getBLID() == getNumKeyID())

because BL_ID and numKeyID are numerical values?

Shouldn't this be

if(%client.isLocalConnection() || ($Server::LAN && $Server::Dedicated) || %client.getBLID() == getNumKeyID())

because BL_ID and numKeyID are numerical values?
It'll still work with $= because they can be compared as strings, but using == might make it faster.