ID:268778
 
I am trying to create a game where as you don't have to use your tabs to get an obj that is laying on the ground, or even using your mouse. I want it so that when you hit the object, it'll automatically disappear and do the specified procedures.

Example: There is a sword on the ground. You wank over to it, and walk on top of it, and it automatically goes into your inventory.

Example 2: There is a potion and you walk on top of it, and it automatically heals you without having to use the tab and inventory.

It would be greatly appreciated if you could help me out.
turf
Entered(mob/M)
if(ismob(M)&&M.client)
for(var/obj/Items/I in src)
I.action(M)

obj/Items
Sword
proc/action(mob/M)
src.Move(M.contents)
M<<"You get [src]"
Potion
proc/action(mob/M)
M.hp=M.maxhp
M<<"You are healed!"
del src


That's untested
In response to Airjoe (#1)
Airjoe wrote:
That's untested

Untested and close, but not quite correct. The type /obj/Items doesn't have an action() proc, so it'll cause an error. Here's a fixed version:

turf
Entered(mob/M)
if(ismob(M)&&M.client)
for(var/obj/Items/I in src)
I.Action(M)

obj/Items
proc/Action(mob/M)
M << "Error. Action not specified."
Sword
Action(mob/M)
src.Move(M)
M<<"You get [src]"
Potion
Action(mob/M)
M.hp=M.maxhp
M<<"You are healed!"
del src