ID:178676
 
How would i make it where if you step on an object youll pick it up instead of clicking a verb to get it
obj/blah
icon = 'Blah.dmi'
Entered()
Move(usr)


-Kappa the Imp
SuperGoku15 wrote:
How would i make it where if you step on an object youll pick it up instead of clicking a verb to get it

One way to do that would be this:
turf
Entered(atom/movable/A)
if(ismob(A))
var/mob/M=A
if(M.autopickup)
for(var/obj/item in src)
item.Move(M)
M << "You pick up \a [item]."

mob
autopickup=1 // you can make a verb to tunr this on and off

Lummox JR
In response to Kappa the Imp
Kappa the Imp wrote:
> obj/blah
> icon = 'Blah.dmi'
> Entered()
> Move(usr)
>

-Kappa the Imp

LOL!

That will put the object in the user's contents only if the user first goes into the object's contents! Not to mention, using usr inside of Move is a bad idea.

Try it this way:

turf
Entered(who)
if(ismob(who))
for(var/obj/O in src)
O.Move(who)
In response to Lummox JR

One way to do that would be this:
turf
> Entered(atom/movable/A)
> if(ismob(A))
> var/mob/M=A
> if(M.autopickup)
> for(var/obj/item in src)
> item.Move(M)
> M << "You pick up \a [item]."
>
> mob
> autopickup=1 // you can make a verb to tunr this on and off

Lummox JR

so would i have to change the object to a turf or would it work as an object?
In response to SuperGoku15
keep them as objects!
I've been trying what you guys said but nothing seems to work can you tell me whats wrong with this it gives me no errors but you dont pick up the item

heart
icon='heart.dmi'
Entered(atom/movable/A)
if (ismob(A))
for(var/obj/heart in src)
if (usr.health==usr.maxhealth)
usr<<"<B>Your health is full"
else
usr.health+=1
del(src)

In response to SuperGoku15
That should be the turf/Entered() proc, not the heart/Entered() proc. You might also look at http://www.deadron.com/byond/ByondBwicki.dmb?TriggeredObjs
In response to SuperGoku15
SuperGoku15 wrote:
so would i have to change the object to a turf or would it work as an object?

Nope, you shouldn't have to change anything.
The code I put there is for the turf, not the objects you're picking up. Essentially, for every turf you step on, the turf will say "This is a mob, who wants to pick things up. So, I'm going to loop through my contents and find things (s)he can pick up."

The objects themselves have no direct way of knowing that a user has stepped onto the same tile as them. When a player moves, Move() calls several procs, including Entered() for their new location (almost always a turf, but it's also used for areas). Other objects on the same turf don't have anything called, so the only way to let them know is for turf.Entered() or the mob to tell them.

This is the reason that to implement a trap, you need to tell the turf there are traps there:
turf
var/list/traps

proc/SetTrap(obj/trap/T)
if(!traps) traps=list()
traps+=T

Entered(atom/movable/A)
if(ismob(A) && traps)
for(var/obj/trap/T in traps)
T.Trigger()
if(!traps.len) traps=null

Lummox JR
In response to SuperGoku15
SuperGoku15 wrote:
I've been trying what you guys said but nothing seems to work can you tell me whats wrong with this it gives me no errors but you dont pick up the item

> heart
> icon='heart.dmi'
> Entered(atom/movable/A)
> if (ismob(A))
> for(var/obj/heart in src)
> if (usr.health==usr.maxhealth)
> usr<<"<B>Your health is full"
> else
> usr.health+=1
> del(src)


There are a few problems here. The first: Never ever use usr inside Entered(). usr is for verbs, and you should only use it there unless you're absolutely sure you know what you're doing with it.
Also, as Shadowdarke said, you need to make this turf.Entered(), not obj/heart.Entered().
And, although it probably doesn't matter in the text output, I'd close that <B> tag with a </B>.

Try this instead:
turf
Entered(atom/movable/A)
if (ismob(A))
var/mob/M=A
var/i=0
for(var/obj/heart/H in src)
if(M.health>=M.maxhealth) break
M.health=min(M.health+H.value,M.maxhealth)
++i
del(H)
if(i) M << sound('heart.wav')

obj/heart
var/value=1
icon='heart.dmi'

Lummox JR