ID:143822
 
Code:
obj
dodgeball
icon = 'dodgeball.dmi'
density = 1
Bump(mob/M)
if(ismob(M))
M.loc = locate(38,43,2)
del(src)





verb
Pick_Up()
set category = "Dodgeball"
set src in oview(1)
if(usr.holding==0)
usr.overlays+='dodgeball.dmi'
usr.overlays+= usr.ball
usr.holding+=1
src.Move(usr)


Throw_Ball()
set category = "Dodgeball"
if(usr.holding==1)
usr.overlays-='dodgeball.dmi'
usr.overlays-= usr.ball
usr.holding=0
src.loc = usr.loc
walk(src,usr.dir,2)







mob/var/holding=0
mob/var/ball


Problem description:

You can throw the ball, and when It hits a mob, the mob teleports to the "Jail" outside of the game. But when you try to pick up the ball again, the ball becomes unthrowable and duplicates itself, leaving the copy on the ground, under the player.

And yes, I know I spaced everything too much.
usr.holding+=1

you might wanna change that to:

usr.holding = 1
The whole holding variable is silly. Just override mob/Enter() to keep two dodgeballs from entering a mob.

mob/Enter(obj/dodgeball/D)
if(istype(D))
if(locate(/obj/dodgeball) in src)
return 0
return ..()


Then you can just use Move() and it'll prevent the ball from entering. if(Move()) will allow you to check whether or not you were able to pick up the ball (though perhaps it would be best if overlays were handled in mob/Entered() and mob/Exited()).
In response to Garthor
Garthor wrote:
The whole holding variable is silly. Just override mob/Enter() to keep two dodgeballs from entering a mob.

mob/Enter(obj/dodgeball/D)
> if(istype(D))
> if(locate(/obj/dodgeball) in src)
> return 0
> return ..()

Then you can just use Move() and it'll prevent the ball from entering. if(Move()) will allow you to check whether or not you were able to pick up the ball (though perhaps it would be best if overlays were handled in mob/Entered() and mob/Exited()).

Im actually not sure where to put any of that. Im still a newbie coder.. thanks for the help tho!
In response to JaxxMarron
The Move(newloc) proc, in order to determine whether a movement is successful or not, will call loc.Exit() and newloc.Enter(). If they're both true, then loc.Exited() and newloc.Entered() are called, then the loc changes. This is behavior that is shared for all atom types (area, turf, obj, mob). Most often it's used to move from one turf to another, but it can be used to handle movement into and out of mobs.

For another example, see: http://developer.byond.com/docs/ref/info.html#/atom/proc/ Entered

By changing mob/Enter() to prevent the ball from entering if another ball is found in the mob, your pickup verb only needs to call Move() to attempt to move the ball into the player. If you want to know whether the move was successful or not, Move() will return 1 on success, so you can use if(Move()).
If the ball deleted itself when it hit something, how would you be able to pick it back up...?