progamerz Posted September 7, 2017 Share Posted September 7, 2017 I am having some problems using #contains in a magic script, this is my code: private boolean hasRunes() { return getInventory().contains("Fire rune") && getInventory().contains("Air rune") && getInventory().contains("Mind rune"); } What happens is at first it will return true if i have all runes but after casting a spell, it would ALWAYS return false, is it a problem in my code, if so how can i fix it? any suggestions? Thanks Quote Link to comment Share on other sites More sharing options...
John Cena Posted September 7, 2017 Share Posted September 7, 2017 So once the tab has changed off the inventory tab you're saying it goes false. If that's correct then it would be because it doesn't know if your inventory has it because it can't see the inventory? Quote Link to comment Share on other sites More sharing options...
progamerz Posted September 7, 2017 Author Share Posted September 7, 2017 1 minute ago, Donald Trump said: So once the tab has changed off the inventory tab you're saying it goes false. If that's correct then it would be because it doesn't know if your inventory has it because it can't see the inventory? Nope, what i am saying is lets say i am doing auto cast, onStart() returns true that it has the runes, but onLoop() returns false after -1 amount of runes so i am not sure Quote Link to comment Share on other sites More sharing options...
ProjectPact Posted September 7, 2017 Share Posted September 7, 2017 Have you tried the canCast method or whatever it is in the magic api? Quote Link to comment Share on other sites More sharing options...
progamerz Posted September 7, 2017 Author Share Posted September 7, 2017 1 minute ago, Project said: Have you tried the canCast method or whatever it is in the magic api? Yup i tried it would work well but, it keeps switching tabs from inventory to spells tab and reverse Quote Link to comment Share on other sites More sharing options...
Explv Posted September 7, 2017 Share Posted September 7, 2017 25 minutes ago, progamerz said: Yup i tried it would work well but, it keeps switching tabs from inventory to spells tab and reverse Could always check if the spell widget is highlighted or whatever. Or store how many spells you can cast at the start, and decrement every successful spell. Just some ideas, cba to check what's wrong with your code myself. 1 Quote Link to comment Share on other sites More sharing options...
John Cena Posted September 7, 2017 Share Posted September 7, 2017 Is onstart even designed for that usage? Quote Link to comment Share on other sites More sharing options...
progamerz Posted September 7, 2017 Author Share Posted September 7, 2017 (edited) 17 minutes ago, Donald Trump said: Is onstart even designed for that usage? That is called debuging? please if u are here to get 100 post counts, u can check other threads(not being rude) 20 minutes ago, Explv said: Could always check if the spell widget is highlighted or whatever. Or store how many spells you can cast at the start, and decrement every successful spell. Just some ideas, cba to check what's wrong with your code myself. Ok thanks ill try it Edited September 7, 2017 by progamerz Quote Link to comment Share on other sites More sharing options...
dreameo Posted September 7, 2017 Share Posted September 7, 2017 Just keep track # of runes and divide them all by rune needed per spell, before casting, make sure each rune divided by runeUsage >= 1. decrement runes by each spell. 1 Quote Link to comment Share on other sites More sharing options...
John Cena Posted September 7, 2017 Share Posted September 7, 2017 18 minutes ago, progamerz said: That is called debuging? please if u are here to get 100 post counts, u can check other threads(not being rude) Ok thanks ill try it The code should work so obviously it must be a case of that. The code is fine the method of delivery is questionable, do what you want. Quote Link to comment Share on other sites More sharing options...
progamerz Posted September 7, 2017 Author Share Posted September 7, 2017 9 minutes ago, dreameo said: Just keep track # of runes and divide them all by rune needed per spell, before casting, make sure each rune divided by runeUsage >= 1. decrement runes by each spell. This would work thanks for the idea Quote Link to comment Share on other sites More sharing options...
dreameo Posted September 7, 2017 Share Posted September 7, 2017 12 minutes ago, progamerz said: This would work thanks for the idea Quote Link to comment Share on other sites More sharing options...
liverare Posted September 8, 2017 Share Posted September 8, 2017 (edited) /** * Calculate how many casts you can perform. This takes infinite-rune items * (e.g. kodai wand/tomb of fire/staves) into consideration too. * * @param airRunesRequired - Air runes required * @param waterRunesRequired - Water runes required * @param earthRunesRequired - Earth runes required * @param fireRunesRequired - Fire runes required * @param bodyRunesRequired - Body runes required * @param mindRunesRequired - Mind runes required * @param cosmicRunesRequired - Cosmic runes required * @param chaosRunesRequired - Chaos runes required * @param natureRunesRequired - Nature runes required * @param lawRunesRequired - Law runes required * @param deathRunesRequired - Death runes required * @param astralRunesRequired - Astral runes required * @param bloodRunesRequired - Blood runes required * @param soulRunesRequired - Soul runes required * @return castCount - How many casts can be performed */ private long getCastCount( int airRunesRequired, int waterRunesRequired, int earthRunesRequired, int fireRunesRequired, int bodyRunesRequired, int mindRunesRequired, int cosmicRunesRequired, int chaosRunesRequired, int natureRunesRequired, int lawRunesRequired, int deathRunesRequired, int astralRunesRequired, int bloodRunesRequired, int soulRunesRequired ) { long castCount = Long.MAX_VALUE; long[][] amounts = new long[12][2]; long[] amount; boolean infiniteAirRunes = equipment.isWearingItemThatContains(EquipmentSlot.WEAPON, "Air", "Mist", "Dust", "Smoke"); boolean infiniteWaterRunes = equipment.isWearingItemThatContains(EquipmentSlot.WEAPON, "Water", "Mist", "Mud", "Steam", "Kodai"); boolean infiniteEarthRunes = equipment.isWearingItemThatContains(EquipmentSlot.WEAPON, "Earth", "Dust", "Mud", "Lava"); boolean infiniteFireRunes = equipment.isWearingItemThatContains(EquipmentSlot.WEAPON, "Fire", "Smoke", "Steam", "Lava") || equipment.isWearingItemThatContains(EquipmentSlot.SHIELD, "Tomb of fire"); long mistRuneCount = inventory.getAmount("Mist rune"); long dustRuneCount = inventory.getAmount("Dust rune"); long mudRuneCount = inventory.getAmount("Mud rune"); long smokeRuneCount = inventory.getAmount("Smoke rune"); long steamRuneCount = inventory.getAmount("Steam rune"); long lavaRuneCount = inventory.getAmount("Lava rune"); amounts[0][0] = airRunesRequired; amounts[1][0] = waterRunesRequired; amounts[2][0] = earthRunesRequired; amounts[3][0] = fireRunesRequired; amounts[4][0] = bodyRunesRequired; amounts[5][0] = mindRunesRequired; amounts[6][0] = cosmicRunesRequired; amounts[7][0] = chaosRunesRequired; amounts[8][0] = natureRunesRequired; amounts[9][0] = lawRunesRequired; amounts[10][0] = deathRunesRequired; amounts[11][0] = astralRunesRequired; amounts[12][0] = bloodRunesRequired; amounts[13][0] = soulRunesRequired; // ELEMENTAL RUNES if (infiniteAirRunes) { amounts[0][1] = -1; } else { amounts[0][1] += inventory.getAmount("Air rune"); amounts[0][1] += mistRuneCount; amounts[0][1] += dustRuneCount; amounts[0][1] += smokeRuneCount; } if (infiniteWaterRunes) { amounts[1][1] = -1; } else { amounts[1][1] += inventory.getAmount("Water rune"); amounts[1][1] += mistRuneCount; amounts[1][1] += mudRuneCount; amounts[1][1] += steamRuneCount; } if (infiniteEarthRunes) { amounts[2][1] = -1; } else { amounts[2][1] += inventory.getAmount("Earth rune"); amounts[2][1] += dustRuneCount; amounts[2][1] += mudRuneCount; amounts[2][1] += lavaRuneCount; } if (infiniteFireRunes) { amounts[3][1] = -1; } else { amounts[3][1] += inventory.getAmount("Fire rune"); amounts[3][1] += smokeRuneCount; amounts[3][1] += steamRuneCount; amounts[3][1] += lavaRuneCount; } // NON-ELEMENTAL RUNES amounts[4][1] = inventory.getAmount("Body rune"); amounts[5][1] = inventory.getAmount("Mind rune"); amounts[6][1] = inventory.getAmount("Cosmic rune"); amounts[7][1] = inventory.getAmount("Chaos rune"); amounts[8][1] = inventory.getAmount("Nature rune"); amounts[9][1] = inventory.getAmount("Law rune"); amounts[10][1] = inventory.getAmount("Death rune"); amounts[11][1] = inventory.getAmount("Astral rune"); amounts[12][1] = inventory.getAmount("Blood rune"); amounts[13][1] = inventory.getAmount("Soul rune"); for (int i = 0; i < amounts.length; i++) { amount = amounts[i]; long requiredCount = amount[0]; long runeCount = amount[1]; if (requiredCount > 0 && runeCount != -1) { castCount = Math.min(castCount, runeCount / requiredCount); } } return castCount; } Edited September 8, 2017 by liverare 1 Quote Link to comment Share on other sites More sharing options...
progamerz Posted September 8, 2017 Author Share Posted September 8, 2017 4 hours ago, liverare said: /** * Calculate how many casts you can perform. This takes infinite-rune items * (e.g. kodai wand/tomb of fire/staves) into consideration too. * * @param airRunesRequired - Air runes required * @param waterRunesRequired - Water runes required * @param earthRunesRequired - Earth runes required * @param fireRunesRequired - Fire runes required * @param bodyRunesRequired - Body runes required * @param mindRunesRequired - Mind runes required * @param cosmicRunesRequired - Cosmic runes required * @param chaosRunesRequired - Chaos runes required * @param natureRunesRequired - Nature runes required * @param lawRunesRequired - Law runes required * @param deathRunesRequired - Death runes required * @param astralRunesRequired - Astral runes required * @param bloodRunesRequired - Blood runes required * @param soulRunesRequired - Soul runes required * @return castCount - How many casts can be performed */ private long getCastCount( int airRunesRequired, int waterRunesRequired, int earthRunesRequired, int fireRunesRequired, int bodyRunesRequired, int mindRunesRequired, int cosmicRunesRequired, int chaosRunesRequired, int natureRunesRequired, int lawRunesRequired, int deathRunesRequired, int astralRunesRequired, int bloodRunesRequired, int soulRunesRequired ) { long castCount = Long.MAX_VALUE; long[][] amounts = new long[12][2]; long[] amount; boolean infiniteAirRunes = equipment.isWearingItemThatContains(EquipmentSlot.WEAPON, "Air", "Mist", "Dust", "Smoke"); boolean infiniteWaterRunes = equipment.isWearingItemThatContains(EquipmentSlot.WEAPON, "Water", "Mist", "Mud", "Steam", "Kodai"); boolean infiniteEarthRunes = equipment.isWearingItemThatContains(EquipmentSlot.WEAPON, "Earth", "Dust", "Mud", "Lava"); boolean infiniteFireRunes = equipment.isWearingItemThatContains(EquipmentSlot.WEAPON, "Fire", "Smoke", "Steam", "Lava") || equipment.isWearingItemThatContains(EquipmentSlot.SHIELD, "Tomb of fire"); long mistRuneCount = inventory.getAmount("Mist rune"); long dustRuneCount = inventory.getAmount("Dust rune"); long mudRuneCount = inventory.getAmount("Mud rune"); long smokeRuneCount = inventory.getAmount("Smoke rune"); long steamRuneCount = inventory.getAmount("Steam rune"); long lavaRuneCount = inventory.getAmount("Lava rune"); amounts[0][0] = airRunesRequired; amounts[1][0] = waterRunesRequired; amounts[2][0] = earthRunesRequired; amounts[3][0] = fireRunesRequired; amounts[4][0] = bodyRunesRequired; amounts[5][0] = mindRunesRequired; amounts[6][0] = cosmicRunesRequired; amounts[7][0] = chaosRunesRequired; amounts[8][0] = natureRunesRequired; amounts[9][0] = lawRunesRequired; amounts[10][0] = deathRunesRequired; amounts[11][0] = astralRunesRequired; amounts[12][0] = bloodRunesRequired; amounts[13][0] = soulRunesRequired; // ELEMENTAL RUNES if (infiniteAirRunes) { amounts[0][1] = -1; } else { amounts[0][1] += inventory.getAmount("Air rune"); amounts[0][1] += mistRuneCount; amounts[0][1] += dustRuneCount; amounts[0][1] += smokeRuneCount; } if (infiniteWaterRunes) { amounts[1][1] = -1; } else { amounts[1][1] += inventory.getAmount("Water rune"); amounts[1][1] += mistRuneCount; amounts[1][1] += mudRuneCount; amounts[1][1] += steamRuneCount; } if (infiniteEarthRunes) { amounts[2][1] = -1; } else { amounts[2][1] += inventory.getAmount("Earth rune"); amounts[2][1] += dustRuneCount; amounts[2][1] += mudRuneCount; amounts[2][1] += lavaRuneCount; } if (infiniteFireRunes) { amounts[3][1] = -1; } else { amounts[3][1] += inventory.getAmount("Fire rune"); amounts[3][1] += smokeRuneCount; amounts[3][1] += steamRuneCount; amounts[3][1] += lavaRuneCount; } // NON-ELEMENTAL RUNES amounts[4][1] = inventory.getAmount("Body rune"); amounts[5][1] = inventory.getAmount("Mind rune"); amounts[6][1] = inventory.getAmount("Cosmic rune"); amounts[7][1] = inventory.getAmount("Chaos rune"); amounts[8][1] = inventory.getAmount("Nature rune"); amounts[9][1] = inventory.getAmount("Law rune"); amounts[10][1] = inventory.getAmount("Death rune"); amounts[11][1] = inventory.getAmount("Astral rune"); amounts[12][1] = inventory.getAmount("Blood rune"); amounts[13][1] = inventory.getAmount("Soul rune"); for (int i = 0; i < amounts.length; i++) { amount = amounts[i]; long requiredCount = amount[0]; long runeCount = amount[1]; if (requiredCount > 0 && runeCount != -1) { castCount = Math.min(castCount, runeCount / requiredCount); } } return castCount; } Tyvm i already made one but, it isn't understandable as this thanks will upgrade to this Quote Link to comment Share on other sites More sharing options...