XF 1.3 Assistance with applying feature to multiple usergroups

I've been able to setup what I need, but only for the standard user group. What's the best way I can take this section of code & apply it to multiple user groups (admins, mods, special groups, etc)? Thanks in advance!

For X & Y, I should be using the group's number, right? This code is essentially applying a trophy rank image on top of the user's avatar. I'd only want registered accounts to have it. (thanks for your help)

The issue I'm having with this code is that it's awarding the rank based on a group that they're in rather than their trophy points if I swap it out. Should I just be changing the code to look like this instead?

For every user, they'll have a "rank". I've set it up say that each rank they have will have a corresponding image in the upper right-hand section of their avatar (see image below). The code works for 90% of users, but some of them don't actually have the image display.

vs
vs

Every single user has the same standard "registered" class. A few users who have a moderating permission don't have the rank, but we also have users who are just a regular user who don't have the rank either.

I have this same code implemented on a few different sites, and there's not one distinct pattern that I can figure out for why it doesn't work for some users. Any help that you or someone else can provide would be greatly appreciated!