Author Topic: Host only command?  (Read 2735 times)

I am just learning how to script again. I was making a little practice script and I came past a problem I cannot solve bymyself.

Question: How can I make this script Host only?
Code: [Select]
function serverCmdKill(%client,%target)
{
if(%client.isAdmin == true && isObject(findclientbyname(%target)))
        {
                echo("serverCmdKill triggered by "@%client.name@" and was targetting "@findclientbyname(%target).name@"!");
                if(isObject(findclientbyname(%target).player))
                {
                        findclientbyname(%target).player.kill();
                }
        }
}

Replace %client.isHost with %client.BL_ID == getNumKeyID() and it'l be host only.

Okay. Do I replace BL_ID with my ID? or just leave it

Code: [Select]
function serverCmdKill(%client,%target)
{
if(%client.BL_ID == getNumKeyID() == true && isObject(findclientbyname(%target)))
        {
                echo("serverCmdKill triggered by "@%client.name@" and was targetting "@findclientbyname(%target).name@"!");
                if(isObject(findclientbyname(%target).player))
                {
                        findclientbyname(%target).player.kill();
                }
        }
}

Okay. Do I replace BL_ID with my ID? or just leave it

Code: [Select]
function serverCmdKill(%client,%target)
{
if(%client.BL_ID == getNumKeyID() == true && isObject(findclientbyname(%target)))
        {
                echo("serverCmdKill triggered by "@%client.name@" and was targetting "@findclientbyname(%target).name@"!");
                if(isObject(findclientbyname(%target).player))
                {
                        findclientbyname(%target).player.kill();
                }
        }
}
Just leave it. %client.bl_id symbolizes what the client's bl_id is, if you did %client.yourblid it wouldn't work.
You might want to use messageAll("serverCmdKill triggered by "@%client.name@" and was targeting "@%target@"!"); instead of that echo command. findClientbyName is not needed in the message function, just %target .

Code: [Select]
function serverCmdKill(%client, %target) {
    if(%client.bl_id == getNumKeyID() && isObject(findClientbyName(%target))) {
        messageAll("serverCmdKill triggered by "@%client.name@" and was targeting "@%target@"!");
        if(isObject(findClientbyName(%target).player))
        {
             %target.player.kill();
        }
    }
}
That should work, I fixed some stuff and shortened it.

I got some new code.

Code: [Select]
function GameConnection::isHost(%client)
{
if(%client.bl_id == getNumKeyID())
{
return true;
}
return false;
}


function servercmdCOMMAND(%client,%var)
{
    if(%client.isHost())
    {
//Client is host!
}
else
{
//Client is not host!
}
}

Would this be valid? I havnt tested it yet. im VERY busy

The top function would not work for LAN, and maybe dedicated servers

Can you fix it to make it work?

I got some new code.

Code: [Select]
function GameConnection::isHost(%client)
{
if(%client.bl_id == getNumKeyID())
{
return true;
}
return false;
}

function servercmdCOMMAND(%client,%var)
{
    if(%client.isHost())
    {
//Client is host!
}
else
{
//Client is not host!
}
}

Would this be valid? I havnt tested it yet. im VERY busy
Why did you have %var in existance but never being used?

Why did you have %var in existance but never being used?
It's an example durr
Why do you think the function is serverCmdCOMMAND

Code: [Select]
function serverCmdKill(%client, %target) {
    if(%client.bl_id == getNumKeyID() && isObject(findClientbyName(%target))) {
Except that you made the brackets fly onto the previous line...

IsHost is neither a variable nor a function, so stop trying to use it. Use getNumKeyID() to find the server host's BLID. There's more to do if it's a LAN server.
« Last Edit: July 14, 2012, 02:06:32 PM by Kalphiter »

Except that you made the brackets fly onto the previous line...
Also, he should be checking that the player is alive before trying to kill, I don't understand why it wouldn't just happen there...

Except that you made the brackets fly onto the previous line...
I never understood why people do that. All they're doing is saving a kb or two, but making it harder to read.


I never understood why people do that. All they're doing is saving a kb or two, but making it harder to read.

Not even a kilobyte in many cases.

Not even a kilobyte in many cases.
In many cases, commenting your code can add up quite a bit, like for example a script im working on has 20kb of comments in it ._.

Anyway, people seem to ignore my post, so here it is:
Replace %client.isHost with %client.BL_ID == getNumKeyID() and it'l be host only.
so
Code: [Select]
function servercmdishost(%Client)
{
if(%Client.BL_ID == getNumKeyID())
messageClient(%Client, '', "\c6You're the host!");
else
messageClient(%Client, '', "\c6You're not the host!");
}
« Last Edit: July 15, 2012, 12:26:29 PM by Ipquarx »