Author Topic: Very simple kill command, need help  (Read 3038 times)

Obviously i'm very new to scripting, but if anyone can fix this for me, and tell me what i'm doing wrong, it'd be greatly appreciated
Code: [Select]
function servercmdkill(%client, %target)
{
  findclientbyname(%target);
  %target.kill();
}

I have also tried
Code: [Select]
function servercmdkill(%client, %target)
{
  findclientbyname(%target).kill();
}

and
Code: [Select]
function servercmdkill(%client, %target)
{
  findclientbyname(%target);
  %client.kill();
}
« Last Edit: September 23, 2012, 11:56:25 AM by kimbucktwo »

Code: [Select]
function servercmdKill(%client,%input)
{
  %Target = findclientbyname(%input);
  %Target.player.kill();
}

That's a very, very crude way of doing it.

Code: [Select]
function servercmdkill(%cl, %ta)
{
    if(!%cl.isadmin)
        return;
    findclientbyname(%ta).player.kill();
}

Code: [Select]
function servercmdKill(%client,%input)
{
  %Target = findclientbyname(%input);
  %Target.player.kill();
}

That's a very, very crude way of doing it.
Code: [Select]
function servercmdkill(%cl, %ta)
{
    if(!%cl.isadmin)
        return;
    findclientbyname(%ta).player.kill();
}

ahhh thank you both! i wasnt far off then, and is there a difference between using %cl and %ta than %client and %target?

ahhh thank you both! i wasnt far off then, and is there a difference between using %cl and %ta than %client and %target?
They're just names

They're just names

isn't %client more than a name? or can you put anything instead of %client in the parenthesis after a servercmd?

isn't %client more than a name? or can you put anything instead of %client in the parenthesis after a servercmd?
Your just giving a name to it,
You could name it anything you want but it's still the same value.

Your just giving a name to it,
You could name it anything you want but it's still the same value.

ahh okay, locking topic, thanks for help
« Last Edit: September 23, 2012, 01:59:37 PM by kimbucktwo »

i've added a bit more to it just for more practice, and there is a syntax error somewhere, but i cant find it

Code: [Select]
function servercmdkill(%client, %target)
{
  if(%target $= "")
  {
    messageclient(%client, '',"\c6No target specified.");
  }
  else
  {
    %killer = %client.player.getname();
    findclientbyname(%target).player.kill();
    messageclient(%client, '',"\c6" @ %killer "\c6 killed you.");
  }
}

%killer = %client.name;

Or just do that in your messageClient.

messageclient(%client, '',"\c6" @ %client.name"\c6 killed you.");

You should also replace
Code: [Select]
if(%target $= "")
  {
    messageclient(%client, '',"\c6No target specified.");
  }
with this:
Code: [Select]
if(!isObject(findClientByName(%target).player)){
     messageClient(%client, '', "Invalid target specified.");
     return;
}
Make sure to use findClientByName(%target) and not just %target.
« Last Edit: September 23, 2012, 02:11:17 PM by Scars75 »

You should also replace
Code: [Select]
if(%target $= "")
  {
    messageclient(%client, '',"\c6No target specified.");
  }
with this:
Code: [Select]
if(!isObject(%target.player)){
     messageClient(%client, '', "Invalid target specified.");
     return;
}

You should also replace
Code: [Select]
if(%target $= "")
  {
    messageclient(%client, '',"\c6No target specified.");
  }
with this:
Code: [Select]
if(!isObject(findClientByName(%target).player)){
     messageClient(%client, '', "Invalid target specified.");
     return;
}
Make sure to use findClientByName(%target) and not just %target.

ahhh okay thanks for that adjustment, however when i kill me it just says " killed you" without showing the name of who killed me,
heres my script

Code: [Select]
function servercmdkill(%client, %target)
{
  if(!isObject(findclientbyname(%target).player))
  {
    messageclient(%client,'',"\c6Invalid target specified.");
    return;
  }
  else
  {
    findclientbyname(%target).player.kill();
    messageclient(%client, '',"\c6" @ %client.player.getname @ "\c6 killed you.");
  }
}

you're calling the VARIABLE "getname" on the PLAYER


the player does not have this.

use this instead: messageclient(%client, '',"\c6" @ %client.getPlayerName() @ "\c6 killed you.");

it calls the METHOD (function) called "getPlayerName" on a client, which returns (lets you use) the name.

you're calling the VARIABLE "getname" on the PLAYER


the player does not have this.

use this instead: messageclient(%client, '',"\c6" @ %client.getPlayerName() @ "\c6 killed you.");

it calls the METHOD (function) called "getPlayerName" on a client, which returns (lets you use) the name.

ahhh it works! thanks for making that clear too, one last thing, why do we use "return;" at the end of some things?