dnd 5e – What is the earliest level that a player character can gain access to a wish spell?

Wish is a 9th-level spell. It’s only on the wizard and sorcerer spell lists.

Full caster classes (including sorcerers and wizards) gain 9th-level spell slots at level 17 in the class. Multiclassed spellcasters know/prepare spells as if single-classed, so you need at least 17 levels in either sorcerer or wizard to have a 9th-level spell slot and thus be able to learn the spell.

The one exception is the bard class, thanks to their Magical Secrets feature:

By 10th level, you have plundered magical knowledge from a wide spectrum of disciplines. Choose two spells from any class, including this one. A spell you choose must be of a level you can cast, as shown on the Bard table, or a cantrip.

The chosen spells count as bard spells for you and are included in the number in the Spells Known column of the Bard table.

You learn two additional spells from any class at 14th level and again at 18th level.

Using the Magical Secrets feature, you can learn 2 spells from any class spell list at 18th level. As full casters, bards also get a 9th-level slot by that point, so they can learn wish using the feature.

Finally, Arcana Domain clerics get the Arcane Mastery feature at 17th level (SCAG, p. 126):

At 17th level, you choose four spells from the wizard spell list, one from each of the following levels: 6th, 7th, 8th, and 9th. You add them to your list of domain spells. Like your other domain spells, they are always prepared and count as cleric spells for you.

They could choose wish as their 9th-level spell from the feature. (Thanks to David Coffron for pointing this out!)

There are a few magic items that can let you cast the wish spell or cast it for you. However, it’s up to the DM whether to even roll on the tables to determine treasure, or whether to allow you to gain items that let you cast the wish spell. Given how powerful wish can be, the DM might be hesitant to do so any sooner than you could normally learn the spell.

The lowest-rarity item, the Efreeti Bottle, is still listed as “very rare”, and only has a 10% chance of giving you wishes:

When you use an action to remove the stopper, a cloud of thick smoke flows out of the bottle. At the end of your turn, the smoke disappears with a flash of harmless fire, and an efreeti appears in an unoccupied space within 30 feet of you.

The first time the bottle is opened, the GM rolls to determine what happens.

On a roll of 91-00 on the percentile dice (“d100”), it gives the following result:

The efreeti can cast the wish spell three times for you. It disappears when it grants the final wish or after 1 hour, and the bottle loses its magic.

All but one of the remaining items that allow you to cast wish are legendary items. The first and probably most controversial is the Deck of Many Things. Only one of the cards in the Deck, the Moon, lets you cast wish (with the other possible effects ranging from campaign-destroyingly good to campaign-destroyingly bad):

Moon. You are granted the ability to cast the wish spell 1d3 times.

A much simpler item that lets you cast wish is the Luck Blade:

Wish. The sword has 1d4–1 charges. While holding it, you can use an action to expend 1 charge and cast the wish spell from it. This property can’t be used again until the next dawn. The sword loses this property if it has no charges.

The Ring of Three Wishes is probably the most straightforwardly named of the bunch, and does what it says on the tin:

While wearing this ring, you can use an action to expend 1 of its 3 charges to cast the wish spell from it. The ring becomes nonmagical when you use the last charge.

And finally, the last item (or pair of items) is an artifact, the Eye and Hand of Vecna (DMG, p. 224). Attuning to both items involves some self-mutilation (and removing either one afterwards kills you), but you gain a variety of benefits and incur a few dangers. If you attune to both, the last benefit listed is:

You can use an action to cast wish. This property can’t be used again until 30 days have passed.

There is, of course, the possibility (however unlikely) of acquiring a 9th-level spell scroll with the wish spell on it. Spell scrolls can only be used by those with the spell on their class spell list, so only sorcerers or wizards can do it (or bards who pick the spell with the Magical Secrets feature, but they’d already know the spell that way so it’s kind of pointless for them). Note that even lower-level sorcerers/wizards could use a wish spell scroll, but they’d have to pass a DC 19 check using their spellcasting ability (Charisma for sorcerers, Intelligence for wizards):

If the spell is on your class’s spell list but of a higher level than you can normally cast, you must make an ability check using your spellcasting ability to determine whether you cast it successfully. The DC equals 10 + the spell’s level. On a failed check, the spell disappears from the scroll with no other effect.

The Magic Item Rarity table on DMG p. 135 suggests that very rare items be limited to 11th-level or higher characters, and that legendary items be limited to 17th-level or higher characters.

However, the magic item tables on the following pages do list specific magic items as possible treasures, and the treasure hoard tables do give guidance on randomly determining the contents of a large cache of treasure, whether that’s the accumulated wealth of a large group of creatures, the belongings of a single powerful creature that hoards wealth, or a reward from a wealthy/powerful benefactor for completing a quest (DMG p. 133):

When determining the contents of a hoard belonging to one monster, use the table that corresponds to that monster’s challenge rating. When rolling to determine a treasure hoard belonging to a large group of monsters, use the challenge rating of the monster that leads the group. If the hoard belongs to no one, use the challenge rating of the monster that presides over the dungeon or lair you are stocking. If the hoard is a gift from a benefactor, use the challenge rating equal to the party’s average level.

Every treasure hoard contains a random number of coins, as shown at the top of each table. Roll a d100 and consult the table to determine how many gemstones or art objects the hoard contains, if any. Use the same roll to determine whether the hoard contains magic items.

The Efreeti Bottle corresponds to a roll of 71 on the d100 on Magic Item Table H (DMG p. 148). Magic Item Table I (DMG p. 149) includes the Luck Blade (corresponding to a roll of 11–15), the Deck of Many Things (81), and the Ring of Three Wishes (94).

The table for treasure hoards corresponding to CR 5–10 creatures (DMG, p. 137) has two rows that involve rolling once on Magic Item Table H; following these guidelines, it’s only possible if the DM rolls 99 or 100 on the d100 when determining the treasure hoard. In order to then get an Efreeti Bottle, the DM would need to roll a 71 on another d100 for the magic item table. (And in order to then have the efreeti grant you 3 wishes, they’d need to roll a 91-00 on the d100 when the bottle was actually used by a character.)

Alternately, the treasure hoard table for CR 11–16 creatures (DMG, p. 138) includes a few more rolls that could theoretically result in an item that lets you cast wish. If the DM rolls 83–92 on the d100 for the treasure hoard table, they can roll 1d4 times on Magic Item Table H (to potentially get an Efreeti Bottle). If they instead roll 93–00 on the d100 for the treasure hoard table, they can roll once on Magic Item Table I. (And they’d then need to roll an 11–15, 81, or 94 on the d100 for the magic item table to result in an item that can let you cast wish.)

Finally, the treasure hoard table for CR 17+ (DMG, p. 139) states that a roll of 73–80 corresponds to 1d4 rolls on Magic Item Table H; a roll of 81–00 corresponds to 1d4 rolls on Magic Item Table I.

Artifacts (such as the Eye and Hand of Vecna) are a totally different beast, beyond even the highest treasure hoard or magic item tables (DMG, p. 219):

An artifact is a unique magic item of tremendous power, with its own origin and history. An artifact might have been created by gods or mortals of awesome power. It could have been created in the midst of a crisis that threatened a kingdom, a world, or the entire multiverse, and carry the weight of that pivotal moment in history.

(…)

Characters don’t typically find artifacts in the normal course of adventuring. In fact, artifacts only appear when you want them to, for they are as much plot devices as magic items. Tracking down and recovering an artifact is often the main goal of an adventure. Characters must chase down rumors, undergo significant trials, and venture into dangerous, half-forgotten places to find the artifact they seek. Alternatively, a major villain might already have the artifact. Obtaining and destroying the artifact could be the only way to ensure that its power can’t be used for evil.

All in all, the DMG does not really expect low-level characters to be able to cast wish even through magic items. You can only expect to have a fairly significant chance to get a magic item that lets you do so once you’re already high enough level to cast the spell (assuming you don’t multiclass). This is probably at least somewhat by design, given that even the spell description begins:

Wish is the mightiest spell a mortal creature can cast. By simply speaking aloud, you can alter the very foundations of reality in accord with your desires.

Frankly, you’re better off talking to your DM about finding a way to cast simulacrum directly rather than trying to cast wish to replicate its effect, given how potentially world-changing (and campaign-affecting) wish can be.

dnd 5e – Problematic player constantly looking to power play

This is called ‘arguing for advantage’, and it’s not really a problem unique to DnD.

‘I should get X because of Y reason’ isn’t usually about the Y reason – the person just wants X. The Y can be anything, and frankly doesn’t matter. When your human perception and judgement (aka basic social interaction skills) tell you that someone is arguing for an advantage rather than for some other reason (because they think Y is more logical, because they think Y is a better story, because they don’t like Z for personal reasons, etc) you should simply say ‘no’.

You may need to say no quite a few times. The arguing for advantage may morph into other means of social pressuring, like vague blame, repetitive asking, calling-in allies, convincing the crowd, so on. It’s entirely possible for this to suck the fun out of the game and make continuing with that player entirely unworkable. However you have a considerable advantage in this situation due to explicitly being the authority, limiting the social pressure it is acceptable to bring against you and giving them an ‘uphill battle’ in attempting to gain the advantage they are seeking.

If need be, explain that in this game the DM is the final arbiter of all rules interactions and world setting. They should be impartial, like a referee, and consult the table’s preferences to make a good game but when it comes down to it the DM is the one who decides what rules are used, makes up new rules if necessary, arbitrates any disputes, and gets to say what hair colour exactly that npc’s beard is. That’s the basic rule of the game and it is what people agree to implicitly when they sit down to game with people.

You can also do the following things.

Provide examples of what advantages can be successfully argued for.

Or ‘asked’ for. The paladin asks if there is a church in the village? You answer ‘yes’. The fighter wants to know if after seeing an awesome polearm fighter he can go learn from him? Yes. You change the fighter’s Fighting Style to Great Weapon Mastery as well, as he’s now using a halberd rather than the two shortswords he was previously, to reflect the results of his character training with the Yuan-ti Spearmaster for those 3 weeks. The mage wants to use a readied frost spell to turn the falling poison rain into ice, so it bounces off the party’s raised shields rather than dowsing and poisoning them? Yes. By agreeing to more reasonable requests, you show the arguing player that things can be gained by toning down his demands – this often leads to the demands being toned down.

Talk to them out of game.

Explain that DnD is a cooperative game and you don’t want one character to be more mechanically powerful than the others as it makes your job harder. Likewise, that giving one player exceptions to the rules and not others both makes your job harder (have to remember two sets of rules) but is also unfair. Explain that GMing is quite difficult for both mechanical and storytelling reasons, and you’d appreciate their help in keeping it simpler. Accusations and further arguing are rarely helpful – informing them of your point of view in a non-accusatory way and thus creating empathy is likely to be more helpful.

Move the game along.

If a player is arguing with you about getting whatever, you can simply move the game along – turn to another player, and tell them that they ‘find the innkeeper’ or whatever they were doing before the arguing player redirected the conversation onto why they should have X. If the player is ‘interrupting’ to make his arguments, it’s rude – this will lead to less arguing overall, as you can also make the ‘sorry but said he wanted to do X, so i’m talking to him now after talking to you about how you want a Flametongue’ which is reasonable/sounds reasonable.

Ultimately this is a social problem. It is about someone not sticking to the implicit rules of an activity. It needs to be solved through that lens, and the RPG-specific tactics available are limited.

There’s also something else that you’ve hinted at.

You’ve talked about whose ‘fault’ the TPK was, used the term ‘power play’ without qualifier or explanation, and talked about how someone making a choice in-game is a ‘problem player’ behaviour (hiring or firing an NPC guide).

These are all red flags. A GM blaming a TPK on a player or players instead of acknowledging that as the designer of the world they have significant control over whether the party lives or dies, someone who does not qualify what ‘power play’ entails to them but assumes it is universal, and a GM who assumes that in-game actions are universally for out-of-game reasons, are all common red flags for negative GM behaviours and attitudes in TTRPGs. I have and will again avoid a game with a GM who talks about such things, expecting that at the table their game will just not be.. good.

While from your question I lack any detail at all to determine whether these hinted-at problems actually exist, i’d suggest in general that whenever you are trying to determine how to interact with someone in a positive way that you also look at your own behaviour in an objective and logical fashion to find out if your own preconceptions, expectations, or negative beliefs are exacerbating any problems with the situation.

unity – Camera doesnt track player properly on different resolution

Hello i have 2d mobile game where camera follow players car, on my mobile phone with resolution 2960×1440 everything works fine but when i start the game on tablet with resolution 2160×1620
the camera shows only a half of the car… i made some drawings for better imagination 🙂

first is my mobile resolution

and second is my tablet resolution

I was trying to do it by myself for a few days but i am new in unity and i do not fully understand Camera class

i have this script on my camera:

public GameObject playerPos;
private Vector3 lastPlayerPosition;
private float distanceToMove;
void Start()
{
    lastPlayerPosition = playerPos.transform.position;
}
void Update()
{
    
        distanceToMove = playerPos.transform.position.x - lastPlayerPosition.x;
        transform.position = new Vector3(transform.position.x + distanceToMove,         transform.position.y, transform.position.z);
        lastPlayerPosition = playerPos.transform.position;
         
}

How can I stop the Unity Video Player on WebGL from starting each video with a frame of all black?

I’m working on a system to seamlessly reconstruct and play numerous segments of a continuous video stream by playing one segment on the active Video Player while loading the next on the hidden, waiting Video Player—and swapping between them when the active segment is done playing.

Although it’s not necessary to see the code for this, I included it below just in case:

public class VideoController : MonoBehaviour
{
    (SerializeField) private VideoPlayer activePlayer;
    (SerializeField) private VideoPlayer waitingPlayer;
    // The waiting player starts off invisible.

    private Queue<string> _segmentUrls;
    private bool _videoIsPlaying;

    private bool NextSegmentExists => _segmentUrls.Count >= 1;

    private void Awake()
    {
        // Initialize fields.
        _segmentUrls = new Queue<string>();

        // Subscribe to events.
        // VideoPlayer.Prepare() doesn't seem to work in WebGL. The workaround is to call
        // Play() instead and set the players to pause once the track is finished preparing.
        activePlayer.prepareCompleted += source =>
        {
            source.Pause();
        };
        waitingPlayer.prepareCompleted += source =>
        {
            source.Pause();
        };
        
        activePlayer.loopPointReached += SwitchVideoPlayer;
        waitingPlayer.loopPointReached += SwitchVideoPlayer;
    }

    public void EnqueueSegment(string segmentUrl)
    {
        _segmentUrls.Enqueue(segmentUrl);

        if (!_videoIsPlaying)
            StartCoroutine(StartPlayback());
        else if (!waitingPlayer.isPrepared)
            PrepareNextSegmentOnWaitingPlayer();
    }

    private IEnumerator StartPlayback()
    {
        PrepareNextSegmentOnWaitingPlayer();
        
        // Give the Video Player a second to finish preparing the segment for playback.
        yield return new WaitForSeconds(1f);

        SwitchVideoPlayer(lastPlayer: activePlayer);
        _videoIsPlaying = true;
    }

    private void PrepareNextSegmentOnWaitingPlayer()
    {
        var segmentUrl = _segmentUrls.Dequeue();
        waitingPlayer.url = segmentUrl;
        waitingPlayer.Play();
    }

    private void SwitchVideoPlayer(VideoPlayer lastPlayer)
    {
        activePlayer = waitingPlayer;
        TransparencyController.ShowGameObject(activePlayer.gameObject);

        waitingPlayer = lastPlayer;
        TransparencyController.HideGameObject(waitingPlayer.gameObject);
        waitingPlayer.Stop();
        
        if (activePlayer.isPrepared)
            activePlayer.Play();
        else
        {
            activePlayer.Stop();
            _videoIsPlaying = false;
            return;
        }

        if (NextSegmentExists)
            PrepareNextSegmentOnWaitingPlayer();
    }
}

When a Video Player begins playing, the first frame or two is just a black screen. As a result, when a segment finishes playing and it’s time to swap the active and waiting players, there’s a momentary black “blink” on the screen.

Demonstration

Below is a GIF of the issue:

Blinking Demo

Each blink corresponds to swapping Video Players.

(Not to be confused, the video player is showing a recording of a Unity project.)

When a Video Player is done preparing the new segment for playback, I have it advance two frames, so it picks off right where the old segment ended and transitions perfectly smoothly.

This is done by changing the callback for VideoPlayer.prepareCompleted as follows:

activePlayer.prepareCompleted += source =>
{
    source.StepForward();
    source.StepForward();
    source.Pause();
};
waitingPlayer.prepareCompleted += source =>
{
    source.StepForward();
    source.StepForward();
    source.Pause();
};
// Experimentation found that two calls to StepForward() are necessary.

Why It Doesn’t Work

It works on Windows, but testing it on the WebGL build—my primary build target—throws an exception telling me VideoPlayer.StepForward() is not supported on WebGL.

I tried the equivalent of calling StepForward() by setting the current time of the Video Player to a value equal to 2 / framerate, where the “2” stands for two frames.

Why It Doesn’t Work

It works on Windows, and it seems adjusting the time value works on WebGL, too—at least for values equal to or less than 0.5 seconds. However, on WebGL, the black blink persists despite the time-skip.

I tried the same approach as in #2, but by directly adjusting the current frame of the Video Player when preparing the segment for the waiting player.

Why It Doesn’t Work

For the same exact reason as in #2. 😫

Why does the Video Player start off with black frames on WebGL no matter what, and how can I avoid that?

gm techniques – How to punish a character while not punishing the player?

In my last session where I am GM, an accident happened. My player attacked unwillfuly an NPC who wants to punish them for that. As they are actually my best player, I really don’t want ruin their fun. Now I need to think how I can punish his character without punishing my player. I would rather not drop NPC vengeance, as rest of my group could get even more relentless seeing there are no consequences of their actions.

Setting

Game is on Dungeon World system in high fantasy world. It is entirely custom made, and has not much beyond where the players currently are. Magic there is quite common and potent.

History before situation

One of my players (let’s call him Bob) had a quarrel with a stablemen about quality of horses. This quarrel escalated quite a bit and finished with a
guard needing to intervene. Another player (lets call her Alice) had a brilliant idea: while Bob and stablemen was gone speaking with guards, she came and casted curse on horses to look like in decay (this would hamper horse quality and help Bob in dispute). Now Bob with guards, stablemen and crowd of onlookers come to stable to check those horses.

Meanwhile, the third player (lets call him Grzegoż, he’s that guy who messed up), is closing to this stable from entirely different direction knowing nothing about quarrel and curse. Grzegoż, as his character is helpful and quite compassionate offered guard boss that he will decurse those horses with small fee. Also, at the same time, guards called town sorceress, very powerful magician NPC to help with curse.

The accident

Grzegoż is a bard, but lately he was learning arcane arts and rituals. After some simple perception tests he started ritual of decursing. First time went poorly, on a second try, Alice approached him and offered help (she could help Grzegoż as she casted that curse). She can speak with different ghosts and spirits, so I’ve allowed speaking with those of curse. Ghosts offered deal, that she help them find another host. Alice agreed and needed to point single humanoid around (there was like hundred of different bystanders around), and in some kind a flash of genius she pointed at the sorceress. Ghosts had no choice and compelled. Also Grzegoż had no idea of this deal.
Grzegoż tried second time, with “help” of Alice, and succeed partially. Expelled ghosts tried to enter the sorceress, but failed miserably as she deflected them with ease. Unfortunately for Grzegoż, she seen from where those ghosts came and assumed it was an attack, promptly freezing everyone around bind magickly Grzegoż and took him to her tower.

The sorceress

She lives in the town my group is now currently. She is only important mage in that town. She is super powerful, cracking entire city in half would be big problem. She is a little bitchy but generally calm and not very caring (until she’s atacked of course). Her main area of expertise is ground magic, general arcane stuff and everything that could arise from being half medusa. She also helped my group quite considerable 2 sessions before and offered some more help in exchange of some adventuring favors.

gm techniques – How punish character while not punishing player?

In my last session where I am GM, an accident happen. My player attacked unwillfuly NPC who want to punish them for that. As they are actually my best player, I really don’t want ruin their fun. Now I need to think how I can punish his character without punishing my player. I would rather not drop NPC vengeance, as rest of my group could get even more relentless seeing there are no consequences of their actions.

Setting

Game is on Dungeon World system in high fantasy world. It is entirely custom made, and has not much beyond where player currently are. Magic there is quite common and potent.

History before situation

One of my player (let’s call him Bob) had quarrel with stablemen about quality of horses. This quarrel escalated quite a bit and finished with guard needing to intervene. Another player (lets call her Alice) had a brilliant idea, while Bob and stablemen was gone speaking with guards, she came and casted curse on horses to look like in decay (this would hamper horse quality and help Bob in dispute). Now Bob with guards, stablemen and crowd of onlookers come to stable to check those horses. Mean time, third player (lets call him Grzegoż, he’s that guy who fucked up), is closing to this stable from entirely different direction knowing nothing about quarrel and curse. Grzegoż, as his character is helpful and quite compassionate offered guard boss that he will decurse those horses with small fee. Also, at the same time, guards called town sorceress, very powerful magician NPC to help with curse.

The accident

Grzegoż is a bard, but lately he was learning arcane arts and rituals. After some simple perception tests he started ritual of decursing. First time went poorly, on a second try, Alice approached him and offered help (she could help Grzegoż as she casted that curse). She can speak with different ghosts and spirits, so I’ve allowed speaking with those of curse. Ghosts offered deal, that she help them find another host. Alice agreed and needed to point single humanoid around (there was like hundred of different bystanders around), and in some kind a flash of genius she pointed at the sorceress. Ghosts had no choice and compelled. Also Grzegoż had no idea of this deal.
Grzegoż tried second time, with “help” of Alice, and succeed partially. Expelled ghosts tried to enter the sorceress, but failed miserable as she deflected them with ease. Unfortunately for Grzegoż, she seen from where those ghosts came and assumed it was an attack, promptly freezing everyone around bind magickly Grzegoż and took him to her tower.

The sorceress

She lives in the town my group is now currently. She is only important mage in that town. She is super powerful, cracking entire city in half would be big problem. She is little bitchy but generally calm and not very caring (until she’s atacked ofc). Her main area of expertise is ground magic, general arcane stuff and everything that could arise from being half medusa. She also helped my group quite considerable 2 sessions before and offered some more help in exchange of some adventuring favors.

unity – How to make Player consistently jump *to* a specific target rather than *towards* it?

I’m trying to make it so if my player hits “E” then they jump precisely to a specific target. The current code results in player jumping towards the target but not really making it there.

I’ve tried adjusting forceMultiply and ForceMode and adding an offset but I just can’t get a result that simply consistently launches the player’s rigidbody rb towards the anchorPoint position.

The code I have is:

private void Update()
{
    if (Input.GetKeyDown(KeyCode.E))
    {
        tryGrabbing = true;
    }
}

private void FixedUpdate()
{
    if (tryGrabbing)
    {
        rb.AddForce(anchorPoint.transform.position * forceMultiply, ForceMode.Impulse);
    }
}

Thank you for any help!!

Python MP3 player with pygame.mixer and tkinter for MacOS

I made a Tkinter MP3 Player with Pygame and am looking for tips to improve. Explanation offered in comments in code, but it generally works by getting all the files in a folder. (Have censored filepaths for privacy.)

import os
import glob
import shutil
import pygame
import tkinter as tk
from pytube import YouTube
import tkinter.messagebox
from tkinter import filedialog as fd
from tkinter import simpledialog
from mutagen.mp3 import MP3
from klaxon import klaxon
import re
import applescript
from youtube_search import YoutubeSearch

def sorted_alphanumeric(data): #for sorting out the music in the tkinter listbox
    convert = lambda text: int(text) if text.isdigit() else text.lower()
    alphanum_key = lambda key: ( convert(c) for c in re.split('((0-9)+)', key) ) 
    return sorted(data, key=alphanum_key)
def listdir_nohidden(path): #for getting all files in a folder without 
    return sorted_alphanumeric(glob.glob(os.path.join(path, '*')))
def move_file(file): #for moving a music file to the folder
    try:
        name_and_ext = os.path.basename(file)
        target = name_and_ext
        shutil.copyfile(file, target)
    except TypeError:
        pass
def mp4_mp3(filepath): #for converting the downloaded mp4 file from pytube into mp3 format
    klaxon(title = 'MP3 Player', subtitle = 'Downloading YouTube...', message = 'This will take some time.')
    from moviepy.editor import VideoFileClip
    try:
        clip = VideoFileClip(filepath)
        clip.write_videofile(filepath.replace('.mp4', '.mp3'), logger = None)
        clip.close()
    except:
        pass
    os.remove(filepath)
    name, ext = os.path.splitext(filepath)
    os.remove(name + 'TEMP_MPY_wvf_snd.mp3')
def download(link): #for downloading the youtube video
    yt = YouTube(link)
    video = yt.streams.first()
    filepath = video.download('/Users/****/Desktop/****/****/****/****/Files')
    mp4_mp3(filepath)
    update_music()
def get_results(search): #for getting the youtube video names
    results = YoutubeSearch(search, max_results = 10).to_dict()
    res = ()
    for x in range(10):
        video = results(x)
        info = ()
        info.append(video('title'))
        info.append('youtube.com' + video('url_suffix'))
        res.append(info)
    return res
def open_window(): #for displaying the youtube video names for downloading
    ans = simpledialog.askstring(title = 'YouTube Video Downloader', prompt = 'What would you like to seach for on YouTube?')
    if ans is not None:
        window2 = tk.Tk()
        window2.title(f'YouTube Search Results For {ans}')
        res = get_results(ans)
        tk.Button(window2, text = res(0)(0), command = lambda : download(res(0)(1))).grid(row = 0, column = 0, padx = 5, pady = 5)
        tk.Button(window2, text = res(1)(0), command = lambda : download(res(1)(1))).grid(row = 0, column = 1, padx = 5, pady = 5)
        tk.Button(window2, text = res(2)(0), command = lambda : download(res(2)(1))).grid(row = 1, column = 0, padx = 5, pady = 5)
        tk.Button(window2, text = res(3)(0), command = lambda : download(res(3)(1))).grid(row = 1, column = 1, padx = 5, pady = 5)
        tk.Button(window2, text = res(4)(0), command = lambda : download(res(4)(1))).grid(row = 2, column = 0, padx = 5, pady = 5)
        tk.Button(window2, text = res(5)(0), command = lambda : download(res(5)(1))).grid(row = 2, column = 1, padx = 5, pady = 5)
        tk.Button(window2, text = res(6)(0), command = lambda : download(res(6)(1))).grid(row = 3, column = 0, padx = 5, pady = 5)
        tk.Button(window2, text = res(7)(0), command = lambda : download(res(7)(1))).grid(row = 3, column = 1, padx = 5, pady = 5)
        tk.Button(window2, text = res(8)(0), command = lambda : download(res(8)(1))).grid(row = 4, column = 0, padx = 5, pady = 5)
        tk.Button(window2, text = res(9)(0), command = lambda : download(res(9)(1))).grid(row = 4, column = 1, padx = 5, pady = 5)
def convert_mils(mils): #for converting the time from pygame.mixer.music.get_pos() into correct format
    seconds = int((mils/1000) % 60)
    minutes = int((mils/(1000 * 60)) % 60)
    return f'{minutes:02d}:{seconds:02d}'
def convert_secs(seconds): #for converting the seconds from mutagen.mp3.MP3(song).info.length into correct format
    m = int(seconds % 3600 // 60)
    s = int(seconds % 3600 % 60)
    return f'{m:02d}:{s:02d}'
def add_music(): #adding music as the user wishes
    try:
        res = applescript.AppleScript('display dialog "How would you like to add music?" buttons {"Cancel", "YouTube Search", "File Upload"} default button "File Upload"').run()
        for item in res:
            new_res = res(item)
        if new_res == 'File Upload':
            play_pause()
            file = get_music()
            if file != 'improper format':
                move_file(file)
                window.after(100, update_music)
        else:
            open_window()
            window.after(100, update_music)    
    except applescript.ScriptError:
        pass
def delete_music():
    selected_file = play_list.get(tk.ACTIVE)
    confirm = tkinter.messagebox.askquestion('MP3 Player', 'Are you sure you want to delete ' + selected_file + '?')
    if confirm == 'yes':
        if selected_file == title.get():
            pygame.mixer.music.stop()
            title.set('')
        os.remove(selected_file + '.mp3')
    window.after(100, update_music)
def rename_music(): #renameing the song
    selected_song = play_list.get(tk.ACTIVE)
    ans = simpledialog.askstring(title = 'Music Renaming', prompt = f'What would you like to rename {selected_song} to?')
    if ans is not None:
        os.rename(selected_song + '.mp3', ans + '.mp3')
        title.set(ans)
        update_music()
def edit_music(): #displaying options for editing
    selected_file = play_list.get(tk.ACTIVE)
    try:
        response = applescript.AppleScript('set res to display dialog "Actions For Song ' + selected_file + '" buttons {"Cancel", "Rename", "Delete"} default button "Delete"').run()
        for item in response:
            res = response(item)
        if res == "Delete":
            delete_music()
        else:
            rename_music()
    except:
        pass
def update_music(): #for updating the files in tkinter Listbox
    play_list.delete(0, tk.END)
    song_list = listdir_nohidden('/Users/****/Desktop/****/****/****/****/Files')
    for x in range(len(song_list)):
        orig = song_list(x)
        name = os.path.basename(orig)
        song_list(x) = name
    pos = 0
    for item in song_list:
        play_list.insert(pos, item.replace('.mp3', ''))
        pos += 1
    if play_list.size() > 10:
        scroll.pack(side = 'right', fill = 'y')
    else:
        scroll.pack_forget()
def unconvert(mins_and_secs): #for changing the '{mins:02d}:{secs:02d}' format into seconds
    mins, secs = mins_and_secs.split(':')
    if mins(0) == '0':
        mins = mins(1:)
    if secs(0) == '0':
        secs = secs(1:)
    more_secs = int(mins) * 60
    total_secs = more_secs + int(secs)
    return total_secs
def update_time(): #for updating music time tracker
    global already_run

    if pygame.mixer.music.get_pos() != -1:
        current_time = pygame.mixer.music.get_pos()
        song = MP3(title.get() + '.mp3')
        seconds_total = int(song.info.length)
        mins_and_secs = convert_mils(current_time)
        current_sec = unconvert(mins_and_secs)
        remaining_secs = seconds_total - current_sec
        remaining_secs = convert_secs(remaining_secs)
        music_time.set(f'{mins_and_secs}t-{remaining_secs}')
    else:
        if already_run is True:
            music_time.set('')
            next_song()
    already_run = True
    window.after(99, update_time)
def get_music(): #getting a file to add to songs
    f = fd.askopenfile(filetypes = (('MP3 Files', '*.mp3'), ('All Files', '*.*')))
    if f is not None:
        file = f.name
        root, ext = os.path.splitext(file)
        if ext in ('.mp3'):
            return file
        else:
            tkinter.messagebox.showinfo('MP3 Player', 'Must be MP3 file format!')
            return 'improper format'
def play(): #playing the music
    if already_run is not True:
        update_time()
    pygame.mixer.music.stop()
    pygame.mixer.music.load(play_list.get(tk.ACTIVE) + '.mp3')
    title.set(play_list.get(tk.ACTIVE))
    pygame.mixer.music.play()
    status.set('Pause')
def pause(): #pausing music
    pygame.mixer.music.pause()
def unpause(): #resuming music
    pygame.mixer.music.unpause()
def change_volume(volume): #chaning volume with tk.Scale
    pygame.mixer.music.set_volume(int(volume)/100)
def on_closing(): #what to do when window is closed
    pygame.mixer.music.stop()
    pygame.mixer.quit()
    window.destroy()
def next_selection(): #to select the next song
    song_name = title.get()
    index = play_list.get(0, "end").index(song_name)
    selection_indices = play_list.curselection()
    play_list.selection_clear(selection_indices)
    play_list.activate(index)
    play_list.selection_set(index)
    selection_indices = play_list.curselection()
    next_selection = 0
    if len(selection_indices) > 0:
        last_selection = int(selection_indices(-1))
        play_list.selection_clear(selection_indices)
        if last_selection < play_list.size() - 1:
            next_selection = last_selection + 1
    play_list.activate(next_selection)
    play_list.selection_set(next_selection)
def next_song(): #to select next song and play it
    next_selection()
    window.after(99, play)
def pause_play(): #to change the button from pause to resume
    stat = status.get()
    if stat == 'Pause':
        pause()
        status.set('Resume')
    else:
        unpause()
        status.set('Pause')
def main(): #main function
    
    global window, title, play_list, music_time, scroll, already_run, status

    already_run = False
    
    window = tk.Tk()
    window.title('MP3 Player')
    window.configure(bg = 'blue')
    window.resizable(False, False)
    window.protocol('WM_DELETE_WINDOW', on_closing)

    controls = tk.Frame()
    controls.grid(column = 1, row = 1, sticky = 'nsew', padx = 10, pady = 10)
    controls.configure(bg = 'blue')

    buttons = tk.Frame()
    buttons.grid(column = 0, row = 0, sticky = 'nsew', padx = 10, pady = 10)
    buttons.configure(bg = 'blue')
    
    songs = tk.Frame()
    songs.grid(column = 0, row = 1, sticky = 'nsew', padx = 10, pady = 10)
    songs.configure(bg = 'blue')

    song = tk.Frame()
    song.grid(column = 1, row = 0, sticky = 'nsew', padx = 10, pady = 10)
    song.configure(bg = 'blue')
    
    song_list = listdir_nohidden('/Users/****/Desktop/****/****/****/****/Files')
    for x in range(len(song_list)):
        orig = song_list(x)
        name = os.path.basename(orig)
        song_list(x) = name
        
    play_list = tk.Listbox(songs, bg='yellow', selectmode=tk.SINGLE)
    scroll = tk.Scrollbar(songs)
    play_list.config(yscrollcommand = scroll.set)
    scroll.config(command = play_list.yview)
    
    pos = 0
    
    for item in song_list:
        play_list.insert(pos, item.replace('.mp3', ''))
        pos += 1

    pygame.init()
    pygame.mixer.init()
    
    title = tk.StringVar()
    music_time = tk.StringVar()
    status = tk.StringVar()
    status.set('Pause')
    
    pause_button = tk.Button(controls, textvariable = status, command = lambda : pause_play())
    play_button = tk.Button(controls, text = 'Play', command = lambda : play())
    add_music_button = tk.Button(buttons, text = 'Add Music', command = lambda : add_music())
    delete_music_button = tk.Button(buttons, text = 'Edit Music', command = lambda : edit_music())
    song_title = tk.Label(song, textvariable = title, fg = 'yellow', bg = 'blue')
    song_time = tk.Label(song, textvariable = music_time, fg = 'yellow', bg = 'blue')
    volume_scale = tk.Scale(controls, from_ = 0, to = 100, tickinterval = 0.00001, showvalue = 0, label = '     Volume', command = change_volume, orient = tk.HORIZONTAL)
    volume_scale.set(50)
    
    add_music_button.pack(side='top', fill = 'x')
    volume_scale.grid(column = 0, row = 4, sticky = 'nsew', padx = 4, pady = 4)
    delete_music_button.pack(side='bottom', fill = 'x')
    play_list.pack(side = 'left', fill = 'both')
    song_title.pack(side = 'top', fill = 'x')
    song_time.pack(side = 'bottom', fill = 'x')
    play_button.grid(column = 0, row = 1, sticky = 'nsew', padx = 4, pady = 4)
    pause_button.grid(column = 0, row = 2, sticky = 'nsew', padx = 4, pady = 4)
    
    os.chdir('/Users/****/Desktop/****/****/****/****/Files')
    
    window.after(10, update_music())
    window.mainloop()

if __name__ == '__main__':
    main()
    

physics – (Unity 3D) How to make Player consistently jump *to* a specific target rather than *towards* it?

I’m trying to make it so if my player hits “E” then they jump precisely to a specific target. The current code results in player jumping towards the target but not really making it there.

I’ve tried adjusting forceMultiply and ForceMode and adding an offset but I just can’t get a result that simply consistently launches the player’s rigidbody rb towards the anchorPoint position.

The code I have is:

private void Update()
{
    if (Input.GetKeyDown(KeyCode.E))
    {
        tryGrabbing = true;
    }
}

private void FixedUpdate()
{
    if (tryGrabbing)
    {
        rb.AddForce(anchorPoint.transform.position * forceMultiply, ForceMode.Impulse);
    }
}

Thank you for any help!!

magento2 – How to use Youtube Player API with jQuery in in Magento 2?

I’m using Magento 2.4 and i’m trying to use Youtube player API with jQuery in Magento 2 .phtml file like this first:

<script>
    require(('jquery'), function($){
        var tag = document.createElement('script');

        tag.src = "https://www.youtube.com/iframe_api";
        var firstScriptTag = document.getElementsByTagName('script')(0);
        firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
        

However it is not working at all, then I tried to inject the youtube player api script in requirejs-config.js like this:

var config = {
    map: {
        '*':{
            youTubeIFrame: 'https://www.youtube.com/iframe_api?noext'
        }
    }
};

.phtml file:

<script>
    require(('jquery','youTubeIFrame'), function($){...

but the youtube video does not appear at all

Is there a correct way to load the Youtube Player API with jQuery in MAgento 2 ?