Nearly Invisible Player

Discussion in 'Plugin Development' started by pr33dat0r, Nov 3, 2012.

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

    pr33dat0r

    Hey all,

    We are currently working on the Crysis 3 Hunter Mode inspired "Hunter vs. Soldier" Mod.
    The problem is, we need to code that a player is nearly invisible (like the Nanosuit Stealth Mode in Crysis 3). So the idea is that we let that player be completely invisible, with some particles spawning on him (like in the Ghostcraft Mod). Like he has an instant potion on him.

    Does anyone know how to code something like that?
    We really need that help! [​IMG]
    Pm me! And get a Member of the Team!

    Greetz
    Mineplace Staff​
     
  2. Offline

    gamerzap

    You could use a scheduler, iterate through all players on the server and show them an effect such as mobspawner flames at the invisible player's location.
     
  3. Offline

    pr33dat0r

    thanks for the tip! can you describe me, how to do this effect? had the same idea...but without knowleadge.
     
  4. Offline

    Codex Arcanum

    Take a look at the player.playeffect(...) method. I think that's what you're looking for.
     
  5. Offline

    gamerzap

    First, make a scheduler. To do that, add this to your onEnabled() method:
    Code:java
    1. getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
    2. //TODO: add code here
    3. }, 30L)

    This will repeat every 1 1/2 seconds. Change 30 to another number to change that.
    Then add the method inside it:
    Code:java
    1. getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
    2. public void run(){
    3. for(Player player : <invisable players>){
    4. for(Player p : getServer().getOnlinePlayers){
    5. p.playEffect(player.getLocation(), Effect.MOBSPAWNER_FLAMES, 30);
    6. }
    7. }
    8. }
    9. }, 30L)

    Put whatever you're using to keep track of you're invisable players at <invisable players>.
    Make sure the effect goes for at least as long as that last number before the L.

    You have to the double for loops because the effects are client-only, so you need to show the flames to every player.
     
  6. Offline

    pr33dat0r

    Thank you! i will test it, and give you answer.
     
  7. Offline

    fireblast709

    pr33dat0r gamerzap This would only use one loop ;D. I used an ArrayList object for the invisible players. I have no clue if there was any specified data for the flames (thats the 0 in the playeffect())
    Code:java
    1. public static ArrayList<String>invis =(ArrayList<String>)Collections.synchronizedList(new ArrayList<String>());
    2.  
    3. public void onEnable()
    4. {
    5. Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable()
    6. {
    7. @Override
    8. public void run()
    9. {
    10. for(String player : invis)
    11. {
    12. Player p = Bukkit.getPlayer(player);
    13. if(p != null)
    14. {
    15. Location l = p.getLocation();
    16. Bukkit.getWorld(l.getWorld().getName()).playEffect(l, Effect.MOBSPAWNER_FLAMES, 0, 20);
    17. }
    18. else
    19. {
    20. invis.remove(player);
    21. }
    22. }
    23. }
    24. } , 0L, effects_per_second*20L);
     
    ferrybig likes this.
  8. Offline

    pr33dat0r

    puhh! I am a totally Newbie in Bukkitprogramming! But thank you! i'll try to use it, and to learn it ^^
     
  9. Offline

    gamerzap

    Wow, I didn't now thare was a World.playeEffect().
     
  10. Look out whit the concurentException if you modigy a list while looping over it, the only list where this aren't aplying to is the CopyOnWriteList
     
  11. Offline

    fireblast709

    ferrybig If you read carefully you will notice the list is a synchronized list, which is thread safe
     
  12. Offline

    nisovin

    That doesn't matter, your code doesn't use threads anyway. You can't remove items from a list while iterating over it.

    Also, you cannot cast a synchronized list to an ArrayList either.
     
  13. Offline

    fireblast709

    nisovin Yes you can cast it to ArrayList (At least i did). Besides he is using a Runnable, which creates a Thread
     
  14. Offline

    nisovin

    No. A Runnable does not create a thread, read what you quoted again. Creating a Runnable does not automatically create a thread, but it can be used to create a thread. In this case, there is no separate thread, and in any case, you cannot remove an item from a list while iterating over it. You must use an Iterator (or as ferrybig said, a CopyOnWriteList).

    Also:
    Code:
     java.lang.ClassCastException: java.util.Collections$SynchronizedRandomAccessList cannot be cast to java.util.ArrayList
    
     
  15. Offline

    fireblast709

    nisovin O lolz true and yea, shouldn't have spoken so fast without running it once...
     
Thread Status:
Not open for further replies.

Share This Page