Author Topic: admin/unadmin through scripting?  (Read 2922 times)

is there same way to grant/remove admin status in script?

Ideally I could grant admin to a trustworthy person when I'm going afk and revoke it when I get back.

Code: [Select]
function serverCmdAdminToggle(%client,%name) {
if(getRawIp(%client) $= "Local") {
  if(findclientbyname(%name)) {
    if(findclientbyname(%name).isAdmin)
      findclientbyname(%name).isAdmin = 1;
    else
      findclientbyname(%name).isAdmin = 0;
  }
}
}
too lazy to add findclientbyname command I have. Also, the name would have to be 1 word if not done in console and not having a / mod like I did.

Could you do %client.isAdmin to make and !%client.isAdmin to take away or cant you use ! that way?

No. Doing %client.isadmin = 1; etc. does NOT work. It just messes up the GUIs etc. To admin it's easiest to do ServerCmdSAD(%client,$Pref::Server::AdminPassword);. De-admining I dunno about. Yes, you CAN do %client.isadmin = 1; but all the GUIs will be wrong-y...

Code: [Select]
function getPlayer(%mode,%player,%id) {
  %cl = -1;
  for( %i = 0; %i < ClientGroup.getCount(); %i++) {
    %cl = ClientGroup.getObject(%i);
    if ((%mode = 0 && %cl.name = %id) || (%mode = 1 && %cl.bl_id = %id))
%pobject = %cl;
    }
  if(%player)
  return %pobject.player;
  else
  return %pobject;
 return 0;
}

function servercmdAdminToggle(%client,%id)
{
 %player = getPlayer(0,0,%id);
 if(getRawIp(%client) $= "Local" && %player)
 {
  %player.isAdmin = 1 - %player.isAdmin;
  messageall('',"\c2" @ %player.name @ " is now " @ (%player.isAdmin ? "" : "not ") @ an Admin. (Server Host Toggle)");
  if(%player.isAdmin){commandtoclient(getPlayer(0,0,%id),'adminsuccess');}
 }
}

To use, type /adminToggle [id], so for me it'd be /admintoggle 130 - my BL_ID. The getPlayer function can be used for other things, too:

getPlayer(0,0,130) - would get my client object (Things like isAdmin, minigame option, etc) as my ID is 130.
getPlayer(1,1,"Space Guy") - would get my player object (Things like health, tools, etc) as my name is "Space Guy".
« Last Edit: June 09, 2007, 02:14:36 PM by Space Guy »

No. Doing %client.isadmin = 1; etc. does NOT work. It just messes up the GUIs etc. To admin it's easiest to do ServerCmdSAD(%client,$Pref::Server::AdminPassword);. De-admining I dunno about. Yes, you CAN do %client.isadmin = 1; but all the GUIs will be wrong-y...
I know that, I don't script or play anymore, I'm taking a break from BL, so I didn't care to go into the files and get the commands needed.

1. so, the magic function that makes it work is clientcmdadminsuccess()?

2. I've never seen getplayer() before, can you tutorialize me and tell me what the parameters are for that thing? I've been using an annoying-as-hell FOR loop to find BL_IDs by reading through the clientgroup.

 :cookie: for you space guy

clientcmdadminsuccess() is the one used when you enter the admin password correctly. It simply allows the client to open the Admin GUI (instead of password box) and instantly opens it for the client. When you remove admin they will still be able to access the GUI, unchangable, but none of the buttons on it (kick, ban, etc) will function unless they are given it again.

getPlayer(%mode,%player,%id) is a custom function by me -

%mode - 0 = %id uses BL_ID (ex. 130); 1 = %id uses Whole Name (ex. "Space Guy")
%player - 0 = Return Player object (things like inventory, bricks, health); 1 = Return Client object (Things like score, isAdmin, minigame join/leave)
%id - Uses %mode to determine what it checks for - name or BL_ID.

Basically, if you want to kill a certain player then use: getPlayer(0,1,130).kill(); - where my ID is 130.

Also, the function does use a for() loop it's just in a function instead of you having to write the whole loop in the console.
« Last Edit: June 11, 2007, 10:17:52 AM by Space Guy »

Great idea Space Guy! I'll make a version myself.  :cookieMonster:

And thanks again for the admin help.