ID:176724
 
Can anyone tell me how I could make a code that checks all the items in a users inventory for items with the suffix "Broken" and then does an action to these items.
Thank you for any help.
ShadowBlade6300 wrote:
Can anyone tell me how I could make a code that checks all the items in a users inventory for items with the suffix "Broken" and then does an action to these items.
Thank you for any help.

One example:

mob
proc
check_broken_items()
for(var/obj/O in contents)
if(O.suffix == "Broken")
O.icon_state = "ruined"
In response to Skysaw
How can I make that chack automaticaly all the time?
In response to ShadowBlade6300
ShadowBlade6300 wrote:
How can I make that chack automaticaly all the time?

An automatic check is probably not what you really need. If a proc runs over and over to check on these things it goes through a process called "polling", which means it's running a lot of the time just to check to see if it has something to do. This is a waste of cycles and will be much worse if more objects are in use.

What you need to do is simply use procs to handle the change of status for the item, and call those procs instead of changing vars manually.
obj/item
var/damage=0 // example: 1 for damaged, 2 for broken

proc/SetDamageSuffix(dmg)
if(dmg>2)
if(ismob(loc)) loc << "[src] is destroyed!"
del(src)
damage=dmg
switch(damage)
if(1) suffix="(damaged)"
if(2) suffix="(broken)"
else suffix=null

obj/item/equipment
var/site

proc/IsEquipped()
return (ismob(loc) && (site in loc.vars) && loc.vars[site]==src)

SetDamageSuffix(dmg)
if(dmg>2 || !IsEquipped)
return ..()
damage=dmg
switch(dmg)
if(1) suffix="(equipped, damaged)"
if(2) suffix="(equipped, broken)"
else suffix="(equipped)"
I can think of ways I'd rather set up the suffix system, but this isn't a bad one.

Lummox JR
In response to Lummox JR
Can I check this when the user loggs in?
In response to ShadowBlade6300
ShadowBlade6300 wrote:
Can I check this when the user loggs in?

You sure can--although if the equipment saved properly, it's probably not necessary. The place to do this would be in mob/Login(), or mob/Read() (an override of the standard Read() routine used to load from a savefile).

You can double-check the suffix at any other time, too. Any time the item's damage status changes, all you have to do is call the right proc. (The proc I provided will actually set the damage stat for you.)

You'd use a similar method to control health meters and HUD displays. Any time the status of the item in question is changed in any way (for example, a health meter could change after healing or taking damage in battle), it should be updated via such a proc.

Lummox JR