#Need a tag for hostile mobs

48 messages · Page 1 of 1 (latest)

errant wren
#

Making a quest in FTB quests and I need to make a script or something with KubeJS that makes it so that killing any hostile mob completes the quest. Its only letting me select one hostile mob, like a zombie or a skeleton. I want the quest to be completed if ANY hostile mob is killed

rare waveBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

wintry pecanBOT
#

Please read #rules 5.

FTB support is not offered in this server.
If you need help with FTB-related mods, packs, or scripts, head over to the official FTB Discord Server by clicking the button:

old karma
#

if you are specifically trying to use kubejs for it, then say so

errant wren
#

wait theres a way to do it without using Kubejs?

#

also that link expired

errant wren
#

hello?

wintry pecanBOT
#

Please be patient, we're helping as fast as we can
We volunteer our time and knowledge to help people as we can.
Not everyone here will have your answer the moment you want it.
Time zones, work/life/schedules etc. also change when people are available to help.

TL;DR: Please have patience. IF and WHEN someone knows, they will assist you.

wintry pecanBOT
#

@old karma updated macro </ftb:967625732551503922>!

old karma
#

link fixed

old karma
#

hang on thonk how did i misread the original question so badly

#

assuming that ftbquests does allow for entity type tags, you can make a custom one with the ServerEvents.tags('entity_type' event.
Then you can loop over all entity types in the game (probably using something like Utils.registries.entityTypes.keySet.forEach(() => stuff()) and check something to see if they are hostile, which is...difficult to say the least
when you loop over all entities in the game you will be looping over entity types, not actual entities, so most things you could check (like if it inherits from Monster, or has an attack goal) cant be checked. im not too sure how you could solve that issue... it may be easier to just write a manual list

errant wren
#

you cant choose a tag for entitys :C

old karma
#

oh great, and its been a requested feature for only almost three years https://github.com/FTBTeam/FTB-Mods-Issues/issues/38 🙄.
In that case i believe you can use a custom task that you can complete with kubejs, but i havent used that before so wont be as helpful

#

which takes the task id as an extra parameter

#

tho.. you need to listen to the entity death event, then do something in this event, so well need to use player persistent data

old karma
#
//requires: ftbquests
//side: server

const $Monster = Java.loadClass('net.minecraft.world.entity.monster.Monster')
EntityEvents.death(event => {
  if (event.entity instanceof $Monster // check if it is a 'monster', which should be basically all hostile mobs
    && event.source.entity != null && event.source.entity.isPlayer() // check if a player killed it
  ) {
    let player = event.source.entity
    if (player.persistentData.hostilesKilled) { // this is true if it is defined as a number greater than 0. if it is undefined, or 0, the else block will execute instead
      player.persistentData.hostilesKilled++ // increase the number of hostiles killed by one
    } else { // if it is not set already then we have to initialize it as a number, else we will get NaNs being thrown around
      // this will also run when it is set to 0, but theres no harm in that
      player.persistentData.hostilesKilled = 1
    }
  }
})

// then the task event
FTBQuestsEvents.customTask('task id goes here', event => {
  event.check = (taskData, player) => {
    if (player.persistentData.hostilesKilled > 0) // if they have killed mobs since we last checked, then increase the progress by that amount
      taskData.addProgress(player.persistentData.hostilesKilled)
      player.persistentData.hostilesKilled = 0 // reset the temp tracker to 0 so it isnt counted twice
    }
  }
  // you can do other stuff here like say how often it should be checked. See <https://github.com/FTBTeam/FTB-XMod-Compat/blob/main/common/src/main/java/dev/ftb/mods/ftbxmodcompat/ftbquests/kubejs/CustomTaskEventJS.java#L21-L30> for what you can do
})

Based on the docs, source code and my knowledge of kubejs, this should work however it is untested
however as often happens when i dont test things its almost guaranteed to not run for some reason or another. im happy to help with errors

old karma
#

make a custom task in ftbquests

#

put the script into a new script file in server_scripts
then copy the task id to the bit that says task id goes here
then save and /reload and the task should progress when you kill a mob

errant wren
old karma
#

ah

#

missing a { after the closing bracket of the if condition

#
-    if (player.persistentData.hostilesKilled > 0) // if they have killed mobs since we last checked, then increase the progress by that amount
+    if (player.persistentData.hostilesKilled > 0) { // if they have killed mobs since we last checked, then increase the progress by that amount
errant wren
#

also how do i add tags to items

wintry pecanBOT
#

You can modify tags with KubeJS, and the wiki has a page on that!

errant wren
#

im confused as hell on this

#

so would I do

#

ServerEvents.tags('item', event => {
// Get the #vsas_woodenpickaxes tag collection and add oak pickaxe to it
event.add('vsas_woodenpickaxes', 'minecraft:wooden_pickaxe')

#

?

#

if I wanted to add the Oak pickaxe to the list of custom wooden pickaxes

old karma
#

yes

errant wren
#

ServerEvents.tags('item', event => {
// Get the #vsas_woodenpickaxes tag collection and add oak pickaxe to it
event.add('vsas_woodenpickaxes', 'minecraft:wooden_pickaxe')})

#

do i put task id where it says task id goes here

#

so 379529F761EA6B8E

old karma
#

yes

errant wren
#

its not working

#

//requires: ftbquests
//side: server

const $Monster = Java.loadClass('net.minecraft.world.entity.monster.Monster')
EntityEvents.death(event => {
if (event.entity instanceof $Monster // check if it is a 'monster', which should be basically all hostile mobs
&& event.source.entity != null && event.source.entity.isPlayer() // check if a player killed it
) {
let player = event.source.entity
if (player.persistentData.hostilesKilled) { // this is true if it is defined as a number greater than 0. if it is undefined, or 0, the else block will execute instead
player.persistentData.hostilesKilled++ // increase the number of hostiles killed by one
} else { // if it is not set already then we have to initialize it as a number, else we will get NaNs being thrown around
// this will also run when it is set to 0, but theres no harm in that
player.persistentData.hostilesKilled = 1
}
}
})

// then the task event
FTBQuestsEvents.customTask('7E72BFB3C073DEEC', event => {
event.check = (taskData, player) => {
if (player.persistentData.hostilesKilled > 0) { // if they have killed mobs since we last checked, then increase the progress by that amount
taskData.addProgress(player.persistentData.hostilesKilled)
player.persistentData.hostilesKilled = 0 // reset the temp tracker to 0 so it isnt counted twice
}
}
// you can do other stuff here like say how often it should be checked. See https://github.com/FTBTeam/FTB-XMod-Compat/blob/main/common/src/main/java/dev/ftb/mods/ftbxmodcompat/ftbquests/kubejs/CustomTaskEventJS.java#L21-L30 for what you can do
})

wintry pecanBOT
#

Never say 'it crashed', 'it errored', or 'it didn't work' without providing the full crash report, log, and scripts!

old karma
#

and how is it not working

#

what does happen (even if thats 'the counter doesnt go up/the task never completes)

errant wren
#

nothing happens at all when I kill a monster. the quest doesnt complete

old karma
#

send the logs

errant wren
#

there is no logs. it says no error. it just doesnt complete the quest

old karma
#

there are logs

#

there are always logs