ID:172119
 
I know this is pretty newbish, but I can't figure out how to do it. How would I delete a certain object in a player's inventory? I've tried del(/obj/thing in usr), del(/obj/thing) in usr, and a couple others, but they either don't work right or give me errors. I know this is an incredibly obvious question, but for that reason I couldn't find the answer to it anywhere. Thanks x_x
subtract it from contents...i think that should work
del(obj)
obj = the thing you want to delete

if you don't have it defined, locate could to the trick
You can look it up in DM by pressing F1 and typeing in locate
In response to DarkCampainger
ok, if I use that, it works when there's 1 item in the usr's inventory. But if there's more than 1 item, it deletes another object, not the one specified. This is what I'm using:

var/obj/thing=locate() in usr

del(thing)

...Am I doing something wrong?
In response to Rippy
Rippy wrote:
ok, if I use that, it works when there's 1 item in the usr's inventory. But if there's more than 1 item, it deletes another object, not the one specified. This is what I'm using:

var/obj/thing=locate() in usr

del(thing)

...Am I doing something wrong?

How do you want to select the object to delete? By some other means than locate?


/Gazoot
In response to Gazoot
I don't know. >.>
In response to Rippy
If you just have a specific type of object in the player's inventory that you want to delete, locate() is probably the way to go.

The way you have it set up there, though, it will just take any /obj from the player's inventory and delete that. If you only want to delete an /obj/thing, you need to do something like this:

var/obj/thing/MyThing = locate() in usr

del(MyThing)

The "MyThing" is a variable name. The bit before it ("/obj/thing") is the type of the object that "MyThing" will get set to.
I'm pretty sure this would work:

for(var/obj/sword/O in usr.contents)
del(O)
In response to SSJ4_Gohan_Majin
He said a certain object. That loop will delete ALL objects of that type. Which is fine if that's what he wants, but it's usually good to clarify these things.
In response to Crispy
ohhhhhh...

I thought that variable names were optional, for convenience. I didn't realise they would change how the code works. Thanks, it works fine ^^