Author Topic: Is this script written correctly?  (Read 582 times)

I recently took a scripting class, and was taught how write a /kill command script. This is what I got:

Code: [Select]
function serverCmdKill(%c,%n)
{
    findClientbyname(%n);
    if(%c.isAdmin && !%n.isAdmin)
    {
       %n.player.kill();
    }
else
    {
      messageClient(%c,'',"You are not admin, you cannot kill this player");
    }
  }

Is that written right?
« Last Edit: June 26, 2010, 10:07:09 PM by Parallel »

%n is just a string.
It makes no sense.

%n is just a string.
It makes no sense.
I was told %c is the client and %n is the victim.

%c is sent as the person who typed the command's client, but %n is just a string of letters.

%c is sent as the person who typed the command's client, but %n is just a string of letters.
Would %player work as the victim instead of %n?

And was it spaced properly?

I'm assuming you didn't get the spacing part very much..
oo, found error in what i taught lawls

Code: [Select]
function serverCmdKill(%c,%n)
{
    findclientbyname(%n);
    if(%c.isAdmin && !%n.isAdmin)
    {
        %n.player.kill();
    }
    else
    {
        messageClient(%c,'',"You are not admin, you cannot kill this player.");
    }
}

Wrong.
%n is still a string.

Needs more %n = findClientByName(%n);

Code: [Select]
function serverCmdKill(%c, %n) {
    %n = findclientbyname(%n);
    if(%c.isAdmin && !%n.isAdmin)
        %n.player.kill();
    else
        messageClient(%c, '', "You are not admin, you cannot kill this player.");
}

That's better...

Would %player work as the victim instead of %n?

And was it spaced properly?
you can name it what ever you want as long as you are consistent with that name and findclientbyname(%n); returns another value so you have to assign it to another variable
like: %n = findclientbyname(%n);