Posted October 5, 201410 yr hello guys, I have tried for hours to edit the attack damage a player causes, but it didn't work. I have tried the LivingHurtEvent and editing event.ammount, but this made the damage infinite. I have tried player.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue();, but this only edits the base value, there is almost no difference if I striked with a sword. Does somebody know a better way to do this?
October 5, 201410 yr I have tried the LivingHurtEvent and editing event.ammount, but this made the damage infinite. That should have worked fine. Show your code? -TGG
October 5, 201410 yr Author Here is the code: I have used system.out.println for better understanding. package knokko.rpg.events.living; import knokko.rpg.RPG; import knokko.rpg.data.WorldData; import knokko.rpg.entity.effect.EntityBlood; import net.minecraft.entity.EntityCreature; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ChatComponentTranslation; import net.minecraft.util.DamageSource; import net.minecraft.util.EnumChatFormatting; import net.minecraftforge.event.entity.living.LivingHurtEvent; import cpw.mods.fml.common.eventhandler.SubscribeEvent; public class HurtEvent { @SubscribeEvent public void hurtEvent(LivingHurtEvent event){ if(event.entityLiving != null){ if(event.source == DamageSource.fall){ event.setCanceled(true); } if(event.source.getEntity() instanceof EntityPlayer){ EntityPlayer player = (EntityPlayer) event.source.getEntity(); System.out.println("getPlayerStrengt = " + RPG.getPlayerStrengt(player)); System.out.println("event.amount before multitplying = " + event.ammount); event.ammount *= RPG.getPlayerStrengt(player); System.out.println("event.amount after multiplying = " + event.ammount); } if(!event.isCanceled()) { float armor = (float) (event.entityLiving.getTotalArmorValue() * 0.04); float armor2 = 1 - armor; int damage = (int) (event.ammount * armor2); if(event.entityLiving instanceof EntityPlayer && event.source.getEntity() instanceof EntityLiving){ if(!((EntityLiving) event.source.getEntity()).getCustomNameTag().isEmpty()){ EntityPlayer hurtPlayer = (EntityPlayer) event.entityLiving; hurtPlayer.addChatMessage(new ChatComponentTranslation(EnumChatFormatting.RED + "You are hurt for " + damage + " damage by " + ((EntityLiving) event.source.getEntity()).getCustomNameTag())); } } else if(event.entityLiving instanceof EntityPlayer && !(event.source.getEntity() instanceof EntityPlayer) ){ EntityPlayer hurtPlayer = (EntityPlayer) event.entityLiving; hurtPlayer.addChatMessage(new ChatComponentTranslation(EnumChatFormatting.RED + "You are hurt for " + damage + " damage by " + event.source.damageType)); } if(event.source.getEntity() instanceof EntityPlayer){ EntityPlayer player = (EntityPlayer) event.source.getEntity(); WorldData.addXP(player, damage); WorldData.addRaceXp(player, damage % 3); } if(event.entityLiving instanceof EntityPlayer && event.source.getEntity() instanceof EntityPlayer){ EntityPlayer hurtPlayer = (EntityPlayer) event.entityLiving; hurtPlayer.addChatMessage(new ChatComponentTranslation(EnumChatFormatting.RED + "You are hurt for " + damage + " damage by " + ((EntityPlayer) event.source.getEntity()).getDisplayName())); EntityPlayer attacker = (EntityPlayer)event.source.getEntity(); attacker.addChatMessage(new ChatComponentTranslation(EnumChatFormatting.GREEN + "You have hit " + hurtPlayer.getDisplayName() + " for " + damage + " damage.")); } else if(event.source.getEntity() instanceof EntityPlayer && ((EntityLiving) event.entityLiving).getCustomNameTag().isEmpty()){ EntityPlayer attacker = (EntityPlayer) event.source.getEntity(); attacker.addChatMessage(new ChatComponentTranslation(EnumChatFormatting.GREEN + "You have hit a mob for " + damage + " damage.")); } else if(event.source.getEntity() instanceof EntityPlayer){ EntityPlayer attacker = (EntityPlayer) event.source.getEntity(); attacker.addChatMessage(new ChatComponentTranslation(EnumChatFormatting.GREEN + "You have hit " + ((EntityLiving) event.entityLiving).getCustomNameTag() + " for " + damage + " damage.")); } if(event.entityLiving instanceof EntityCreature || event.entityLiving instanceof EntityPlayer){ if(damage >= 1){ event.entityLiving.worldObj.spawnEntityInWorld(new EntityBlood(event.entityLiving.worldObj, event.entityLiving.posX, event.entityLiving.posY, event.entityLiving.posZ, 1)); } if(damage >= 2){ event.entityLiving.worldObj.spawnEntityInWorld(new EntityBlood(event.entityLiving.worldObj, event.entityLiving.posX, event.entityLiving.posY + 1, event.entityLiving.posZ, 1)); } if(damage >= 3){ event.entityLiving.worldObj.spawnEntityInWorld(new EntityBlood(event.entityLiving.worldObj, event.entityLiving.posX + 1, event.entityLiving.posY, event.entityLiving.posZ, 1)); } if(damage >= 4){ event.entityLiving.worldObj.spawnEntityInWorld(new EntityBlood(event.entityLiving.worldObj, event.entityLiving.posX - 1, event.entityLiving.posY, event.entityLiving.posZ, 1)); } if(damage >= 5){ event.entityLiving.worldObj.spawnEntityInWorld(new EntityBlood(event.entityLiving.worldObj, event.entityLiving.posX, event.entityLiving.posY, event.entityLiving.posZ + 1, 1)); } if(damage >= 6){ event.entityLiving.worldObj.spawnEntityInWorld(new EntityBlood(event.entityLiving.worldObj, event.entityLiving.posX, event.entityLiving.posY, event.entityLiving.posZ - 1, 1)); } if(damage >= 7){ event.entityLiving.worldObj.spawnEntityInWorld(new EntityBlood(event.entityLiving.worldObj, event.entityLiving.posX, event.entityLiving.posY, event.entityLiving.posZ, 1)); } if(damage >= { event.entityLiving.worldObj.spawnEntityInWorld(new EntityBlood(event.entityLiving.worldObj, event.entityLiving.posX, event.entityLiving.posY + 0.5, event.entityLiving.posZ, 1)); } if(damage >= 9){ event.entityLiving.worldObj.spawnEntityInWorld(new EntityBlood(event.entityLiving.worldObj, event.entityLiving.posX + 0.5, event.entityLiving.posY, event.entityLiving.posZ, 1)); } if(damage >= 10){ event.entityLiving.worldObj.spawnEntityInWorld(new EntityBlood(event.entityLiving.worldObj, event.entityLiving.posX - 0.5, event.entityLiving.posY, event.entityLiving.posZ, 1)); } if(damage >= 11){ event.entityLiving.worldObj.spawnEntityInWorld(new EntityBlood(event.entityLiving.worldObj, event.entityLiving.posX, event.entityLiving.posY, event.entityLiving.posZ + 0.5, 1)); } if(damage >= 12){ event.entityLiving.worldObj.spawnEntityInWorld(new EntityBlood(event.entityLiving.worldObj, event.entityLiving.posX, event.entityLiving.posY, event.entityLiving.posZ - 0.5, 1)); } } } } } } Here is the important part of the console: getPlayerStrengt = 1.4107303442451825E15 event.amount before multitplying = 1.5 event.amount after multiplying = 2.11609549E15 I can't really help that the file is not very easy...
October 5, 201410 yr By crikey dude, if you multiply the damage by 1x10^15, no wonder it does 'infinite damage' The LivingHurtEvent is working fine, you've done the hard bit already, you just need to figure out why RPG.getPlayerStrength returns 1.4107303442451825E15, which for sure it shouldn't -TGG
October 5, 201410 yr Author I don't understand what you mean, 1.4107303442451825E15 is a number between 1 and 2, isn't it? But I don't know why there is an "E" in the double. RPG.getPlayerStrengt returns that number because I have programmed it that way. It is bound with several classes and playerdata that is added in livinghurtevent. Is it so strange it returns a number between 1 and 2? And do you mean with "1x10^15" 1000000000000000? That would say something. Here is RPG.java if you need it: package knokko.rpg; import knokko.rpg.data.WorldData; import net.minecraft.entity.player.EntityPlayer; public class RPG { public static boolean isKnownClass(String string){ if(string.matches("warrior")){ return true; } else if(string.matches("mage")){ return true; } else { return false; } } public static boolean isKnownRace(String string){ if(string.matches("human")){ return true; } else if(string.matches("orc")){ return true; } else if(string.matches("enderman")){ return true; } else { return false; } } private static double getClassStrengt(String Class){ if(Class.matches("warrior")){ return 1.25; } else if(Class.matches("mage")){ return 0.5; } else { return 1; } } private static double getClassStrengt(EntityPlayer player){ return getClassStrengt(WorldData.getClass(player)); } private static double getRaceStrengt(String race){ if(race.matches("human")){ return 1; } else if(race.matches("orc")){ return 3; } else if(race.matches("enderman")){ return 2; } else { return 1; } } private static double getRaceHealth(String race){ if(race.matches("human")){ return 1; } else if(race.matches("orc")){ return 2.5; } else if(race.matches("enderman")){ return 2; } else { return 1; } } private static double getRaceHealth(EntityPlayer player){ return getRaceHealth(WorldData.getRace(player)); } public static double getPlayerHealth(EntityPlayer player){ double xp = WorldData.getRaceXP(player); double raceHealth = getRaceHealth(player); return raceHealth * (1 + (xp * 0.0001)); } private static double getRaceStrengt(EntityPlayer player){ return getRaceStrengt(WorldData.getRace(player)); } public static double getPlayerStrengt(EntityPlayer player){ double raceStrengt = getRaceStrengt(player); double classStrengt = getClassStrengt(player); double xp = WorldData.getXP(player); double racexp = WorldData.getXP(player); return raceStrengt * (1 + (xp * 0.0001 * racexp)) * classStrengt; } private static double getRaceMana(String race){ if(race.matches("human")){ return 1; } else if(race.matches("enderman")){ return 1.25; } else if(race.matches("orc")){ return 0.25; } else { return 1; } } private static double getClassMana(String Class){ if(Class.matches("warrior")){ return 0.75; } else if(Class.matches("mage")){ return 2; } else { return 1; } } private static double getClassMana(EntityPlayer player){ return getClassMana(WorldData.getClass(player)); } private static double getRaceMana(EntityPlayer player){ return getRaceMana(WorldData.getRace(player)); } public static double getPlayerMana(EntityPlayer player){ double raceMana = getRaceMana(player); double classMana = getClassMana(player); double xp = WorldData.getXP(player); double racexp = WorldData.getRaceXP(player); return raceMana * (1 + (racexp * xp * 0.0001)) * classMana; } } Here is WorldData.java, but it is more playerdata at the moment package knokko.rpg.data; import knokko.rpg.main.s; import net.minecraft.command.PlayerSelector; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; import net.minecraft.world.WorldSavedData; public class WorldData extends WorldSavedData{ public static final String id = s.i; public static final String xp = "experience"; public static final String clas = "class"; public static final String mana = "mana"; public static final String maxmana = "maxmana"; public static final String race = "race"; public static final String racexp = "race xp"; public EntityLivingBase test; public NBTTagCompound players; public WorldData(String id) { super(id); } public WorldData(){ super(id); } @Override public void readFromNBT(NBTTagCompound nbt) { players = (NBTTagCompound) nbt.getTag("players"); } @Override public void writeToNBT(NBTTagCompound nbt) { nbt.setTag("players", players); } public static WorldData get(World world){ WorldData data = (WorldData) world.loadItemData(WorldData.class, id); if(data == null){ data = new WorldData(); world.setItemData(id, data); } return data; } public static int getXP(EntityPlayer player){ if(player == null){ return -1; } else { WorldData data = get(player.worldObj); if(data != null){ if(data.players == null){ data.players = new NBTTagCompound(); } } return data.players.getInteger(player.getUniqueID() + xp + getClass(player)); } } public static void addXP(EntityPlayer player, int amount){ if(player != null){ WorldData data = get(player.worldObj); if(data != null){ if(data.players == null){ data.players = new NBTTagCompound(); } } data.players.setInteger(player.getUniqueID() + xp + getClass(player), data.players.getInteger(player.getUniqueID() + xp + getClass(player)) + amount); data.markDirty(); } } public static void setXP(EntityPlayer player, int amount){ if(player != null){ WorldData data = get(player.worldObj); if(data != null){ if(data.players == null){ data.players = new NBTTagCompound(); } } data.players.setInteger(player.getUniqueID() + xp + getClass(player), amount); data.markDirty(); } } public static String getClass(EntityPlayer player){ if(player != null){ WorldData data = get(player.worldObj); return data.players.getString(player.getUniqueID() + clas); } else { return null; } } public static void setClass(String clas, EntityPlayer player){ if(player != null){ WorldData data = get(player.worldObj); if(data.players == null){ data.players = new NBTTagCompound(); } data.players.setString(player.getUniqueID() + data.clas, clas); data.markDirty(); } } public static int getMana(EntityPlayer player){ if(player != null){ WorldData data = get(player.worldObj); if(data.players == null){ data.players = new NBTTagCompound(); } return data.players.getInteger(player.getUniqueID() + mana + getClass(player)); } else { return -10; } } public static void setMana(EntityPlayer player, int amount){ if(player != null){ WorldData data = get(player.worldObj); if(data.players == null){ data.players = new NBTTagCompound(); } data.players.setInteger(player.getUniqueID() + mana + getClass(player), amount); data.markDirty(); } } public static void addMana(EntityPlayer player, int amount){ if(player != null){ WorldData data = get(player.worldObj); if(data.players == null){ data.players = new NBTTagCompound(); } if(data.players.getInteger(player.getUniqueID() + mana + getClass(player) + amount) > data.players.getInteger(player.getUniqueID() + maxmana + getClass(player))){ data.players.setInteger(player.getUniqueID() + mana + getClass(player), data.players.getInteger(player.getUniqueID() + maxmana + getClass(player))); } else { data.players.setInteger(player.getUniqueID() + mana + getClass(player), data.players.getInteger(player.getUniqueID() + mana + getClass(player)) + amount); } } } public static int getMaxMana(EntityPlayer player){ if(player != null){ WorldData data = get(player.worldObj); if(data.players == null){ data.players = new NBTTagCompound(); } return data.players.getInteger(player.getUniqueID() + maxmana + getClass(player)); } else{ return -10; } } public static void setMaxMana(EntityPlayer player, int amount){ if(player != null){ WorldData data = get(player.worldObj); if(data.players == null){ data.players = new NBTTagCompound(); } data.players.setInteger(player.getUniqueID() + maxmana + getClass(player), amount); data.markDirty(); } } public static void setRace(EntityPlayer player, String race){ if(player != null){ WorldData data = get(player.worldObj); if(data.players == null){ data.players = new NBTTagCompound(); } data.players.setString(player.getUniqueID() + data.race, race); data.markDirty(); } } public static String getRace(EntityPlayer player){ if(player != null){ WorldData data = get(player.worldObj); if(data.players == null){ data.players = new NBTTagCompound(); } return data.players.getString(player.getUniqueID() + race); } else { return null; } } public static void addRaceXp(EntityPlayer player, int amount){ if(player != null){ WorldData data = get(player.worldObj); if(data.players == null){ data.players = new NBTTagCompound(); } data.players.setInteger(player.getUniqueID() + racexp + getRace(player), data.players.getInteger(player.getUniqueID() + racexp + getRace(player)) + amount); data.markDirty(); } } public static void setRaceXP(EntityPlayer player, int amount){ if(player != null){ WorldData data = get(player.worldObj); if(data.players == null){ data.players = new NBTTagCompound(); } data.players.setInteger(player.getUniqueID() + racexp + getRace(player), amount); data.markDirty(); } } public static int getRaceXP(EntityPlayer player){ if(player != null){ WorldData data = get(player.worldObj); if(data.players == null){ data.players = new NBTTagCompound(); } return data.players.getInteger(player.getUniqueID() + racexp + getRace(player)); } else { return -10; } } } Giving the stats is done in the HurtEvent you could allready see.
October 5, 201410 yr Author Thank you for that, now I understand the problem much better. Now I am going to look what the big number is...
October 5, 201410 yr Author I have found out the whole problem, my xp was far too high. So the strike was far too strong. And the getting of xp goes to fase. Thank you both for help.
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.