Author Topic: Targetting player with servercmd?  (Read 2465 times)

Hey,
lets say I want to make a script to forcekill a player. I know enough TS to make that with ease, except I am not sure how to make it kill the specified player. For example, /kill x- with forcekill x is a player's name, and I want it to kill that player.
I am not actually looking for a forcekill script, I just need to know how to target a player.
I think %victim is a variable used?

If you say /asdf a b c d e f then it will call the function serverCmdAsdf(%client, %a, %b, %c, %d, %e, %f) with variables %a through %f as "a" through "f". Each word after the slash command is put into a parameter.

Using this, you can define a %target variable in the serverCmd, then use /whatever TargetName to put "TargetName" into %target.
%target would then be a string of the target's name, not the target itself. To find the target, you use findClientByName with %target as the parameter, and it will return the client object, from which you can use .player to find the player object to kill (if there is one).


An additional note: Variable names do not matter. %victim doesn't magically become the target. You could do %victim = 3.14159; or %victim = findClientByName(%target); ; it doesn't matter that it's called victim, all that matters is what's inside of it. However you should keep your variable names relevant to what they're storing, so its easier for yourself and other people to understand.
« Last Edit: September 03, 2014, 07:56:53 AM by boodals 2 »

so all i need to do is servercmdasdf(%targetname) { %targetname.player.kill(); } ?

or do i do %a = %targetname

« Last Edit: September 03, 2014, 08:06:07 AM by -Setro- »

so all i need to do is servercmdasdf(%targetname) { %targetname.player.kill(); } ?

or do i do %a = %targetname
Neither.

serverCmdDoThis(%client, %target) { %target = findClientByName(%target); %target.player.kill(); }
« Last Edit: September 07, 2014, 08:02:52 PM by jes00 »


serverCmdDoThis(%client, %target) { %target = findClientByName(%target); %target.player.kill(); }

headcrab is correct.

the first parameter of any server command is the client calling it.

To directly answer your question: to get a client object from a name, use findClientByName( name ). To get a client object from a BL_ID, use findClientByBL_ID( BL_ID ). Then, to get a player from a client object, reference the .player variable.

E.g.
findClientByName("Trinick").player.addVelocity("0 0 10");

To add parameters to a serverCmd, simply define them in the function definition. Each word after the /command will be put into a different variable.

E.g.
function serverCmdTargetPlayer(%client, %playerName) { findClientByName(%playerName).player.addVelocity("0 0 10"); }
« Last Edit: September 06, 2014, 04:23:03 PM by $trinick »

You should also throw a couple if statements in there to prevent bad things from happening and not to mention it's good practice, as you're new to TS. Maybe check if the findClientByName function actually returns a client object? Maybe after that, check if the client actually has a player object? Etc.

serverCmdDoThis(%client, %target) { %target = findClientByName(%target); %target.player.kill(); }
Woops.

I think %victim is a variable used?
It doesn't really matter what you name the variable.
function serverCmdKill(%client, %target)
{
    findClientbyName(%target).player.kill();
}

will do the exact same thing as making all the %targets as %victims. It doesn't matter at all - I could name it %dinosaurGold if I wanted to.

It doesn't really matter what you name the variable.
function serverCmdKill(%client, %target)
{
    findClientbyName(%target).player.kill();
}

will do the exact same thing as making all the %targets as %victims. It doesn't matter at all - I could name it %dinosaurGold if I wanted to.
Stated in the first post.

The whole servercmd input is a huge subject. I learned exactly what everything was for, before i started doing anything with them

Don't forget serverCmd always has the client that called it as the first argument.

Also it would be good practice to put admin checks on the person calling the serverCmd

so y'know it doesn't get abused