Author Topic: ClearTools help  (Read 1592 times)

Hey guys, I have this little snip of code that Greek2Me gave to me.


function serverCmdClearTools(%client)
{
   %player = %client.player; //ok, we've found their player

   if(isObject(%player)) //let's check to make sure that the player actually exists
      %player.clearTools(); //clear their tools

   messageClient(%client,'',"Your tools were cleared."); //tell them what happened
}


Now, how do I package and implement this into the game? I'm VERY new to addons, and this is getting interesting. (Jeez, so many percent signs.)

How do you want to implement it? Because that snippet of code is a valid function by itself

How do you want to implement it? Because that snippet of code is a valid function by itself

I want to make it work as a command in my server. Like for this to happen -

Say /cleartools [playername]
Clears their tools, says "Your tools were cleared."

If that made no sense, I'm not quite sure what you mean by "How do you want to implement it?"

Ok, you make a very slight modification to the script, like so

Code: [Select]
function serverCmdClearTools(%name)
{
   %client = findclientbyname(%name); //We only had their name, so we use this to find their client
   %player = %client.player; //ok, we've found their player

   if(isObject(%player)) //let's check to make sure that the player actually exists
      %player.clearTools(); //clear their tools

   messageClient(%client,'',"Your tools were cleared."); //tell them what happened
}
Enable that code on your server and you will be able to type /clearTools [name] and have it clear that player's tools

Ok, you make a very slight modification to the script, like so

Code: [Select]
function serverCmdClearTools(%name)
{
   %client = findclientbyname(%name); //We only had their name, so we use this to find their client
   %player = %client.player; //ok, we've found their player

   if(isObject(%player)) //let's check to make sure that the player actually exists
      %player.clearTools(); //clear their tools

   messageClient(%client,'',"Your tools were cleared."); //tell them what happened
}
Enable that code on your server and you will be able to type /clearTools [name] and have it clear that player's tools

Thank you.
How can I make it SA only?
« Last Edit: August 13, 2012, 07:17:57 PM by hodototman »

to make it super admin only, you have to check that %client.isSuperAdmin is true

Here is your amended code:
Code: [Select]
function serverCmdClearTools(%name)
{
   %client = findclientbyname(%name); //We only had their name, so we use this to find their client
   %player = %client.player; //ok, we've found their player

   if(isObject(%player) && %client.isSuperAdmin) //let's check to make sure that the player actually exists
   {
      %player.clearTools(); //clear their tools
      messageClient(%client,'',"Your tools were cleared."); //tell them what happened
   }
}

to make it super admin only, you have to check that %client.isSuperAdmin is true

Here is your amended code:
Code: [Select]
function serverCmdClearTools(%name)
{
   %client = findclientbyname(%name); //We only had their name, so we use this to find their client
   %player = %client.player; //ok, we've found their player

   if(isObject(%player) && %client.isSuperAdmin) //let's check to make sure that the player actually exists
   {
      %player.clearTools(); //clear their tools
      messageClient(%client,'',"Your tools were cleared."); //tell them what happened
   }
}

So this makes it that only SAs can use the command?

Thank you.
How can I make it SA only?
Don't say thank you before you test it

because if you did test it, you would've found it doesn't work AT ALL.

First off, the first argument in every server command is the client that sent the command, you can't just change the name of the variable and hope that it magically knows that you want it to be a name.

second, even if that first error didn't happen, you have it set to message the client whether or not the players tools were cleared! You can't just assume that people always put in valid input.

Here is a fixed version, with error messages and that super-admin-only addition:
Code: [Select]
function serverCmdClearTools(%client, %name)
{
//Make sure the user is super admin
if(!%client.isSuperAdmin)
{
messageClient(%client, '', "\c6You must be super admin to clear other player's tools!");
return false;
}

//Find the target by their name
%target = findclientbyname(%name);
%player = %target.player;

//Make sure the target is on the server, and has spawned.
//If not, give an error message to the sender.
if(isObject(%target))
{
if(isObject(%player))
%player.clearTools();
else
{
messageClient(%client, '', "\c6That person has not spawned yet!");
return false;
}
}
else
{
messageClient(%client, '', "\c6There is nobody by that name on the server!");
return false;
}

messageClient(%client,'',"Your tools were cleared."); //Message the victim

return true;
}

Jesus christ what am I doing
Here is the correct code:
Code: [Select]
function serverCmdClearTools(%userCl,%name)
{
   %client = findclientbyname(%name); //We only had their name, so we use this to find their client
   %player = %client.player; //ok, we've found their player

   if(isObject(%player) && %userCl.isSuperAdmin) //let's check to make sure that the player actually exists and that they are super admin
   {
      %player.clearTools(); //clear their tools
      messageClient(%client,'',"Your tools were cleared."); //tell them what happened
   }
}

Edit: for the record I already had this typed out before Ip posted, I wasn't paying attention

Don't say thank you before you test it

because if you did test it, you would've found it doesn't work AT ALL.

First off, the first argument in every server command is the client that sent the command, you can't just change the name of the variable and hope that it magically knows that you want it to be a name.

second, even if that first error didn't happen, you have it set to message the client whether or not the players tools were cleared! You can't just assume that people always put in valid input.

Here is a fixed version, with error messages and that super-admin-only addition:
Code: [Select]
function serverCmdClearTools(%client, %name)
{
//Make sure the user is super admin
if(!%client.isSuperAdmin)
{
messageClient(%client, '', "\c6You must be super admin to clear other player's tools!");
return false;
}

//Find the target by their name
%target = findclientbyname(%name);
%player = %target.player;

//Make sure the target is on the server, and has spawned.
//If not, give an error message to the sender.
if(isObject(%target))
{
if(isObject(%player))
%player.clearTools();
else
{
messageClient(%client, '', "\c6That person has not spawned yet!");
return false;
}
}
else
{
messageClient(%client, '', "\c6There is nobody by that name on the server!");
return false;
}

messageClient(%client,'',"Your tools were cleared."); //Message the victim

return true;
}

Thank you, Ipquarx. I'll try to make something similar on my own now.

Thanks, this is resolved!

Can't you just do function servercmdclrtools(%cl, %tar){if(isObject(%pl=findclientbyname(%tar).player)&&%cl.issuperadmin){%pl.cleartools();}}

Shortcode ftw.

Server commands always have %client as the first arg.

Code: [Select]
function serverCmdClearTools(%client,%a,%b,%c,%d,%e,%f,%g)
{
if(!%client.isSuperAdmin)
return;

%name = trim(%a SPC %b SPC %c SPC %d SPC %e SPC %f SPC %g); //we need to string together all the words to find the name
%victim = findClientByName(%name); //We only had their name, so we use this to find their client
%player = %victim.player; //ok, we've found their player

if(isObject(%player)) //let's check to make sure that the player actually exists
{
%player.clearTools(); //clear their tools
messageClient(%victim,'',"Your tools were cleared."); //tell them what happened
}
}

Warning - while you were typing 5 new replies have been posted. You may wish to review your post.
agh

Can't you just do function servercmdclrtools(%cl, %tar){if(isObject(%pl=findclientbyname(%tar).player)&&%cl.issuperadmin){%pl.cleartools();}}

Shortcode ftw.
no stuff

First off, he's learning to code, so we're going to teach him an accepted way to use whitespace, and we're also going to add feedback so he knows what the forget is going on. Secondly, that code will not work because you screwed up the variables. Thirdly, all you did was remove the whitespace, shorten the variable names, and remove a single step from the process to get a finished product that looks plain ugly

no stuff

First off, he's learning to code, so we're going to teach him an accepted way to use whitespace, and we're also going to add feedback so he knows what the forget is going on. Secondly, that code will not work because you screwed up the variables. Thirdly, all you did was remove the whitespace, shorten the variable names, and remove a single step from the process to get a finished product that looks plain ugly
What variables are screwed up
Was just an idea whether you can set the variable inside the isObject check

One problem -

When it says "Your tools were cleared" It broadcasts it to the whole server.