Author Topic: new who command  (Read 3593 times)

Offline capo

  • Friend
  • **
  • Posts: 70
    • View Profile
new who command
« on: September 18, 2006, 11:35:40 am »
Trying to create a new command, similar to who, that lists only the members of a specific guild and accessible only by that specific guild.



This is what I have so far, but it returns... nothing.  Any suggestions would be most welcome:



code:


#include <lib.h>
#include <privs.h>
#include <config.h>

inherit LIB_DAEMON;

#define SEP repeat_string("**",39)+"*\n";

int cmd(string args)
 {
    int p;
    string x, tmp="", ret="";
    object *thieves;

    thieves = filter(users(), (: $1->GetClass() == "thief" :) );
    p = 0;


    for (int i=0; i<sizeof(thieves); i++)
        {
        if(thieves || environment(thieves)) continue;
            {
            tmp += "";
            if(sizeof(thieves->GetShort()) < 50) {
            tmp+=sprintf(" %s", thieves->GetShort());
            }
            else
             {
                tmp+=" "+capitalize(thieves->GetKeyName())+ " the Long-Titled.";
             }
            if(thieves->GetSleeping() > 0) tmp+=" (%^YELLOW%^sleeping%^RESET%^) ";
            else if (thieves->GetProperty("afk")) tmp+=" (%^YELLOW%^afk%^RESET%^)";
            else if (query_idle(thieves)>240 && thieves->GetInCombat()!=1)  tmp+=" (%^YELLOW%^idle%^RESET%^)";
            else if (in_edit(thieves)) tmp+=" (%^RED%^edit%^RESET%^)";
            else if(thieves->GetInCombat())  tmp+=" (%^RED%^combat%^RESET%^)";
            tmp+="\n";
            p++;
        }
    }
 return 1;
 }




Offline cratylus

  • Your favorite and best
  • Administrator
  • ***
  • Posts: 1022
  • Cratylus@Dead Souls <ds> np
    • View Profile
    • About Cratylus
new who command
« Reply #1 on: September 18, 2006, 11:38:36 am »
I don't see where you try to send tmp to the player.

Offline capo

  • Friend
  • **
  • Posts: 70
    • View Profile
new who command
« Reply #2 on: September 18, 2006, 11:46:04 am »
code:

#include <lib.h>
#include <privs.h>
#include <config.h>

inherit LIB_DAEMON;

#define SEP repeat_string("*=",39)+"*\n";

int cmd(string args)
 {
    int p;
    string x, tmp="", ret="";
    object *thieves = filter(users(), (: $1->GetClass() == "thief" :) );
    p = 0;
   

    for (int i=0; i<sizeof(thieves()); i++) {
        if(!obs || !environment(thieves)) continue;
            {
            else tmp+=sprintf("         ");
            tmp += "";
            if(sizeof(thieves->GetShort()) < 50) {
                tmp+=sprintf(" %s", obs->GetShort());
            }
            else
         {
                tmp+=" "+capitalize(thieves->GetKeyName())+ " the Long-Titled.";
            }
            if(thieves->GetSleeping() > 0) tmp+=" (%^YELLOW%^sleeping%^RESET%^) ";
            else if (thieves->GetProperty("afk")) tmp+=" (%^YELLOW%^afk%^RESET%^)";
            else if (query_idle(thieves)>240 && thieves->GetInCombat()!=1)  tmp+=" (%^YELLOW%^idle%^RESET%^)";
            else if (in_edit(thieves)) tmp+=" (%^RED%^edit%^RESET%^)";
            else if(thieves->GetInCombat())  tmp+=" (%^RED%^combat%^RESET%^)";
            tmp+="\n";
            p++;
        }
    }
   ret+=SEP;
    ret+=tmp;
    ret+=SEP;
return 1;
 }

Offline cratylus

  • Your favorite and best
  • Administrator
  • ***
  • Posts: 1022
  • Cratylus@Dead Souls <ds> np
    • View Profile
    • About Cratylus
new who command
« Reply #3 on: September 18, 2006, 11:47:51 am »
write(ret);

Offline capo

  • Friend
  • **
  • Posts: 70
    • View Profile
new who command
« Reply #4 on: September 18, 2006, 11:54:36 am »

Hmm. Right. Now the problem is that it returns this:



> twho

*******************************************************************************



*******************************************************************************



I think I need to use the lowercase() function again.


Offline capo

  • Friend
  • **
  • Posts: 70
    • View Profile
new who command
« Reply #5 on: September 18, 2006, 11:57:27 am »
Or maybe not  (fail)

Offline capo

  • Friend
  • **
  • Posts: 70
    • View Profile
new who command
« Reply #6 on: September 18, 2006, 12:04:37 pm »
Success, crude but it works.



code:


#include <lib.h>
#include <privs.h>
#include <config.h>

inherit LIB_DAEMON;

#define SEP repeat_string("**",39)+"*\n\n";

int cmd(string args)
 {
    int p;
    string x, tmp="", ret="";
    object *thieves;

    thieves = filter(users(), (: $1->GetClass() == "thief" :) );
    p = 0;


    for (int i=0; i<sizeof(thieves); i++)
        {
        if(!thieves || !environment(thieves)) continue;
         {
            tmp += "";
            if(sizeof(thieves->GetShort()) < 50)
                {
            tmp+=sprintf(" %s", thieves->GetShort());
                }
            else
                {
                tmp+=" "+capitalize(thieves->GetKeyName())+ " the Long-Titled.";
                }
            if(thieves->GetSleeping() > 0) tmp+=" (%^YELLOW%^sleeping%^RESET%^) ";
            else if (thieves->GetProperty("afk")) tmp+=" (%^YELLOW%^afk%^RESET%^)";
            else if (query_idle(thieves)>240 && thieves->GetInCombat()!=1)  tmp+=" (%^YELLOW%^idle%^RESET%^)";
            else if (in_edit(thieves)) tmp+=" (%^RED%^edit%^RESET%^)";
            else if(thieves->GetInCombat())  tmp+=" (%^RED%^combat%^RESET%^)";
            tmp+="\n";
            p++;
         }
      }

    ret+=SEP;
    ret+=tmp;
    ret+=SEP;
    write(ret);
    return 1;
 }


Offline capo

  • Friend
  • **
  • Posts: 70
    • View Profile
new who command
« Reply #7 on: September 18, 2006, 12:11:31 pm »
Hmm.  When trying to add in a use restriction --- either creator or thief --- I created the following errors:  Any suggestions to fix?



code:

#include <lib.h>
#include <privs.h>
#include <config.h>

inherit LIB_DAEMON;

#define SEP repeat_string("**",39)+"*\n\n";

int cmd(string args)
 {
    int p;
    string x, tmp="", ret="";
    object *thieves;
    object ob;

    thieves = filter(users(), (: $1->GetClass() == "thief" :) );
    p = 0;

  if(!creatorp(ob) && lower_case(ob->GetClass()) != "thief")
     {
        message("info","That is not a command", ob);
        return 0;
     }
 else
   for (int i=0; i<sizeof(thieves); i++)
        {
        if(!thieves || !environment(thieves)) continue;
         {
            tmp += "";
            if(sizeof(thieves->GetShort()) < 50)
                {
            tmp+=sprintf(" %s", thieves->GetShort());
                }
            else
                {
                tmp+=" "+capitalize(thieves->GetKeyName())+ " the Long-Titled.";
                }
            if(thieves->GetSleeping() > 0) tmp+=" (%^YELLOW%^sleeping%^RESET%^) ";
            else if (thieves->GetProperty("afk")) tmp+=" (%^YELLOW%^afk%^RESET%^)";
            else if (query_idle(thieves)>240 && thieves->GetInCombat()!=1)  tmp+=" (%^YELLOW%^idle%^RESET%^)";
            else if (in_edit(thieves)) tmp+=" (%^RED%^edit%^RESET%^)";
            else if(thieves->GetInCombat())  tmp+=" (%^RED%^combat%^RESET%^)";
            tmp+="\n";
            p++;
         }
      }
      }

    ret+=SEP;
    ret+=tmp;
    ret+=SEP;
    write(ret);
    return 1;
 }


Offline capo

  • Friend
  • **
  • Posts: 70
    • View Profile
new who command
« Reply #8 on: September 18, 2006, 01:20:20 pm »
Figured it out.