Author Topic: [FIXED] Kill Command  (Read 938 times)

So I have this kill code, it's supposed to kill the player and then chat the players name and has been forcekilled. The only problem is that it doesn't chat out the players name, just has been forcekilled.

Code: [Select]
function servercmdKill(%client, %target)
{
    if(!%client.isAdmin)
        return;
    if(isObject(%player = findClientByName(%target).player))
        %player.kill();
MessageAll('',"\c3" @ %player.name SPC "\c6has been force killed.");

}
« Last Edit: February 13, 2014, 03:44:18 PM by Czar »

try %player.client.name
since there is no name variable on the player, it's on the client

try %player.client.name
since there is no name variable on the player, it's on the client
%player.client.getplayername(); (i think thats the function name) is the preferred method


Also you need brackets around the two lines after the if, otherwise it will always execute the second line
You can get away with not using brackets only if theres only one line you need inside the if, like the previous one
« Last Edit: February 13, 2014, 09:53:34 AM by Headcrab Zombie »

%player.client.getplayername(); (i think thats the function name) is the preferred method


Also you need brackets around the two lines after the if, otherwise it will always execute the second line
You can get away with not using brackets only if theres only one line you need inside the if, like the previous one
I prefer %client.name
try %player.client.name
since there is no name variable on the player, it's on the client
This would be silly to do, as you already have the %client variable.

I prefer %client.name
There was an official notice from Badspot somewhere (patch notes or dev thread i believe) that said something to the effect that getplayername() should be used and that client.name is only being kept for backwards compatibility

This would be silly to do, as you already have the %client variable.
%client is the client calling the command, not the client its being called upon, which is the name that is needed
The client being called upon is never actually defined, it goes straight from name to player

You could also %player.getShapeName() I think as well.

You could also %player.getShapeName() I think as well.
Yeah, but...why?
It just seems silly

So far none of them have worked, they just chat " has been killed." except for jes00, it chatted the name of the person who commenced the forcekill command.

You should save the result of findClientByName(%target) instead of just immediatelly getting .player from it and use .getPlayerName() on it.

So would this work?

Code: [Select]
function servercmdKill(%client, %target)
{
    if(!%client.isAdmin) return;
    if(%target.isObject)
{
%player = findClientByName(%target)
MessageAll('',"\c3" @ %player.player.name SPC "\c6was force killed.");
                %player.player.kill();
}
MessageAll('',"\c3" @ %player.name SPC "\c6has been force killed.");

}

...no, thats even more broken.
Like, way more.

1. Revert back to the code in OP
2. Put opening bracket before the kill, and closing bracket after the messageall
3. In the messageall, change %player.name to %player.client.getPlayerName()


Preferably do what Port said, but focus on making it work first

...no, thats even more broken.
Like, way more.

1. Revert back to the code in OP
2. Put opening bracket before the kill, and closing bracket after the messageall
3. In the messageall, change %player.name to %player.client.getPlayerName()


Preferably do what Port said, but focus on making it work first

Thank you
I gotta listen more...