Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Can you spawn entities at all using php?

Comments in 'Plugin Development' started by GlaciercreepsMC, Feb 1, 2014.

  1. GlaciercreepsMC
    Offline

    GlaciercreepsMC Active Member Plugin Developer

    Joined:
    Jan 21, 2014
    Posts:
    91
    Plugins:
    1
    Minecraft User:
    GlaciercreepsMC
    Alright, so I got an idea of making a command that spawns primed tnt (or any entity really) either at given coordinates or above you (ex. code for command below), but I don't know if it would work or even how to do it. If it is possible, could anyone tell me what I'd have to do? Thanks!

    PHP:
     public function init(){
        
    $this->api->console->register("tnt""[x] [y] [z]", array($this"spawnTNT"));
    }

    public function 
    spawnTNT(){

    }

    I don't know what I would do from there, as I'm still pretty new to plugin developing. Any help is appreciated!:)
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    EntityAPI::add() in a non static style.
  3. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Or new Entity() if you want raw, but bad choice

    Or just do ($ex=new Explosion ($params...))->explode ($params...)
  4. SpiderPig
    Offline

    SpiderPig Active Member

    Joined:
    Sep 21, 2013
    Posts:
    128
    Minecraft User:
    SpiderPig
    PHP:
                $data = array(
                    
    "x" => $this->0.5,
                    
    "y" => $this->0.5,
                    
    "z" => $this->0.5,
                    
    "power" => 4,
                    
    "fuse" => 20 4//4 seconds
                
    );
                
    $this->level->setBlock($this, new AirBlock(), falsefalsetrue);
                
    $e ServerAPI::request()->api->entity->add($this->levelENTITY_OBJECTOBJECT_PRIMEDTNT$data);
                
    ServerAPI::request()->api->entity->spawnToAll($e);
                return 
    true;
  5. SpiderPig
    Offline

    SpiderPig Active Member

    Joined:
    Sep 21, 2013
    Posts:
    128
    Minecraft User:
    SpiderPig
    Should help you get a idea on how it works
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    I thought TNT was 5 seconds.
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Is this from TNTBlock class?
  8. SpiderPig
    Offline

    SpiderPig Active Member

    Joined:
    Sep 21, 2013
    Posts:
    128
    Minecraft User:
    SpiderPig
  9. GlaciercreepsMC
    Offline

    GlaciercreepsMC Active Member Plugin Developer

    Joined:
    Jan 21, 2014
    Posts:
    91
    Plugins:
    1
    Minecraft User:
    GlaciercreepsMC
    :confused: um, sorry, I forgot to mention that I'm still unfamiliar with the API's, and that I'm not a professional php developer. Right now I'm trying to learn more php; codeacademy.com doesnt teach everything about php (what I mean is all the built-in php functions). Sorry for forgetting to say that. :oops:
  10. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    With reference to the thread title, what other methods would you suggest apart from PHP?
  11. SpiderPig
    Offline

    SpiderPig Active Member

    Joined:
    Sep 21, 2013
    Posts:
    128
    Minecraft User:
    SpiderPig
    Look at some YouTube tutorials on how to learn php
  12. Darunia18
    Offline

    Darunia18 Staff Member Sectional Moderator

    Joined:
    Aug 23, 2013
    Posts:
    755
    Plugins:
    2
    Minecraft User:
    Darunia18
    I know php.net has a lot more information once you understand the basics from CodeCademy. And you'll get the hang of the API. Just experiment with code, read some other peoples' code, and maybe look at the PM source code if you really want to try to understand how that works XDD
    PEMapModder likes this.
  13. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    In fact you can just learn everything from php.net and from other people's code (including the PocketMine Team's)
  14. GlaciercreepsMC
    Offline

    GlaciercreepsMC Active Member Plugin Developer

    Joined:
    Jan 21, 2014
    Posts:
    91
    Plugins:
    1
    Minecraft User:
    GlaciercreepsMC
    Yeah, I think that should work. Lol, looking at other people's code is just a little bit confusing right now, but I get some of it.

    Same thing as above. Thanks guys for support :)

    Also sorry for answering late, as now my main focus is Java. I'll still try to learn php when I'm bored and/or don't feel like programming in Java; I still wanna make plugins. :)
  15. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Java is a bit more troublesome because you can only throw an exception or return null if you want to return false in PHP so PHP is more convenient. In the other hand, it is difficult to, both make and find, a good IDE, for PHP, because there are so much unknown issues in PHP, like, if you `eval()` a line then use the result, the IDE might shout at you for using undefined variables, etc.
  16. KnownUnown
    Offline

    KnownUnown Active Member Plugin Developer

    Joined:
    Aug 22, 2013
    Posts:
    65
    Plugins:
    1
    Minecraft User:
    KnownUnown
    What do you mean, "You can only throw an exception or return null if you want to return false"? Returning a boolean in Java is entirely plausible, and possible. See the following functional code:
    Code:
    public boolean seeICanReturnFalse(){
        System.out.println("I AM RETURNING FALSE!);
        return false;
    }
    Also, if your IDE does that (with eval() and variable output), you need to get a better ide ;)
    jython234 and I_Is_Payton_ like this.
  17. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    I mean
    Code:
    public Xml seeICantReturnFalse(String in){
        if(in.charAt(0)!='<')
            return null;
        return new Xml(in);
    }
    
  18. I_Is_Payton_
    Offline

    I_Is_Payton_ Active Member Plugin Developer

    Joined:
    Jan 18, 2014
    Posts:
    76
    Plugins:
    1
    Minecraft User:
    I_Is_Payton_
    use ceil instead of manually rounding up by 0.5
  19. KnownUnown
    Offline

    KnownUnown Active Member Plugin Developer

    Joined:
    Aug 22, 2013
    Posts:
    65
    Plugins:
    1
    Minecraft User:
    KnownUnown
    Just use this....
    Code:
    public void seeICanReturnFalse(String in){
        if(in.charAt(0)!='<')
            return false;
        return new Xml(in);
    }
    
    I_Is_Payton_ likes this.
  20. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Void? Void methods cannot return anything!
    Are you talking about Object?

Share This Page

Advertisement