Author Topic: Trying to create an autokill script, getting errors...  (Read 1856 times)

exec("Add-Ons/Gamemode_Slayer");

function serverCmdAutoKill(%client, %target) {
  if(!isObject(%target)); {
    if(!isAdmin(%client));
    commandToServer('autokill', %target); {
      findClientByName(%target).player.kill(onRoundStart);
    }
  }
};

Can anyone point out the issues here?

EDIT: I want to have players killed on the start of a Slayer mini-game's round. I have no idea what I'm doing here.
« Last Edit: June 29, 2015, 02:12:30 AM by blood.fm »


seriously, did you learn how to write scripts in torque or you just guessed because this really seems like guesswork.
you should learn the syntax for those functions and what they do.
start by writing a detailed description of what you want to do in this thread and somebody with more knowledge than me might help you
« Last Edit: June 29, 2015, 02:42:23 AM by Klarck »

The issues causing it from being technically functional?

  • You're using ; after the main part of an if statement. If statements should not have any ; themselves
  • Your admin check (Have you defined the isAdmin function, by the way? Perhaps you meant %client.isAdmin?) does not wrap its entire expression in braces.
  • You're wrapping the actual kill line in braces when there is no statement that would allow for braces there.
  • You have a ; after the function implementation

The general issues?

  • You are trying to execute a folder/archive. You need to specify the actual .cs file.
  • You are checking if the name of the player to kill is an object..?
  • You are only allow non-admins to force kill players
  • You are making the server send a command to the server
  • .kill() does not take an argument like that (unless Slayer adds one)
  • You are not checking if the player is alive in the first place

The issues causing it from being technically functional?

  • You're using ; after the main part of an if statement. If statements should not have any ; themselves
  • Your admin check (Have you defined the isAdmin function, by the way? Perhaps you meant %client.isAdmin?) does not wrap its entire expression in braces.
  • You're wrapping the actual kill line in braces when there is no statement that would allow for braces there.
  • You have a ; after the function implementation

The general issues?

  • You are trying to execute a folder/archive. You need to specify the actual .cs file.
  • You are checking if the name of the player to kill is an object..?
  • You are only allow non-admins to force kill players
  • You are making the server send a command to the server
  • .kill() does not take an argument like that (unless Slayer adds one)
  • You are not checking if the player is alive in the first place
What the hell...

What should I use to learn TS, as everything I've read about appears to be disfunctional...?

arent there some tutorials somewhere on the forums?
if you have no friends that are good scripters you can just look at addons and try to learn from them.


http://forum.blockland.us/index.php?PHPSESSID=7qltnoaa3equgl20akp3kdmg86&topic=20754.0
literally the topmost topic in the coding help section
i don't think linking an apendix is going to help a beguiner learn what's going on

here is the link to the official coding resources thread http://forum.blockland.us/index.php?topic=214415.0 (at the top it has a quick guide to some primary features in touredscript), and if you haven't done any programming before, use codecademy and learn some basic javascript, it'll help you get a hang of the syntax, which seems to be the main issue that you're having here

function serverCmdAutoKill(%client, %target)
  if(%client.isAdmin) { //dunno if i'm right here
    onServerCmd('autokill', %target) //i want this to function when a player does /autokill command
    if %target.isObject.player.kill(); // this *should* check to see if the player is an object, what does an object dignify anyway?
}

Ah, so I did it again. I have no idea what I'm doing, so feel free to point out my mistakes as assholish detailed as possible. Everything is explained in the comments.
 

The /autokill command triggers the entire function serverCmdAutoKill(%client, ...) { *code that's executed* }


Edit:
I'll just write out the function and I want you to learn from it.
Code: [Select]
function serverCmdAutoKill(%client, %name)
{
if(%client.isAdmin)
{
%target = findClientByName(%name);
if(isObject(%target.player))
{
%target.player.kill();
return;
}
else
{
//better let them know about what went wrong
return;
}
}
//better let them know about what went wrong
}

I want you to tell me what you think each part of this does and I'll correct you if needed.
« Last Edit: June 29, 2015, 08:13:14 AM by Dannu »

Whenever you check for isAdmin, it's a good idea to also check for || .isSuperAdmin. The default game will always set the former when the latter is set, but there's nothing to stop some genius add-on maker from setting isSuperAdmin and not setting isAdmin

Whenever you check for isAdmin, it's a good idea to also check for || .isSuperAdmin. The default game will always set the former when the latter is set, but there's nothing to stop some genius add-on maker from setting isSuperAdmin and not setting isAdmin
In that case you should get the creator to fix his add-on and not support the bad practice

In that case you should get the creator to fix his add-on and not support the bad practice
It's amazing how often you see this in practice. We need to write up some standards and then we get the satisfaction of calling scripts ill-formed.


function serverCmdAutoKill(%client, %name) // the function
{
   if(%client.isAdmin) // does a check to see if the initiator is admin
   {
      %target = findClientByName(%name); // finds the target by his/her alias
      if(isObject(%target.player)) // checks to see if the player is alive
      {
         %target.player.kill(); // kills the target player
         return; // not exactly sure what this does, but it might just be an end statement???
      }
      else // if the player cannot be found alive
      {
         //better let them know about what went wrong // not sure what you want me to do here or below
         return;
      }
   }
   //better let them know about what went wrong
}

all of my answers are in the code

H3

return; // not exactly sure what this does, but it might just be an end statement???
The return; statement stops the code from running, whilst allowing the function to return data.

When you call a statement such as this:
%target = findclientbyname(%name);

What you first need to know is that findclientbyname itself, is a function. If I were to guess what the code looked like, it would look like this:
Code: [Select]
function findClientByName(%name)
{
for(%a=0;%a<ClientGroup.getCount();%a++)
{
%b = ClientGroup.getObject(%a);
if(strStr(%b.name, %name) >= 0)
return %b;
}

return false;
}
Disclaimer: I'm not sure if findClientByName is at all written in torque script - it might be written in the c++ side of the engine.

When you use return, you can also attach any/some sort of data (usually boolean) to return with it. Here are some samples of returning data:
Code: [Select]
return; // returns nothing, used to terminate the current code being ran.
return true;
return false;
return 100-50;
return %a-%b+c;
return %string;
return %word1 SPC %word2 SPC %word3;
return strLen("THIS IS A STRING");

Now back to the %target = findclientbyname(%name); line. %target is a variable that will now hold the value of what the function (findClientByName) had returned. In this case, it's the client object that the player is connected to.


The return statement is widely used upon all (I think) programming. In torque script you can use it to your own use like:

Code: [Select]
function minus(%a, %b)
{
return %a - %b;
}

function main()
{
%blah = 9;
%what = 5;
%result = minus(%blah, %what);

echo(%result);
// '4' is what should be echo'd in console.
}

And a little further advanced, you can use return in a recursive manner to create another kind of loop:
Code: [Select]
function getOneHundred(%count)
{
if(getRandom(0, 100) != 100)
return %count;
else
return getOneHundred(%count+1);
}
This will run (infinitely) until getRandom(min, max); generates '100' as a random number. In the event that it doesn't generate '100', it will call itself again to generate it (thus again.. infinitely). Also, while it's doing that, I'm making it pass an argument of %count to keep track of how many times it is calling itself. That way I can see how many attempts it needs for it to roll '100'.


I probably forgot to cover some other stuff. If anyone else has anything to add on, feel free to do so.
« Last Edit: June 30, 2015, 12:46:39 AM by H3 »