ID:175854
 
I am having trouble, I have been trying to get this done for a while, here it is. As some of you know I am making Chrono Warp for BYOND, I have no experience with HUD making and I find the tutorials very confusing. I need to make a HUD that appears in battle at the top of screen and dissappears at the end of battle either when a player dies or defeats all the enemies, I have made the icons for each seperate part (HUD screen, letters, numbers, ATB bar etc.) Can anyone help me please?

Thankyou very much in advance as it is a great step in the project.
Please help me. I really need to know how to do this.
To make a HUD, you need to define each of the HUD pieces as an obj in our code, and set a couple of important variables; layer, and screen_loc... An example:

obj
HUD
layer = MOB_LAYER + 1
HUDitem1
screen_loc = "1,1"
HUDitem2
screen_loc = "2,1"
HUDitem3
screen_loc = "NORTH,3"
//and so on

The layer variable tells the program how to display the object's icon relative to other objects in the same tile... The higher the variable, the higher in the pile the object will be displayed... So it is usually preferable to set it to something higher than everything else in the game, so that the icon will always remain on top...

An example of normal icon layering that you've probably seen is when a mob steps onto an obj... The mob's layer is by default higher than the obj, so its icon is displayed as being on top of the obj's icon... For a HUD item, you don't want that, so its layer has to be higher than the mob layer...

I chose to set it to one layer higher than the default MOB_LAYER, but it can be set to any number, even decimals...




The screen_loc variable tells the program where on the player's screen to put the object... "1,1" will put it in the lower left hand corner, at x=1, y=1... "1,10" will put it at x=1, y=10, etc...

However, they aren't limited to x,y coordinates... You can also specify just "[x],NORTH" to align the object at the top of the map at whatever x coordinate you want (this is probably what you'll need to do with your HUD, since you want it along the top of the map)...

Other tricks may be used as well, like "NORTHEAST" (this will put the object in the top right corner, northeast...) or "SOUTHWEST to NORTHEAST" (this will fill in an entire rectangle of the objects from the first point to the second, in this case, from the bottom left to the top right corners, which will fill the entire screen)

And pretty much any combination of the above... "WEST,3" will put the object along the left edge of the screen at y=3... Etc, etc...

So you'll just have to figure out where you want them, and set this variable to whatever will do it the best for you...




Once you have them all defined, you have to create a way of adding them to the client's screen...

Usually, this is done in Login()...

mob
Login()
..()
src.client.screen += new/obj/HUD/HUDitem1
src.client.screen += new/obj/HUD/HUDitem2
// etc, etc

This will create a new instance of each of the objects, and add them to the player's screen at whatever screen_loc they are set to...

There are all kinds of tricks that can be used here, too... Instead of just adding each of the objects separately, they can all be put into a world list and then added using a for() loop... This is what my game does, actually... Here's an example:

var/HUDlist[0]

world
New()
..()
HUDlist += new/obj/HUD/HUDitem1
HUDlist += new/obj/HUD/HUDitem2
// etc, etc
mob
Login()
..()
for(var/obj/HUD/h in HUDlist)
src.client.screen += new h.type

This will add each of the items to the global HUDlist, and then when a player logs in, it will loop through that list, and add a new instance of each object to the player's screen...

I think that this method is preferable, especially if you've got a ton of objects to add...

In the case of things like meters and such that are directly tied to the mob, you need to have a way to attach them to their owners... HUD items like this work in single player, but tend to break down in multi, because you end up trying to update one mob's meter, and it gets another mob's meter instead...

In order to make sure the correct meter is attached to the correct mob, you have to add another little bit:

obj
HUD
var/mob/owner
// all of the other object definition
stuff from above

mob
Login()
..()
for(var/obj/HUD/h in HUDlist)
var/obj/HUD/H = new h.type
H.owner = src
src.client.screen += H

This will do what the above did, but will also make sure that each of the objects are given a variable (owner) that is set to their proper owner (the player that has the item in their screen)...

Then, for the case of a meter, when you update it, you can do something like this:

obj
HUD
Meter
Update()
src.icon_state = "[owner.health]"

...or whatever... Any method you use of updating the meter based on the mob's stats, you can use the owner var to ensure that the proper mob is being used...




You mentioned wanting to add and remove the objects based on battle conditions... In order to do it this way, it's just slighlty different...

You should use the global list method I described above, but move all of the client.screen addition to whatever procs are called at the beginning of battle, instead of Login()... And then, remove them in a proc called at the end of battle... You should also store them in a mob list as well, so they can be removed more easily... Like so:

mob
var/PlayerHUDlist[0]
proc
BeginBattle()
if(src.client)
for(var/obj/HUD/h in HUDlist)
var/obj/HUD/H = new h.type
H.owner = src
src.PlayerHUDlist += H
src.client.screen += H
EndBattle()
if(src.client)
for(var/obj/HUD/h in src.PlayerHUDlist)
src.PlayerHUDlist -= h
del(h)

Of course, those are just examples... You'll need to put this type of code into whatever procs you have at the beginning, and end of battle...and change them accordingly (like if you use ProcName(mob/M), you can change the "src"s to "M" and such... The if(src.client) check is necessary in case these procs are called by any NPCs... They don't have clients, so it'll give errors without the checks in place... That's not the case with putting it in Login(), because any mob that calls Login() must have a client...




Hopefully that helps... I know it was a long post, but it should tell you what you need to know... Feel free to ask more questions about parts you might not understand...
In response to SuperSaiyanGokuX
SuperSaiyanGokuX wrote:
> proc
> BeginBattle()
> if(src.client)
> for(var/obj/HUD/h in HUDlist)
> var/obj/HUD/H = new h.type
> H.owner = src
> src.PlayerHUDlist += H
> src.client.screen += H
> EndBattle()
> if(src.client)
> for(var/obj/HUD/h in src.PlayerHUDlist)
> src.PlayerHUDlist -= h
> del(h)
>


Instead of having to create a list full of objects, you could just cycle through all of the types of hud/battle.
for(var/obj/O in typesof(/obj/HUD/battle/))
src.client.screen += O


And then for the removal..

for(var/obj/HUD/battle/B in src.client.screen)
del(B)


-Rcet
In response to Rcet
Heh, good point...

I suppose it boils down to how you've defined your HUD objects...

In my game, I use a lot of different HUD items and lists to add and remove them as necessary, but I couldn't always use typesof() because not all of them are defined as separate object types... I suppose they could be, but that's just not the way I started out, so I went with list usage to keep them all categorized...

But yeah, your way would work rather nicely...
In response to SuperSaiyanGokuX
I dont know how often you guys check this post but I need some real help here. You see I just started using byond and I want to make a choice for the player. When some one logs in for the first time I want them to choiose 1 of three races to be.

The names of the Icon files are Fevis,Enrik, and Shandiri.
All of them have the male,female, and neuter movies for movement (You know, the 12 picture ones) and I just can`t figure out how to do it.

I only want character creation to happen once and I was wondering If anyone could figure this one out..

Either post an answer here or e-mail me at :

[email protected]

MOCHOS Thanks anyone who answers
In response to SuperSaiyanGokuX
Wow, thanks alot, I still have a problem though, I might have to increase the view size for it, the names of the characters which appear can become too large and cover the rest of the HUD, could I make it so the letters appear closer together and slightly smaller?
In response to Dreadlordmajik
Make your own thread, don't try to take over someone else's.
In response to Rii
SSGX, is it possible for me to use 1 part of the coding to cover numerous screen locations? e.g. one that covers from 2,16 to 16,16 using 1 icon state and instead of repeating the screen_loc = "2,16", "3,16" etc. if you know what I mean
In response to Rii
Yup, you can code objects to cover a rectangular area (full screen would be "SOUTHWEST to NORTHEAST", but smaller rectangles can be filled)

For something that ranges from 2,16 to 16,16, you can do it like this:

screen_loc = "2,16 to 16,16"
In response to SuperSaiyanGokuX
Ah ok, thats made it a lot easier now.

But do you know if you can make HUD text appear closer together. I want to be able to display the players names on the hud but the letter icons are too spaced out and too tall, can I reduce them without having to reduce the icon size?
In response to Rii
One more thing, Ive sorted out the coding but still, the HUD does not appear, tell me what I am doing wrong please:

proc
Battle()
if(src.client)
for(var/obj/Battle_HUD/h in HUDlist)
var/obj/Battle_HUD/H = new h.type
H.owner = src
src.PlayerHUDlist += H
src.client.screen += H
sleep(10)
switch(input("What would you like to do.")in list("Attack","Run"))
if("Attack")
Attack()
if("Run")
Run()

Death()
if(src.client)
for(var/obj/Battle_HUD/h in src.PlayerHUDlist)
src.PlayerHUDlist -= h
del(h)
if(src.HP<=0)
usr.EXP+=src.EXP
usr.GP+=src.GP
Levelup()
usr.islocked=0
del src
In response to SuperSaiyanGokuX
Lol that teached me some stuff too. I knew how to do HUD's but not how to make health & such with it. other than using an extreamly long proc.
In response to Rii
As for how large the letter are (width and heighth), the only way to shrink them down is to change the icons...

As for how far apart they're spaced, you can use pixel offsets (look up atom/var/pixel_x and atom/var/pixel_y in the reference) or icon shift (look up icon/proc/Shift) to move the icons closer together (and overlap, to take up the excess room)... However, this is a rather complicated process to explain (especially since I don't know exactly how your system works in displaying the names)... So I can't be of much more help on this one...
In response to Dreadlordmajik
Dreadlordmajik wrote:
I dont know how often you guys check this post but I need some real help here. You see I just started using byond and I want to make a choice for the player. When some one logs in for the first time I want them to choiose 1 of three races to be.

The names of the Icon files are Fevis,Enrik, and Shandiri.
All of them have the male,female, and neuter movies for movement (You know, the 12 picture ones) and I just can`t figure out how to do it.

I only want character creation to happen once and I was wondering If anyone could figure this one out..

Either post an answer here or e-mail me at :

[email protected]

MOCHOS Thanks anyone who answers


It sounds to me like your just looking for a save system? If so, I would prefer RaeKwon's Save system, or Deadrons character handling. You can find them both in the hub.


As far as the switch goes, heres what you would need:
mob/Login()
var/y = input("Which character will you be?") in list ("Fevis","Enrik",Shandiri")
switch(y)
if("Shandiri")
usr.icon = ‘Shandiri.dmi’
if(“Enrik”)
usr.icon = ‘Enrik.dmi’
if(“Fevis”)
usr.icon = ‘Fevis.dmi’
I never got a chance to compile it, but it should work fine.
-Demon-
In response to Rii
Hmmm, all of that code looks fine...

The problem must be in the HUDlist... Are all of the objects being added to the HUDlist in world/New()? And are all of the objects assigned layer variables higher than everything else on the map?

Another problem I notice is the use of both usr and src in the Death() proc... These two procs have to belong to the player in order for it to add and remove the HUD items...because src has to be the player...

And if that's the case, then in the death proc, src and usr will be the same (most of the time, anyways)...

So do these procs run under the same type that the player's mob is? And are they called for the player, instead of the NPC?

It could be any of the above problems, so I can't give you a definite answer yet... But we should be able to figure it out...
In response to Demonskata630
Except, of course, for the missing opening double quotes on Enrik.
In response to SuperSaiyanGokuX
Funny how you say it looks fine when there are 4 instances of usr in those two procs combined. Can you find them all?
In response to SuperSaiyanGokuX
The HUD is working but now im experiencing another problem, ive set it so that the HUD appears when you bump into an enemy only problem is that it isnt working, and once the enemy is defeated then the player seems to freeze:

Bumped(O)
if(src.client)
for(var/obj/Battle_HUD/h in src.PlayerHUDlist)
src.PlayerHUDlist -= h
del(h)

Death()
if(src.client)
for(var/obj/Battle_HUD/h in src.PlayerHUDlist)
src.PlayerHUDlist -= h
del(h)
if(src.HP<=0)
src.EXP+=src.EXP
src.GP+=src.GP
Levelup()
src.islocked=0
del src
Deathcheck()
if(usr.HP<=0)
src<<"The [src] killed you."
src.GP/=2
src.HP=1
src.loc=locate(1,1,1)
if(src.client)
for(var/obj/Battle_HUD/h in src.PlayerHUDlist)
src.PlayerHUDlist -= h
del(h)
In response to Rii
It's because you're using usr.
Page: 1 2 3