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

Enchantment returns NULL

Discussion in 'Development' started by VlaD3n, Oct 30, 2019.

  1. VlaD3n

    VlaD3n Silverfish

    Messages:
    15
    I have a problem, when I try to enchant a thing, it kicks me. Screen from the logs attached. The code is below.

    $rinstruments = array(15, 16, 18, 17);
    $instruments = array(256, 257, 258, 269, 270, 271, 273, 274, 275, 277, 278, 279, 284, 285, 286);
    if(in_array($item->getId(), $instruments)){
    for($i = 0; $i != mt_rand(2, 3); $i++){
    $item->addEnchantment(new EnchantmentInstance(Enchantment::getEnchantment($rinstruments[array_rand($rinstruments)]), mt_rand(1, 2)));
    $player->getInventory()->setItemInHand($item);
    }}
     

    Attached Files:

  2. KevinGr19

    KevinGr19 Spider

    Messages:
    9
    Do you test the program without randomize the enchantment level ?

    It may occurs dues of the for loop
     
  3. VlaD3n

    VlaD3n Silverfish

    Messages:
    15
    I tried it without randomization, sometimes it works, and sometimes it gives the same error.
     
  4. VlaD3n

    VlaD3n Silverfish

    Messages:
    15
    NULL gives exactly when receiving an enchantment ID, the level does not affect this.
     
  5. KevinGr19

    KevinGr19 Spider

    Messages:
    9
    If you are trying to take a random element of $rinstruments, try this : §rinstruments[random_int(0,3)]

    Or replace the 3 by : count($rinstruments)

    If you don't want to take a random element of that, then I don't understand the code. Ima beginner in php
     
  6. VlaD3n

    VlaD3n Silverfish

    Messages:
    15
    Doesn't work
     
  7. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
  8. VlaD3n

    VlaD3n Silverfish

    Messages:
    15
    jasonwynn10 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.