ID:2088585
 
(See the best response by FKI.)
Problem description:
So. Here's my issue. First of all I'm still fairly new to lists and I'm learning datums as I create this.

I'm creating a party system. A brief summary of the current party system is:

-You can click create party and input a name
-It will check if that name is already taken
-You can click join party then click on a player. You will join their party if they're in one
-You can view all current parties along with their party members

There's so much more I need to do for this before I'm done.


So anyways. My current issue is that I'm trying to display small health/mana bars around the player and all their party members. But only you and your party can see your own bars. Nobody else.

So I'm thinking client.image is the only way to accomplish this. Which I'm also new to. I think I'm calling the image properly but it doesn't display. I think it has to do with how poorly I have this party system setup. So I'd like some help optimizing this and then doing this health/mana bar part.

Finally, on to my actual code. I'd like to apologize beforehand for the level of noobyness you're going to encounter here. Don't cringe too badly.

I came up with this after reading a few posts on datums and looking at a couple examples of a party system.

Also, mob/HUMANS/PC is for player characters. In case my naming is odd.

Code:
mob/HUMANS/PC/var/PARTY/PT = new

var
list
ALL_PARTIES_LIST = list()

mob
var
PARTY_DATUM //This variable holds the current persons party
tmp/PARTY_INPUT_OPEN = 0 //This is used to check if you have a party command open already. If so, don't let them use any other commands
tmp/JOINING_PARTY = 0 //This is used to check if you're currently joining a party or not.

mob
New()
PARTY_HEALTH_BAR_IMAGE = image("GLOBAL/GUI/HUD/PARTY_HEALTH_BAR.dmi", src)
..()


PARTY
New()
..()
ALL_PARTIES_LIST += src
Del()
ALL_PARTIES_LIST -= src

var/tmp
PARTY_NAME //Party's name
list
MEMBERS = new/list()
DEPUTIES = new/list()
mob/PARTY_LEADER
SHARE_RANGE = 20


proc
CREATE_PARTY(ENTERED_NAME, mob/creator)
if(PARTY_NAME != null)
world << "[PARTY_NAME]"
return

if(usr.PARTY_INPUT_OPEN == 1)
return

usr.PARTY_INPUT_OPEN = 1
PARTY_LEADER = creator
ENTERED_NAME = input("Enter Party Name", "Name", ENTERED_NAME)
for(var/PARTY/P in ALL_PARTIES_LIST)
if(ckey(P.PARTY_NAME) == ckey(ENTERED_NAME))
PARTY_LEADER << "Your party, [ENTERED_NAME] could not be created. It already exists."
PARTY_LEADER = null
del src


PARTY_NAME = ENTERED_NAME
MEMBERS += PARTY_LEADER
PARTY_LEADER.PARTY_DATUM = src

PARTY_LEADER << "You are now the leader of [ENTERED_NAME]!"
usr.PARTY_INPUT_OPEN = 0


JOIN_PARTY()
usr.JOINING_PARTY = 1
usr << "Click a player to join their party"

JOIN_PARTY_SUCCESSFUL(var/PARTY_I_WANT_TO_JOIN)
world << "src:[src] usr: [usr.GMOB_CHARACTER_NAME] Joined [PARTY_I_WANT_TO_JOIN:PT.PARTY_NAME]"
PARTY_I_WANT_TO_JOIN:PT.MEMBERS += usr //Adds the usr to the party of the person they clicked on

for(var/X in PARTY_I_WANT_TO_JOIN:PT.MEMBERS)
world << "1 member. Add health"
X:UPDATE_HEALTH_MANA_PARTY_BARS_DISPLAY()


SHOW_ALL_PARTIES()
usr << "Currently active parties:"
for(var/X in ALL_PARTIES_LIST)
if(X:PARTY_NAME != null)
usr << "[X:PARTY_NAME]"
for(var/Z in X:MEMBERS)
usr << " [Z:GMOB_CHARACTER_NAME]"


UPDATE_HEALTH_MANA_PARTY_BARS_DISPLAY()
usr << "Health bar should show up..."
usr.client.images += usr.PARTY_HEALTH_BAR_IMAGE //Display the health bar on the usr's client



mob
HUMANS
PC
Click()
if(usr.JOINING_PARTY == 1)
usr << "Join this guys party [src]"
usr.JOINING_PARTY = 0
if(src.PT.PARTY_NAME != null)
world << "They're in [src.PT.PARTY_NAME]"

PT.JOIN_PARTY_SUCCESSFUL(src)


else
..()


The only way I know how to call these procs is by using

mob/HUMANS/PC
verb
CREATE_PLAYER_PARTY()
PT.CREATE_PARTY(GMOB_CHARACTER_NAME, src)
Best response
You are off to a good start to be new. Just a few things I want to note:

  • You are using usr in your procs when it's more ideal not to. (You can read about usr here.) I'd be sending a mob argument to the party's procs (small example of that below).
  • You could -- and probably should -- be type-casting your variables as to make use of the dot (.) operator instead of abusing the lookup/runtime search operator (:). Ex:

    // pay attention to the 'player' varible...

    party
    // what you are doing
    proc/joined(var/player)
    player:mod_something = 1
    player:do_something()
    members += player

    party
    // type-casting
    proc/joined(var/mob/human/pc/player)
    player.mod_something = 1
    player.do_something()
    members += player


    The less ambiguous your code, the better. I also seem to recall the lookup operator being slower than the alternative (someone feel free to correct me).
  • The way you are attempting to add the bar images to every party member's screen is not good and could be attributed to why it isn't working. All you really need to do is send the image to a list of mobs/clients using the output operator.

    members << bar_image
    


    You are responsible for taking care of the images per client and making sure they get cleaned up.
  • I think creating a party datum just to check if the party can be created is overdoing it. I'd personally do the name handling in the creation verb and create the party datum with the valid name after we've checked it.
  • Instead of having a global list of existing parties for the purpose of preventing duplicate name entries, you could set each partys' tag to something like "party_somepartyname". Then checking for a party with a given name would be as simple as var/party/p = locate("party_somepartyname"). You avoid a for() loop in the process, which is more often desired than not.
  • Slight nitpick: I think writing your code in all caps is not something you want to get in a habit of. Personally, I think it makes your code harder and unpleasant to read.