Fwoosh

Discussion in 'Plugin Development' started by Saturisk, Feb 26, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    Saturisk

    Catchy title huh?
    Haha, well i want to create a plugin that when you say '/fire' you burst into flames. It's just for a prank on a friend, not meant for any harm.

    What would be the easiest way?
    I could see ENTITY_PLAYER + Fireticks, but i don't understand fireticks.
     
  2. Offline

    Edward Hand

    fireticks is how long you will be on fire for (in ticks, which are 1/20th of a second long).
    if fireticks isnt zero, you're on fire. Every tick the value decreases by 1 until it reaches zero and you stop being on fire.
    So, to make someone be on fire for 5 second, set fire ticks to 5*20=100
     
  3. Offline

    Saturisk

    Well i want to direct it only towards the person that says it, that could just me like:
    if(s[0].equalsIgnoreCase("/fire"){

    fireticks = 5*20;

    }

    never worked with fireticks so don't know what it is yet
     
  4. Offline

    Edward Hand

    event.getPlayer().setFireTicks(100);
     
  5. Offline

    Saturisk

    On another note, i have never used a function that's like:
    /fire <player> like to set that player on fire, because that would be nice too
    in other words how could i set a guy on fire, since some of my friends goof around on my server i would think it would be funny to just set them on fire willy nilly.
     
  6. Offline

    Edward Hand

    Code:
    if(s[0].equalsIgnoreCase("/fire"){
        Player target;
        if(s.length > 1)
            target = plugin.getServer().getPlayer(s[1]);
        if(target == null)
            target = e.getPlayer();
        target.serFireTicks(100);
    }
    a bit like that (just off the top of my head)
     
  7. Offline

    Saturisk

    urgh, haha never dealt with somethin like that before, time to hit the books XD
    --- merged: Feb 26, 2011 10:23 PM ---
    where would you learn that stuff?
     
  8. Offline

    Edward Hand

    which stuff in particular?
     
  9. Offline

    Saturisk

    Well i understand the if statements but you just threw in targets and stuff

    Code:
    Player target;
        if(s.length > 1)
            target = plugin.getServer().getPlayer(s[1]);
        if(target == null)
            target = e.getPlayer();
        target.serFireTicks(100);
    --- merged: Feb 26, 2011 10:28 PM ---
    Quick question is minecraft.net down for you too?
     
  10. Offline

    Edward Hand

    It's been down all day. Let me try to comment the code a little:
    PHP:
    if(s[0].equalsIgnoreCase("/fire"){
        
    //Define a variable of type Player, called target, for storing the person to set on fire (initially set to null).
        
    Player target;
        
    //Check whether their command includes an extra argument for player name
        
    if(s.length 1)
            
    //If so, set target to be the player with the name given
            
    target event.getPlayer().getServer().getPlayer(s[1]);
        
    //if by this point target is still equal to null, either a name argument wasn't supplied or there was no player with that name.
        
    if(target == null)
            
    //in that case, target the player calling the command.
            
    target event.getPlayer();
        
    //set target on fire.
        
    target.setFireTicks(100);
    }
     
  11. Offline

    Saturisk

    If i have one string, like s[0] i have to set that up like:
    String[] s = what? for that instance, because i have String split[0] = event.getMessage().split(" "); and event.getPlayer();
    --- merged: Feb 26, 2011 10:39 PM ---
    Then it says that the "e" and s's arent registered variables.
     
  12. Offline

    Edward Hand

    Oh. replace that 'e' with 'event' (force of habit - I usually name my events e)

    Also, you need this line (which I assumed you already had from the code you showed me):
    String[] s = event.getMessage().split(" ");
     
  13. Offline

    Saturisk

    Ahh, i wish i caught onto that but this is so new to me XD
    The Player Target; part is the only part that's "broken" that part is fine, but the other target variables in it say i have to make Player target = null;
     
  14. Offline

    Edward Hand

    Oh yeah. It'll complain it may not have been initialised. That's what happens when you code off the top of your head ^_^.

    Set it equal to null then.
     
  15. Offline

    Saturisk

    alrighty :) Thanks Edward!
    --- merged: Feb 26, 2011 10:52 PM ---
    I want to make it if player is op to, but i get the thing "op" is not a static reference do i need to make it "public static void (){} or whatever?
    --- merged: Feb 26, 2011 10:52 PM ---
    Sorry for bombarding you with questions~
     
  16. Offline

    Edward Hand

    remember:
    use event.getPlayer().isOp()
    (its a function)
     
  17. Offline

    Saturisk

    So if i have : if(event.getPlayer().isOp() && s[0].equalsIgnoreCase("/fire"))
    it's saying if player is Op and he says /fire do: etc
     
  18. Offline

    Edward Hand

  19. Offline

    Saturisk

    awesome!~
    Just think i thought this was greek 3 days ago... haha thanks for you help Edward.
     
  20. Offline

    Edward Hand

    Any time.
     
  21. Offline

    Saturisk

    ill take that offer
     
  22. Offline

    Plague

    Since we're obvously teaching programming here:
    if you use event.getPlayer() so often, try to assign it somewhere so you do not call the function too many times.
    Player myPlayer = event.getPlayer();
    and use myPlayer instead.
    I know here it does not really matter, but if you get into that practice it will only make your code better in the future.
     
  23. Offline

    Saturisk

    Alright cool, see i can remember this stuff because i studied web development for a while, created a few websites here and there so this isn't all that new with variables but still its tough :p
    [​IMG]
     
Thread Status:
Not open for further replies.

Share This Page