1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Createing a message tags system

Discussion in 'Development' started by Atomization, Jul 30, 2020.

  1. Atomization

    Atomization Baby Zombie

    Messages:
    120
    GitHub:
    iAtomPlaza
    Hi, I'm trying to make a system to apply various tags to messages, such as `{player}` and `{faction}`

    I do know how to simply use `str_replace()` to modify the tag in the message to the value, but i cant seem to figure out a efficient system to create tags to replace with...

    here is what im currently doing...
    PHP:
    public static $tags = [];
    public static function 
    updateTag(string $tagstring $value) {
        
    self::$tags[$tag] = $value;
    }
    explanation:
    $tags is a variable that is supposed to hold all the tags registered
    i have to call updateTag() before each message to make sure the values for each tag is send

    while it works... it sucks, very inefficient... i dont wanna call it 10-15 times per command just to change the tags as it goes though the command. any better ideas?
     
  2. tungstenvm

    tungstenvm Witch

    Messages:
    54
    if i am not wrong, you wanna add extra text into a message when it is displaying

    U can use PlayerChatEvent, i dont recommend using $player->setDisplayName()
    then adding more text into it using setMessage("[Text] ".$ev->getMessage());
    that what i would do
     
  3. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    why dont u recommend set display name
     
    GodWeedZao likes this.
  4. tungstenvm

    tungstenvm Witch

    Messages:
    54
    it will display in some other message like the default kill , death message of pocketmine
     
  5. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    yes, he can just set nametag to cfg, for example my tag is HeroWeed in the cfg, and onChatEvent, get player tag in the cfg and str_replace it with player nametag (in the chat)
     
  6. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    also if you want to show that to people under player name (above head) you can use $player->setScoreTag()
    its working fine for me
     
  7. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    or he can do it easier, just set
    PHP:
    $player->setDisplayNameTag($player->getName "\n" "TagHere");
    //and explode it with . or \n
    explode("\n"/*name of player here*/); //like $name
    //now set player nametag in chat with $name[0] it'll set player name to first param in tag
     
  8. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
  9. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    Could you show us how did you register the tags?
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.