ID:2675555
 
(See the best response by Magicsofa.)
Code:
mob/RPM
verb
Invisible()
set desc = "Turn Invisible"
set name = "(RPM Lvl 1) Invisible"
set category = "Staff"
if(usr.changed == 0)
var/image/I = image("Invisible.dmi", usr)
usr << I
usr.invisibility = 101
usr.density = 0
usr.changed = 1
usr.sight |= SEE_SELF
hearers() << "RPM [src.name] dissappears."
else
var/image/I = image("Invisible.dmi", usr)
usr << -I
usr.invisibility = 0
usr.density = 1
usr.changed = 0
usr.sight &= ~SEE_SELF
hearers() << "RPM [src.name] reveals themselves."


Problem description:
Trying to add 'invisible.dmi' which is just an icon saying invisible so that the usr knows when he has the verb on or not since his icon is still shown to himself. Any help is great, thanks! :)
Best response
First of all, "invisible.dmi" should be in single quotes: 'invisibile.dmi'.

Second, this line is incorrect:

usr << -I


You're attempting to send the player "-I" which doesn't really make sense. To get rid of the image in this case, I think your only option is to delete it.

If you don't mind other players who can see invisible mobs being able to see the tag as well, just use an overlay. Also, there's no need for the 'changed' variable as far as I can tell. Just test the invisibility var:

if(!invisibility) //true if invisibility is 0 or null
overlays += I
else
overlays -= I


Finally, you don't need to put usr. before all those vars. Usr is the activator of the verb, whereas src is the object "containing" the verb. So, src would be fine here, and you only need to expicitly write src if there's another var with the same name. Usually, "var" is the same as "src.var"

var/image/I = image('Invisible.dmi',src)
src << I
invisibility = 101
density = 0
sight |= SEE_SELF


You actually did this already, since you wrote "hearers()" with nothing before it. That equates to "src.hearers()," not "usr.hearers()".
mob/RPM
verb
Invisible()
set desc = "Turn Invisible"
set name = "(RPM Lvl 1) Invisible"
set category = "Staff"
if(!invisibility)
overlays += image('Invisible.dmi', usr)
invisibility = 101
density = 0
sight |= SEE_SELF
hearers() << "RPM [src.name] dissappears."
else
overlays -= image('Invisible.dmi', usr)
invisibility = 0
density = 1
sight &= ~SEE_SELF
hearers() << "RPM [src.name] reveals themselves."


So I checked out image proc in the DM reference and fixed what you suggested and this worked for me. Tested and working. Thank you so much :). Now is there any chance you know anything about how to adjust where the image lands on the player? I would like it below their player icon and not across the middle of it. Or should I make a new thread :O. Thank you! ^^
The "cheap" way would be to adjust the position manually within the icon. I assume it's not 32 pixels tall, in which case you could slide it to the bottom of the icon.

You can also apply pixel offsets to images (and pretty much anything else that appears on screen). The image proc itself doesn't allow you to put them in as an argument however, so you'll need a reference to the image allowing you to modify it (just like you did before):

var/image/I = image('Invisibile.dmi', src)
I.pixel_y = -24
overlays += I


I only took out the var/image/I part before because it's more compact if you just want to add a simple overlay. Look at the vars(image) page of the reference to see everything you can modify with an image object.
If you want to be able to remove the overlay, you'll need to either repeat the offset before removing it (basically do the exact same thing before removing as you did before adding), or you could store the image somewhere accessible to both branches at different times.

For simplicity, you can even use a "global" local var, since this image is actually identical for everyone who uses this verb, every time they use it:
var/global/image/I = image('invisible.dmi', pixel_z = -24)
if(!invisibility)
overlays += I
invisibility = 101
// etc.
else
overlays -= I
invisibility = 0
// etc.

Note that pixel offsets are not documented for image(), but they do work.

Alternatively, if the image only has constant modifications, you can define it as an image type and add its type to overlays instead, which saves an object instance:
image/invisible
icon = 'invisible.dmi'
pixel_z = -24

// and in the verb:
if(!invisibility)
overlays += /image/invisible
// etc.
else
overlays -= /image/invisible
// etc.

You could also define this as an /obj or any other type of atom instead of /image, and it'll work the same.
In response to Kaiochao
Kaiochao wrote:
Note that pixel offsets are not documented for image(), but they do work.

Oh snap, didn't know that!
I did infact go with the global var and the pixel offset. It works awesome now. Thank you everyone for your help! I appreciate it :D