#Tone down difficulty when dying too much
66 messages · Page 1 of 1 (latest)
Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!
It seems difficulty effects all based on position? Weird, but it’s possible to decrease via DifficultyData.
I’ll check more into this later and provide code on how to do so
Alrighty
am i correct that difficulty effect all players, or is it position based? i'm still confused
ahh difficulty is based on position from spawn
we can try this one if it doesn't work then position based.
const $DifficultyData = Java.loadClass('io.github.flemmli97.improvedmobs.difficulty.DifficultyData');
EntityEvents.death('minecraft:player', event => {
let player = event.getEntity();
let difficultyData = $DifficultyData.get(event.server);
let difficultyLevel = difficultyData.getDifficulty(event.level, player);
let difficultyDistance = $DifficultyData.getDifficultyFromDist(event.level, player.position);
difficultyData.setDifficulty(Math.max(0, difficultyLevel - difficultyDistance), event.server);
// difficultyData.save();
})
confusing because you can get the difficulty from a specific level, but you can't set the difficulty to that level, only overworld
at first i was getting the difficulty and difficulty distance from event.server but replaced it with event.level.
i'm not sure what to use.
hopefully this works. i haven't tested but the code is what it should be
and not sure how much of the difficulty should be decreased. set it back to 0 if died? feel fre to change.
so the mod has a difficulty for each player
my goal was to make it so whenever you died, you would decrease the difficulty a little bit
@olive wharf
i just don't see a way to do it per player
i have wrote this but its kind of shitty i wont lie
// Persistent storage for tracking deaths
let death_tracker = {};
function initializePlayerData(player_name) {
return {
deaths: 0,
difficulty: -4 // Initial difficulty
};
}
// Function to update the player's difficulty based on death count
function updatePlayerDifficulty(player, player_name) {
let player_data = death_tracker[player_name];
// Increment death count
player_data.deaths++;
// Calculate the exponential difficulty multiplier and decrease amount
const death_multiplier = Math.pow(2, player_data.deaths - 1);
const decrease_amount = -1 / death_multiplier;
// Update difficulty, ensuring it doesn't go below -2
const new_difficulty = Math.max(-2, player_data.difficulty - decrease_amount);
player_data.difficulty = new_difficulty;
// Run the command to update the player's difficulty
player.server.runCommandSilent(`/improvedmobs difficulty player ${player_name} add ${new_difficulty.toFixed(2)}`);
// Notify the player (for debugging purposes)
player.tell(`Your death has decreased your Improved Mobs difficulty to ${new_difficulty.toFixed(2)}.`);
}
// Event listener for player death
EntityEvents.death(event => {
let player = event.player;
// Ensure the player exists before continuing
if (!player || !player.username) {
return; // Exit the function if the player is null or username is not available
}
let player_name = player.username;
// Initialize player data if it doesn't exist
if (!death_tracker[player_name]) {
death_tracker[player_name] = initializePlayerData(player_name);
}
// Update the player's difficulty after death
updatePlayerDifficulty(player, player_name);
});```
like this works, but its going below 0 difficulty, like into the negatives
and i dont want that, i want the difficulty to stop decreasing alltogether when it reaches 0
"ensuring it doesn't go below -2"
that was your intent to not go below -2 lol
Math.max(0, player_data.difficulty - decrease_amount) in that case
that doesnt even work
i kept that there to see if it even worked
and it didnt
it goes even below -2
ok looking at the command source i kindof get it now
if i do this, difficulty increases rather than decrease
const $CrossPlatformStuff = Java.loadClass('io.github.flemmli97.improvedmobs.platform.CrossPlatformStuff');
EntityEvents.death('minecraft:player', event => {
let player = event.getEntity();
if (!death_tracker[player.username]) {
death_tracker[player.username] = initializePlayerData(player.username);
}
death_tracker[player.username].deaths += 1;
let death_multiplier = Math.pow(2, death_tracker[player.username].deaths - 1);
let decrease_amount = -1 / death_multiplier;
death_tracker[player.username].difficulty = Math.max(0, death_tracker[player.username].difficulty - decrease_amount)
let iplayer = $CrossPlatformStuff.INSTANCE.getPlayerDifficultyData(player);
// let difficultyLevel = iplayer.getDifficultyLevel()
iplayer.setDifficultyLevel(death_tracker[player.username].difficulty)
iplayer.save();
player.tell(`Your death has decreased your Improved Mobs difficulty to ${death_tracker[player.username].difficulty.toFixed(2)}.`);
})
apparently via config the difficulty can be global or per player.
im aware of that
the issue however is that once it increases, it cant be decreased whatsoever
that's how you get and set the difficulty. now how much to decrease it by?
do you want to decrease based on the position from spawn still?
decreased multiplier?
fraction of difficulty?
how i made it is basically starts from a flat 2, to then decrease for each death
so 2, 1.5, 1.25 and so on
doesnt take into consideration anything
right so the way you have it is -1 / playerDeaths
approx, yes
-1, -0.5, -0.3, etc
yeah
there i updated code above. is that good?
updated again
i took account for the original code you had
should also not go negative either and properly decreases.
oh and last thing
i see why it goes negative. you're storing your own difficulty (-4 initially) instead of taking into account the current difficulty.
this will constantly keep going negative below -4. (well with the new code, difficulty will always be 0 since it's death_tracker.death will always be negative)
think you want to initializePlayerData with the current difficulty level (not -4) before decreasing
i don't know how much the level increases overtime to decide how much it needs to be decreased when player dies.
that's why i thought a decrease multiplier from the difficulty level the mod has would be better than using your own difficulty level?
getting rid of death_tracker entirely
instead maybe something like this? this will half the difficulty level each death and will not go below 0
const $CrossPlatformStuff = Java.loadClass('io.github.flemmli97.improvedmobs.platform.CrossPlatformStuff');
EntityEvents.death('minecraft:player', event => {
let player = event.getEntity();
let iplayer = $CrossPlatformStuff.INSTANCE.getPlayerDifficultyData(player);
let new_difficulty = Math.max(0, iplayer.getDifficultyLevel() * 0.5)
iplayer.setDifficultyLevel(new_difficulty);
iplayer.save();
player.tell(`Your death has decreased your Improved Mobs difficulty to ${new_difficulty}.`);
})
and also maybe check if the player actually dies by a mob before decreasing?
but you have the code now to get and set difficulty level. you can adjust to your likings how you want.
ill test it now
so which one should i be testing exactly?
when i use this, im getting this error:
Error in 'EntityEvents.death': TypeError: Cannot find function getDifficultyLevel in object Optional[io.github.flemmli97.improvedmobs.forge.capability.PlayerDifficultyData@487f4c05].
alright, i fixed it
thank you, this code does exactly what i want it to do
i appreciate the help immensely!
Ticket closed!
how'd that happen?
