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

sendMessage Help

Discussion in 'Development' started by Junkdude, Apr 22, 2019.

  1. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    Whenever my sendMessage function executes, it sends 4 messages insetad of one, heres my code if you need it
    Code:
     if((mt_rand($stone->get("itemchance"), 100) === 100))
                    {
                    foreach ($stone->get("items") as $item) {
                    $item1 = intval($item);
                        if($this->invFull($p))
                        {
                            $p->sendMessage($title . "You found a lucky block item, but your inventory was full!");
                        }else{
                            $p->sendMessage($lbmsg);
                            $p->getInventory()->addItem(Item::get($item1));
                        }
                        }
                    }  
     
  2. KielKing

    KielKing Zombie

    Messages:
    245
    GitHub:
    kielking
    because $stone->get("items") returns an array of 4 values, and the foreach loops accordingly

    you can escape this loop by doing
    PHP:
    if((mt_rand($stone->get("itemchance"), 100) === 100)){
        foreach(
    $stone->get("items") as $itemId){
            
    $itemId intval($itemId);
            if(!
    $this->invFull($p){
                
    $p->sendMessage($lbmsg);
                
    $p->getInventory()->addItem(Item::get($itemId));
            }else{
                
    $p->sendMessage($title "You found a lucky block item, but your inventory was full!");
                break;
            }
        }
    }
     
    notdrewdev and HimbeersaftLP like this.
  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.