ID:273772
 
Okay so I have a pick up verb that works well with my newly implemented grid inventory however I would like it to function differently.

Rather than have players walk on top of an item before they can pick it up, I'd like the player to be able to initiate the pick up from anywhere but have it walk them to the spot before the item is picked up.

I know this will likely be a loop and involve walk_to() as well as oview but I have no idea how to formulate it as working code. My many attempts have failed so if anyone knows how this should work then could you please help me out? Thanks.

Assume it's pseudo-code as I'm not sure about errors/etc.
//same with all directions, or inside your movement proc
client/North()
mob.pickingUp = 0;

item/Click()
usr.pickingUp = 1
while(get_dist(src, usr) && usr.pickingUp)
step_to(usr, src)
sleep(movementDelay)
if(usr.pickingUp)
usr.pickingUp = 0
Pickup()

item/proc/Pickup()
//your pickup code which moves object and etc
In response to Zaoshi
@Zaoshi - 2 things...

1. Is your pickingUp variable a /client variable or an /item variable? You seem to display that you know the different between src and use within the Click proc, but at the same time you display that you don't know the difference. Personally, with such a system, I would put such a variable on the /item so that if others tried to pick the same item up, they would not be able to since it's already in process of being picked up by someone else.

2. IF your pickingUp is meant to be a /client variable, then every time the player made a Move via step_to, their pickingUp variable would be reset to 0, thus ending the loop.
In response to Spunky_Girl
Fixed, pickingUp is under /mob now, and it is supposed to end the loop.
In response to Zaoshi
The same problem exists... As soon as the player makes one step towards picking that item up, the loop will end.

EDIT
You could put a check inside client/Move() to check to see if the Move() made is further or equidistant away from the item, and if so, then cancel the picking up loop process.
In response to Spunky_Girl
client/Move() is only called when the client (player) presses an arrow key (or another macro set to a movement direction). It will not be called by step(), walk(), ect. So if it is called, you can assume the player wants control of their movement back.

I would suggest that you set pickingUp to the actual item they are targeting. Then you can also prevent the mob from going for two items at the same time, or going for an item that has been deleted.

Also, the loop shouldn't be handled under the item, it should be under the mob. And you need to check that the item's location remains a turf (ie hasn't been picked up by another player)
In response to Spunky_Girl
Doesn't client/North() get called only when I use .north command?
In response to Zaoshi
I completely forgot how client/Move() (as well as North(), East(), etc) were different from their mob/Move() counterparts. My bad. x.x
In response to DarkProtest
Is it fine now? I can't bother to start DM and test it.

mob
var/item/pickingUp = 0
proc/PickupItem(item/I)
pickingUp = I
while(pickingUp && get_dist(src, pickingUp) && isturf(pickingUp.loc))
step_to(usr, src)
sleep(movementDelay)
if(usr.pickingUp && !get_dist(src, pickingUp) && isturf(pickingUp.loc))
pickingUp.Pickup()
pickingUp = 0

client/Move()
mob.pickingUp = 0

item/Click()
usr.PickupItem(src)
In response to Zaoshi
Hey, thanks for your help guys. I've been insanely busy the past few days so I haven't been online.

Zaoshi I'll try out your code and see if I can get it working. Looks pretty good so I should be able to iron out any random issues. Thanks :D
In response to Zaoshi
Why give a /item type variable a number value at all when declared?