I'll already say sorry for my english if it's hard to understand what I'm trying to explain. I'm not a country with english as their main language. What I want is each time the First Integer is at another Integer. Say, each time the Kills of the players hits 10,20,30,4o,50 etc. then do something. Is there an easy way to accomplish this? And what about a way to increment it?
khave I assume you have some kind of a kill counter Here you go: Code:java if (killsCounter == 10) {//Do something when the player has 10 kills}else if (killsCounter == 20){//Do something when the player has 20 kills} Instead of the killsCounter place your variable in which you count the kills!
If you want to do the same thing or call the same method every increment of 10, simply do: Code:java if(killcounter % 10 == 0){ //method call or do stuff killcounter++;}else{ killcounter++;}
Code:java int Test = 10int Killcounter = player.getKills(); /*player.getKills(); does not exist in this case LOL*/if (Killcounter == Test){player.sendMessage("Quack");} /*Choose whatever you like*/
Thank you that was what I was looking for. Somehow though this does not seem to work: Code:java int unarmed = manager.getPlayerConfig(hitter).getInt("Skills.Unarmed"); int level = 10; if(unarmed % level == 0){} Dw, I have tried testing it with a message and no message pops up. My config does get the number correctly too. The integer is 1 Already knew you could do that, but it would take ages. I'd have to do that for every number divisible by 10...
Code:java package me.khave.lowe.listeners; import me.khave.lowe.Manager;import org.bukkit.ChatColor;import org.bukkit.entity.Player;import org.bukkit.event.EventHandler;import org.bukkit.event.Listener;import org.bukkit.event.entity.EntityDamageByEntityEvent; import java.io.IOException; /*** Created by hellehave on 07/08/14.*/public class EntityDamageByEntity implements Listener { @EventHandler public void onEntityDamageByEntity(EntityDamageByEntityEvent e){ if (!(e.getEntity() instanceof Player && e.getDamager() instanceof Player)) return; Player p = (Player) e.getEntity(); Player hitter = (Player) e.getDamager(); Manager manager = new Manager(hitter); int unarmed = manager.getPlayerConfig(hitter).getInt("Skills.Unarmed"); int level = 10; if(unarmed % level == 0){ hitter.sendMessage("Good job!"); try { manager.getPlayerConfig(hitter).set("Skills.Unarmed", manager.getPlayerConfig(hitter).getInt("Skills.Unarmed") + 1); level = level * 2; hitter.sendMessage(ChatColor.GREEN + "Your Unarmed leveled up to " + manager.getPlayerConfig(hitter).getInt("Skills.Unarmed") + "!"); manager.savePlayerConfig(hitter); } catch(IOException IO){ IO.printStackTrace(); } } }}
khave Do you know what value 'unarmed' is? Are your events registered? Could another plugin (if you have any) be conflicting?
Code:Java int each = 10;for (int i = 0; i < 10000; i += each) {if (killsOfPlayer == i) {player.sendMessage("You have a killstreak of " + i + ".");break;}} you can make the value 'each' too e.g 50. so it will send the player the message when he have 50, 100, 150, 200, 250 and so on.. kills
FisheyLP Code offers no help to the problem at hand. khave If 'unarmed' is one than the code block will not execute. 1 % 10 = 1. % is modulus operator, or remainders. So, x % 10 will only equal zero if x is 10, 20, 30, etc... So, that code block does not execute if unarmed is 1.
Haha yea that's basic math. Derp xD. Though when I change it to something like 2 to 10 ( if(1 % 10 == 0) ) it still does not work. What am I doing wrong.. ;-;
khave ... 1 % 10 == 0 will never execute because 1 % 10 is 1. Change your if check to - if (10 % 10 == 0)
That makes it paste the message each time I hit something though? ALSO: I didn't mean to offend you at the basic math. That was a derp towards myself, like I was dumb for not realizing
khave Well yeah ... 10 % 10 == 0 will always execute. khave Your code is invalid because: unarmed = 1. if Unarmed % 10 = 0 -- Add one to unarmed With that code above, unarmed will never be raised higher. EDIT by Moderator: merged posts, please use the edit button instead of double posting.
I've tried adding one to unarmed so it's 2 % 10 = 0, but that doesn't make it say anything at all no matter how many times I hit an entity.
khave That's also partly because you don't have any idea about what you are doing. As I have told you already, something like 2 % 10 can never have a remainder of 0. 2%10 is equal to 2. 3 % 10 is equal to 3. You need to actually read into the modulus operator in finer detail..
Okay I get that, but then how the heck am I supposed to make it do it each 10th time? EDIT: derp, I'm an idiot. I figured it out now. I now see what you mean by you saying that it can't have a remainder. I need to count each time the player punches an entity and have that instead of the config value. Thanks! ;3 (Your math is wrong though. 2 % 10 is equal to 0.2 and 3 % 10 is equal to 0.3, as you move the comma each time you divide by a number in the tens, hundreds, thousands.)