Help with CH /list script (auto_include.MS)

Discussion in 'CommandHelper Scripts' started by thefirstboss, Nov 28, 2015.

  1. thefirstboss

    thefirstboss New Member

    Hi could i have help with this script? How do i add/remove ranks to the list? It doesn't seem to be working ingame (users not showing up on /list command. What do i do?

    proc(_list,
    #Herochat breaks list so lets re-implement here.
    #Need to figure out a way of hiding vanished users.
    #Could possibly extend to list by world...
    #Would also be nice to have sorted by group
    assign(@adminlist,range(0))
    assign(@modslist,range(0))
    assign(@donatorlist,range(0))
    assign(@userlist,range(0))
    assign(@defaultlist,range(0))
    assign(@players,all_players())
    msg(concat(color(BLUE),'There are ',color(RED),array_size(@players),color(BLUE),' players online:'))
    foreach(@players,@pl,
    if(array_contains(pinfo(@pl,9),donators),
    array_push(@donatorlist,concat(color(YELLOW),'[D]',color(DARK_GREEN),pinfo(@pl,4),color(WHITE)))
    )
    if(array_contains(pinfo(@pl,9),users),
    array_push(@userlist,concat(color(YELLOW),'+',color(GRAY),pinfo(@pl,4),color(WHITE)))
    )
    if(array_contains(pinfo(@pl,9),admins),
    array_push(@adminlist,concat(color(YELLOW),'[A]',color(RED),pinfo(@pl,4),color(WHITE)))
    )
    if(array_contains(pinfo(@pl,9),mods),
    array_push(@modslist,concat(color(YELLOW),'[M]',color(BLUE),pinfo(@pl,4),color(WHITE)))
    )
    if(array_contains(pinfo(@pl,9),default),
    array_push(@defaultlist,concat(color(DARK_GRAY),pinfo(@pl,4),color(WHITE)))
    )
    )
    msg(concat(color(red),'=======================',color(red),'Admins',color(red),'======================'))
    msg(array_implode(@adminlist),' ')
    msg(concat(color(red),'=======================',color(blue),'Mods',color(red),'========================'))
    msg(array_implode(@modslist),' ')
    msg(concat(color(red),'=====================',color(dark_green),'Donators',color(red),'======================'))
    msg(array_implode(@donatorlist),' ')
    msg(concat(color(red),'=======================',color(gray),'Users',color(red),'======================='))
    msg(array_implode(@userlist),' ')
    msg(concat(color(red),'=======================',color(dark_gray),'Noobs',color(red),'======================='))
    msg(array_implode(@defaultlist),' ')
    #msg(array_implode(array_merge(@adminlist,@modslist,@donatorlist,@userlist,@defaultlist),', '))
    )
  2. PseudoKnight

    PseudoKnight Well-Known Member

    In the future you can wrap your code with [ php ][ /php ] tags so that it's easier to read. You can also paste to http://paste.thezomg.com/ and choose the CommandHelper Language from the drop-down menu so that it highlights the syntax nicely.

    Bukkit doesn't know about permission groups, so plugins have to determine this via other means. pgroup() and pinfo(9) use the same method as WorldEdit. In fact, older versions of CommandHelper directly use WorldEdit's method. In those versions, sometimes groups will be automatically detected, depending on your permissions plugin. But as a fallback, it will pick up the permission node group.groupname to indicate which group you're in. If you're on the new builds, this is the only way to detect groups except via extensions.

    Summary: Add "group.groupname" permission nodes to all your group permissions. eg. group.donators

    Optional: Check has_permission('group.donators') instead of a list of groups.
  3. PseudoKnight

    PseudoKnight Well-Known Member

    I don't think I fully covered your questions. I'm not sure what you do and don't know, so I'll cover some stuff.

    - proc is a procedure. They do not trigger on commands directly. You have to setup an alias to run the procedure.

    Example: (aliases.msa)
    PHP:
    *:/list = >>>
        _list()
    <<<
    - To add or remove groups you would duplicate or remove them. Each group is separated out. As an example, these lines cover the mods group:
    PHP:
    assign(@modslist,range(0))
    if(array_contains(pinfo(@pl,9),mods),
    array_push(@modslist,concat(color(YELLOW),'[M]',color(BLUE),pinfo(@pl,4),color(WHITE)))
    )
    msg(concat(color(red),'=======================',color(blue),'Mods',color(red),'========================'))
    msg(array_implode(@modslist),' ')
     
    - If you're on the latest builds of CommandHelper, I can write an updated version of this for you and stick it in an alias.
  4. PseudoKnight

    PseudoKnight Well-Known Member

    Here's an alternative. It uses modern syntax. It dynamically uses defined groups and colors at the top, so you can easily add/remove groups. It does assume a few things, though. The _list() procedure above shows a player in every group they're in. This one below only shows the player in their highest priority group, which prevents redundancy when you have group inheritance. If you add a group to the @groups array, you have to add a color to the @colors array. You add this to a *.msa file like aliases.msa, since it's an alias.
    PHP:
    *:/list = >>>
        # define your groups here in order of priority (high to low)
        @groups = array('Admins', 'Mods', 'Donators', 'Users', 'Default');
        # define respective group colors here in minecraft color codes
        @colors = array('4', 'b', 'a', 'e', '7');
       
        # dynamically prepare lists
        @grouplist = associative_array();
        foreach(@g in @groups) {
            @grouplist[@g] = array();
        }
       
        # assign players to their group's list
        foreach(@p in all_players()) {
            foreach(@g in @groups) {
                if(has_permission(@p, 'group.'.to_lower(@g))) {
                    @grouplist[@g][] = @p;
                    break();
                }
            }
        }

        # display all groups and players
        foreach(@i: @g in @groups) {
            msg(color(7).'======================= '.color(@colors[@i])[email protected]g.color(7).' ======================');
            msg(array_implode(@grouplist[@g]));
        }
    <<<
  5. thefirstboss

    thefirstboss New Member

    ok, thanks i defined the alias in the config alredy... and as for the script you gave me i would like to know how to do it without the lines... for example here are my server groups (Ops, admins, mods, Donator+, Donators, Users, defaults. I would like it displayed like this
    &eThere are &cX &eplayers online:
    all online owners will be here at the top like this
    all online admins second
    all mods
    all donators+
    all donators
    all users
    and finally all default ranks



    also i have an alias in config that points too auto include. so i need the proc(_list
    Last edited: Nov 29, 2015
  6. PseudoKnight

    PseudoKnight Well-Known Member

    I'm not going to do it all for you. Adding/removing groups should be painless because I set it up super simple. As for formatting, here's another example using smart strings (double quotes) to insert variables directly into strings instead of dot concating (connecting multiple strings together), and colorize() to change color codes into colors.
    PHP:
    *:/list = >>>
        # define your groups here in order of priority (high to low)
        @groups = array('Admins', 'Mods', 'Donators', 'Users', 'Default');
        # define respective group colors here in minecraft color codes
        @colors = array('4', 'b', 'a', 'e', '7');
       
        # dynamically prepare lists
        @grouplist = associative_array();
        foreach(@g in @groups) {
            @grouplist[@g] = array();
        }
       
        @players = all_players();
        @count = array_size(@players);
       
        # assign players to their group's list
        foreach(@p in @players) {
            foreach(@g in @groups) {
                if(has_permission(@p, 'group.'.to_lower(@g))) {
                    @grouplist[@g][] = @p;
                    break();
                }
            }
        }

        # display all groups and players
        msg(colorize("&eThere are&c @count &eplayers online:"));
        foreach(@i: @g in @groups) {
            msg(color(7).'======================= '.color(@colors[@i])[email protected]g.color(7).' ======================');
            msg(array_implode(@grouplist[@g]));
        }
    <<<
  7. thefirstboss

    thefirstboss New Member

    Okay! Thanks so much i really appreciate your help!!!!
    But one last thing... so i put the script in and it worked however it did not show the User as the name appears in chat.. it just showed them in white. also say i want to remove the ========== Groupname ============. I did this and there were a bunh of blank spaces. I would like each group space to be ignored if no players from that group are presant. Is this possible?
    so recap: How to show pex names in list, spacing

    thanks so much !!!
  8. thefirstboss

    thefirstboss New Member

    oh and one last last thing, why did my first script not show the players that were online thanks
  9. PseudoKnight

    PseudoKnight Well-Known Member

    PHP:
        msg(colorize("&eThere are&c @count &eplayers online:"));
        foreach(@i: @g in @groups) {
            if(@grouplist[@g]) {
                msg(color(@colors[@i])[email protected]g.': '.array_implode(@grouplist[@g]));
            }
        }
  10. thefirstboss

    thefirstboss New Member

    ?... an btw your script did not make it work... i did use the group.groupname on each like group.default went to default etc
    Last edited: Nov 29, 2015