#particle thing

1 messages · Page 1 of 1 (latest)

storm lantern
#

so

#
public static void makeParticleCircle() {
        for (Player p : Bukkit.getOnlinePlayers()) {
            Location location = p.getPlayer().getLocation();
            for (int degree = 0; degree < 360; degree++) {
                double radians = Math.toRadians(degree);
                double x = Math.cos(radians);
                double z = Math.sin(radians);
                location.add(x, 0, z);
                location.getWorld().spawnParticle(Particle.END_ROD, location, 0);
                location.subtract(x, 0, z);
            }
        }
    }
#

@amber cradle

#

and now?

amber cradle
#

You need to parameterize the method with a radius and height-offset

storm lantern
#

ok

#
public static void makeParticleCircle(double x, double z, double y, double radius) {
        for (Player p : Bukkit.getOnlinePlayers()) {
            Location location = p.getPlayer().getLocation();
            for (int degree = 0; degree < 360; degree++) {
                double radians = Math.toRadians(degree);
                x = Math.cos(radians);
                z = Math.sin(radians);
                location.add(x, 0, z);
                location.getWorld().spawnParticle(Particle.END_ROD, location, 0);
                location.subtract(x, 0, z);
            }
        }
    }
```this?
amber cradle
#

You should not use 360 points for every circle. You should scale that based on the radius.
Btw this will create a circle for every player on the server. Do you really want that?

storm lantern
#

no

#

i made a thing to make it run only at players wearing a custom helmet

#

but lets pretend its for all players

amber cradle
#

You should probably add the player as a parameter too

#

So you can call that method for each player

storm lantern
#

ok

#
 public static void makeParticleCircle(double x, double z, double radius, Player p) {

            Location location = p.getPlayer().getLocation();
            for (int degree = 0; degree < 360; degree++) {
                double radians = Math.toRadians(degree);
                x = Math.cos(radians);
                z = Math.sin(radians);
                location.add(x, 0, z);
                location.getWorld().spawnParticle(Particle.END_ROD, location, 0);
                location.subtract(x, 0, z);
            }
        }
    }
#

this?

amber cradle
#

Looks ok.
Now we need to write a second method that generates the sin wave based on the distance from the player

#

So
input -> distanceFromPlayer
output -> heightOfWave

#

Then we step from 0 to N in steps of 0.1 or so and then generate a circle with this radius and height

amber cradle
storm lantern
#

i put input as parameter of method right?

storm lantern
#

x and z made the circle

amber cradle
#
    public static void makeParticleCircle(double heightOffset, double radius, Player player) {
        Location location = player.getLocation();
        for (int degree = 0; degree < 360; degree++) {
            double radians = Math.toRadians(degree);
            double x = Math.cos(radians) * radius;
            double z = Math.sin(radians) * radius;
            location.add(x, heightOffset, z);
            location.getWorld().spawnParticle(Particle.END_ROD, location, 0);
            location.subtract(x, heightOffset, z);
        }
    }
storm lantern
#

ill test it wait

amber cradle
#
    public static void makeParticleCircle(double heightOffset, double radius, Player player) {
        Location location = player.getLocation();
        for (int degree = 0; degree < 360; degree++) {
            double radians = Math.toRadians(degree);
            double x = Math.cos(radians) * radius;
            double z = Math.sin(radians) * radius;
            location.add(x, heightOffset, z);
            location.getWorld().spawnParticle(Particle.END_ROD, location, 0);
            location.subtract(x, heightOffset, z);
        }
    }

    public static void createParticleSinWaveCircle(Player player, double distance, double amplitude, double freq) {
        double height = Math.sin(distance * freq) * amplitude;
        makeParticleCircle(height, distance, player);
    }

    public static void createParticleWave(Player player, double startRad, double endRad, double steps) {
        double ampl = 1.0;
        double freq = 0.33;
        double rad = startRad;
        while (rad <= endRad) {
            createParticleSinWaveCircle(player, rad, ampl, freq);
            rad += steps;
        }
    }
storm lantern
#

oh

amber cradle
#

Usage:

createParticleWave(player, 1.0, 5.0, 0.1);
#

Creates a wave from distance 1.0 - 5.0 in 0.1 steps

storm lantern
#

ok

#

1.0 from player?

#

1.0 blocks?

#

and what is steps

#

also

#

is there a way to make it take time?

#

like take 5seconds to complete the circle

#

was this meant to happen?

#

@amber cradle

#

@Flo | Gestankbratwurst#4120 ?

#

i wanted it to make this

#

@amber cradle ?

amber cradle
storm lantern
#

;-;

#

you know it?

amber cradle
#

This should be simpler

storm lantern
#

yay

#

can you tell me how?

amber cradle
#

Try this:

    public static void makeParticleSinCircle(double radius, Player player) {
        Location location = player.getLocation();
        for (int degree = 0; degree < 360; degree++) {
            double radians = Math.toRadians(degree);
            double x = Math.cos(radians) * radius;
            double y = Math.sin(radians);
            double z = Math.sin(radians) * radius;
            location.add(x, y, z);
            location.getWorld().spawnParticle(Particle.END_ROD, location, 0);
            location.subtract(x, y, z);
        }
    }
storm lantern
#

just it?

amber cradle
#

Just this yes

storm lantern
#

kk

amber cradle
#

It might look a bit odd because its just a single sin wave.

storm lantern
amber cradle
#

pic pls

storm lantern
#

i increased the steps amount and it taked time to make the circle

storm lantern
storm lantern
amber cradle
#

The new method ive sent

storm lantern
#

yea ok wait

storm lantern
#

so it would make the waves and take time to make them

amber cradle
#

Ah i see.

#

Change

double y = Math.sin(radians);

to

double y = Math.sin(radians * 4);
storm lantern
#

radians * number
number is waves?

amber cradle
#

Yes the number should be the amount of waves

storm lantern
#

so i can add it as parameter?

amber cradle
#

sure

storm lantern
#
 public static void makeParticleSinCircle(double radius, Player player, int waves) {
        Location location = player.getLocation();
        for (int degree = 0; degree < 360; degree++) {
            double radians = Math.toRadians(degree);
            double x = Math.cos(radians) * radius;
            double y = Math.sin(radians) * waves;
            double z = Math.sin(radians) * radius;
            location.add(x, y, z);
            location.getWorld().spawnParticle(Particle.END_ROD, location, 0);
            location.subtract(x, y, z);
        }
    }
#

ty

#

nah u pro

amber cradle
#

nice. I would just decrease the number of points a bit.

for (int degree = 0; degree < 360; degree++) {

Could be

for (int degree = 0; degree < 360; degree += 4) {

To have 90 points instead of 360

storm lantern
#

less particles right?

amber cradle
#

yeah

storm lantern
#

kk

#

not everyone has a non-potato pc

#

thanks for help

#

@amber cradle

#

how do i change the height offset

#

its too big

amber cradle
#
double y = Math.sin(radians * waves) * height;
storm lantern
#

ok

#

gg thanks

storm lantern
#

with this

    public static void makeParticleSinCircle(double radius, Player player, int waves, double heightOffset) {
        Location location = player.getLocation();
        for (double degree = 0.0; degree < 360.0; degree+=4) {
            double radians = Math.toRadians(degree);
            double x = Math.cos(radians) * radius;
            double y = Math.sin(radians * waves) * heightOffset;
            double z = Math.sin(radians) * radius;
            location.add(x, y, z);
            location.getWorld().spawnParticle(Particle.END_ROD, location, 0);
            location.subtract(x, y, z);
        }
    }
storm lantern
#

@amber cradle?

#

I want to do the wave circle (that i already have) but with the steps from the other

storm lantern
#

@amber cradle

amber cradle
#

Oh yeah. Idk just throw some math at it...

#

What are you trying to do?

storm lantern
#

Im not he math guy here

amber cradle
#

So you want a wave that goes outwards + has waves on a radial axis?
This will just result in random hills...

storm lantern
#

No

storm lantern
#

But it takes some time to complete the circle

amber cradle
#

What do you mean by that? The circle should show instantly.

storm lantern
#

Steps made it take some time to complete

#

I want it do "draw" the wave circle

amber cradle
#

So you want it to appear over time?

#

Like a laser pointer going in a circle

storm lantern
#

Yes

#

But waveing y axis

amber cradle
#

Oh i wont help with that. Its basically the same thing but you create a stateful runnable.

storm lantern
#

I think i can just mix both things u sent me

amber cradle
#

You will need a scheduler for that

storm lantern
#

I mean

storm lantern
#

Just increased steps

amber cradle
#

Thats probably just lags showing. You need a runnable. Trust me on that.

storm lantern
#

Kk

storm lantern
#

If it doesnt make the circle instantly then its not lag

storm lantern
#

Im probably already doing it and dont know

#

public class ArmorTask extends BukkitRunnable

storm lantern
amber cradle
#

You will need 2 classes.
For once the task:

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Particle;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;

import java.util.UUID;

public class WaveParticleTask extends BukkitRunnable {

    private final UUID playerID;
    private final int waves;
    private final double height;
    private final double radius;
    private int degree = 0;

    public WaveParticleTask(UUID playerID, int waves, double height, double radius) {
        this.playerID = playerID;
        this.waves = waves;
        this.height = height;
        this.radius = radius;
    }

    @Override
    public void run() {
        degree %= 360;
        Player player = Bukkit.getPlayer(playerID);
        if (player == null) {
            this.cancel();
            return;
        }
        double radians = Math.toRadians(degree);
        double x = Math.cos(radians) * radius;
        double y = Math.sin(radians * waves) * height;
        double z = Math.sin(radians) * radius;
        Location particleLoc = player.getLocation().add(x, y, z);
        player.getWorld().spawnParticle(Particle.END_ROD, particleLoc, 0);
        degree += 5;
    }

}
#

Then a manager:

import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

public class WaveParticleManager implements Runnable {

    private final Map<Player, WaveParticleTask> runningTasks = new HashMap<>();

    public void startTask(Player player) {
        runningTasks.put(player, new WaveParticleTask(player.getUniqueId(), 5, 0.66, 2.5));
    }

    public void stopTask(Player player) {
        Optional.ofNullable(runningTasks.get(player)).ifPresent(BukkitRunnable::cancel);
    }

    @Override
    public void run() {
        runningTasks.values().forEach(WaveParticleTask::run);
    }

}
#

Then you can do this in your main class:

    private final WaveParticleManager waveParticleManager = new WaveParticleManager();

    @Override
    public void onEnable() {
        Bukkit.getScheduler().runTaskTimer(this, waveParticleManager, 1, 1);
    }
#

If you want to start a wave task simply do:

waveParticleManager.startTask(player);
storm lantern
#

kk

#

thanks

#

i found another way

#

but its very big

#

Then a manager:
cannot resolve symbol 'Then'

#

nvm

#

i copied wrong

storm lantern
#

if yes: cannot resolve symbol ''player''

#
public void onEnable() {
        instance = this;
        CustomArmorManager.startTask(player);
//cannot resolve symbol player
//Non-static method 'startTask(org.bukkit.entity.Player)' cannot be referenced from a static context
        Setup.setup(this);
    }
#

i changed some things and got no errors

#

task

package me.lucasgithuber.obsidianexpansion.utils;

import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Particle;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;

import java.util.UUID;

public class CustomArmorTask extends BukkitRunnable {

    private final UUID playerID;
    private final int waves;
    private final double height;
    private final double radius;
    private int degree = 0;

    public CustomArmorTask(UUID playerID, int waves, double height, double radius) {
        this.playerID = playerID;
        this.waves = waves;
        this.height = height;
        this.radius = radius;
    }

    @Override
    public void run() {
       
                degree %= 360;
                Player player = Bukkit.getPlayer(playerID);
                if (player == null) {
                    this.cancel();
                    return;
                }
                double radians = Math.toRadians(degree);
                double x = Math.cos(radians) * radius;
                double y = Math.sin(radians * waves) * height;
                double z = Math.sin(radians) * radius;
                Location particleLoc = player.getLocation().add(x, y, z);
                player.getWorld().spawnParticle(Particle.END_ROD, particleLoc, 0);
                degree += 5;
            }
        }
    
#

manager

package me.lucasgithuber.obsidianexpansion.utils;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

public class CustomArmorManager implements Runnable {

    private static final Map<Player, CustomArmorTask> runningTasks = new HashMap<>();

    public static void startTask() {
        for(Player p : Bukkit.getOnlinePlayers()) {
            runningTasks.put(p, new CustomArmorTask(p.getUniqueId(), 10, 0.66, 2.5));
        }
    }

    public void stopTask(Player player) {
        Optional.ofNullable(runningTasks.get(player)).ifPresent(BukkitRunnable::cancel);
    }

    @Override
    public void run() {
        runningTasks.values().forEach(CustomArmorTask::run);
    }

}
#

enable

public void onEnable() {
        instance = this;
        CustomArmorManager.startTask();
        Setup.setup(this);
    }
#

ofc, in the task i will be doing a check for armor so it wont execute at every player in server

#

it didnt work

storm lantern
#

it doesnt even fire

amber cradle
#

This just means you need to write more code 😄
Doesnt get more spoon feedy than that

storm lantern
#

wdym by spoon feedy

#

im brazilian idk what that is

#

oh

#

i see what i did wrong

storm lantern
#

now it makes the particles but only at 1 place

storm lantern
#

i did it, now it makes the circle with waves

#

but instantly

#

never tought math were this hard

#

welp i gtg

#

tomorrow i try to do it

storm lantern
amber cradle
#

This is what is happening for me

storm lantern
#

Wha

#

Weird

storm lantern
#

how do you check for player

#

@amber cradle

storm lantern
#

i tried

for(Player player : Bukkit.getOnlinePlayers()){
customArmorManager.startTask(player);
}
#

it removed the error but it didnt show particles

#

@Flo | Gestankbratwurst#4120 ?

amber cradle
#

Nope...

storm lantern
#

nope what

#

@amber cradle nope what

amber cradle
#

You need more spigot/programming experience. This project is way over your head.

storm lantern
#

ok

storm lantern
#

does anyone know it?

#

@amber cradle its working know, but no circle

storm lantern
#

i mean, you said it worked for you

amber cradle
#

Because it does

storm lantern
#

and why doesnt it for me if its same math

#

wrong vid

storm lantern
#

yoo

#

i kinda did it

#

the code is too big but eh, i "did" it

#

@amber cradle

amber cradle
#

nice