ID:147850
 
I'm attempting to make a medal system, and of course, I'm already stumped. I'm trying to make the medal appear as an overlay, and if the medal exists, I want it to delete the overlay, add one to the icon state and add the overlay again.
obj
Medals
icon = 'Medals.dmi'
icon_state = ""

mob
player
icon = 'player.dmi'
verb
Add_Medal()
var/obj/Medals/T
var/IS
var/MN
if(!T in src.overlays)
src.overlays += T
return
if(T in src.overlays)
IS = T.icon_state
del T
MN = text2num(IS)
MN += 1
src.overlays += T
T.icon_state = "gold[MN]"
return
Enigmaster2002 wrote:
I'm attempting to make a medal system, and of course, I'm already stumped. I'm trying to make the medal appear as an overlay, and if the medal exists, I want it to delete the overlay, add one to the icon state and add the overlay again.
> obj
> Medals
> icon = 'Medals.dmi'
> icon_state = ""
>
> mob
> player
> icon = 'player.dmi'
> verb
> Add_Medal()
> var/obj/Medals/T
> var/IS
> var/MN
> if(!T in src.overlays)
> src.overlays += T
> return
> if(T in src.overlays)
> IS = T.icon_state
> del T
> MN = text2num(IS)
> MN += 1
> src.overlays += T
> T.icon_state = "gold[MN]"
> return
>


The problem here is that an object isn't stored in overlays -- rather, a "snapshot" image is generated of a particular object, and that image is added or removed from the overlays list when the code specifies to add/remove the object.

Here's how I would do it:

mob
player
icon = 'player.dmi'
var/obj/Medals/medal

proc/IncreaseMedal()
if(!medal) //if we don't have a medal...
medal = new /obj/Medals
overlays += medal
return

//otherwise...
overlays -= medal
var/IS = medal.icon_state
var/MN = text2num(IS) + 1
medal.icon_state = "gold[MN]"
overlays += medal


(Might also be a good idea to have the following code:

Write()
//remove overlay before saving
overlays -= medal
..()
Read()
..()
//add overlay upon loading
if(medal) overlays += medal

...just so your overlay doesn't get "stuck" on a character on save/load.)
In response to Spuzzum
Well, I tried what you gave me Spuzzum, and most likely I messed up somewhere.... it adds the medal the first time I click the verb, but doesn't seem to do anything else...
obj
Medals
icon = 'Medals.dmi'
icon_state = "gold1"

mob
player
icon = 'player.dmi'
verb
Add_Medal()
var/obj/Medals/medal
if(!medal)
medal = new /obj/Medals
src.overlays += medal
return
src << "1"
src.overlays -= medal
src << "2"
var/IS = medal.icon_state
src << "3"
var/MN = text2num(IS) + 1
src << "4"
medal.icon_state = "gold[MN]"
src << "5"
src.overlays += medal
src << "Done"
In response to Enigmaster2002
Bump.