Author Topic: Will this work?  (Read 1250 times)

ok, im trying to make an addon and...
EDIT:
just look at this
PM:
ok, so i am almost finished creating the script i set out to make happen, This is basically it, but when im done it wont KILL the players in the else category-

if i am right, this will check all players on the server and (just for now it will kill) non admins  and give a messageboxok to admins when someone says /killnonadmin.
am i right?
Function ServerCmdkillnonadmin();
{
  for(%i = 0; %i < clientGroup.getCount(); %i++)
  {
  %client = clientGroup.getObject(%i);
  if(%client.isAdmin || %C.isSuperAdmin || %c.isHost)
    {
    messageboxOK("There they go..."; "You were just saved by your administrative powers, congrats on still being here");
    }
  else
    {
    %player = %client.player;
    %player.kill();
    }
  }
}

well, its a start, but there some problems.

first:  all "serverCmd"  functions have the first argument as %client
so yours needs to say:  function ServerCmdkillnonadmin(%client)
  - 'Function' needs to be lowercased:  'function'
  -  no semicolon ;  at the end of a function

Now that you have the serverCmd following the correct pattern, your assign a value to variable %client inside your function.  While torque doesnt care if you do this, other languages will, and since you said your just learning, its a good idea to start learning good ways of coding.

So with that - you need to change:   %client = clientGroup.getObject(%i);
to use something other than %client.  try: %obj or %cl or something.

next thing I see is this line:
if(%client.isAdmin || %C.isSuperAdmin || %c.isHost)
   %client has a value (but we are changing the variable name)
   %C has no value
   %c also has no value
again with the "best practice"  %c and %C are the same as far as torque is concerned, but not all languages are that way, so keep things consistent, and use %C and %C or %c and %c

what I think you meant was this:
if(%client.isAdmin || %client.isSuperAdmin || %client.isHost)
   -- which will change when you rename %client to something else

Next is this line:
messageboxOK("There they go..."; "You were just saved by your administrative powers, congrats on still being here");

Torque will give you a syntax error on this.  Do some searching on the forums to find an example to see how its used.

Lastly
    %player = %client.player;
    %player.kill();

can be changed to:
    %client.player.kill();

does the same thing with less script.


Good stuff:
unlike a lot of posters, all your {} match, and your gramamar skills are working well.

thankyou. i do beleive i wll take that wonderful advice and now i will lock this. whats more, i have a question for you, and im going to PM you right away

thankyou. i do beleive i wll take that wonderful advice and now i will lock this. whats more, i have a question for you, and im going to PM you right away
please post your question in the thread so others can learn too

oh alright
i would like to know the command to disconnect a player from the server. would it be
%client.disconnect();?
or what? also...
« Last Edit: March 28, 2011, 09:50:42 PM by wizzlemanizzle »

Quote
Now that you have the serverCmd following the correct pattern, your assign a value to variable %client inside your function.  While torque doesnt care if you do this, other languages will, and since you said your just learning, its a good idea to start learning good ways of coding.

So with that - you need to change:   %client = clientGroup.getObject(%i);
to use something other than %client.  try: %obj or %cl or something.
what are you saying here? are you telling me NOT to use % client as what i query the server for? the cliet is what i need to affect later on i am pretty sure
« Last Edit: March 28, 2011, 08:41:29 PM by wizzlemanizzle »

what are you saying here? are you telling me NOT to use % client as what i query the server for? the cliet is what i need to affect later on i am pretty sure

you dont have to change the name of the variable -- its just a good idea.
you can also call it anything you want.  The pattern is do to this:
function serverCmdSomething(%client)
  {
   if (%client.isAdmin)
   ... do stuff ...

   messageClient(%client, '', "Stuff");
   ... do stuff ...
  }


now this pattern will work:
function serverCmdSomething(%client)
  {
   %client = <something> ;
   if (%client.isAdmin)
   ... do stuff ...

  %client = <somethingElse>;
   messageClient(%client, '', "Stuff");
   ... do stuff ...
  }
but its a really bad habit to get into.


Try something like this:
for (%i = 0; %i < clientGroup.getCount(); %i++)
  {
  %cl = clientGroup.getObject(%i);
  if(%cl.isAdmin || %cl.isSuperAdmin || %cl.isHost)

 

Red Guy? you still havent answered my other question...

oh alright
i would like to know the command to disconnect a player from the server. would it be
%client.disconnect();?
or what? also...

%client.delete();

make sure you don't do a %client.player.delete(); as this will glitch players out

also, next time you want to find something like this function out:
1. go into console
2. type trace(1);
3. perform the action that you want to find the function for
4. go back to console and as quickly as possible, type trace(0);
5. look up in console log and see which function lines match the function you're trying to find

suggestion: do it in single player, so you won't get all the stuff for connections and such

thanks again placid
you are a lifesaver

keeping this open for now incase i need something else

ahem, placid, i would like to thank you for youreffort to help me, but i must inform you that deleting the client prevents the player from joining any server until they restart blockland...
the command i was looking for ( I used trace();) is infact
disconnect();

What? No it doesn't.

Deleting the client object on a server does nothing to the player but disconnect them, and in fact the kick button does this exactly.

ahem, placid, i would like to thank you for youreffort to help me, but i must inform you that deleting the client prevents the player from joining any server until they restart blockland...
the command i was looking for ( I used trace();) is infact
disconnect();
this only works on yourself. deleting the client deletes their whole client's access to your server besides rejoining therefore making them leave. disconnect(); would disconnect yourself from the server. what you were doing was trying yourself. try hosting a server that your friend comes on and have him connect. trace his disconnection, he will be deleted.

Next is this line:
messageboxOK("There they go..."; "You were just saved by your administrative powers, congrats on still being here");

Torque will give you a syntax error on this.  Do some searching on the forums to find an example to see how its used.

commandToClient(%client,'messageBoxOK',"Title","Text goes here.");