ID:163179
 
Is there a way I can use bump on an object and if not is there another way to make something happen when you go in contact with it?
The atom's Bump() procedure can do what you want.

atom
Bump(atom/Obstacle)
world << "[src] bumped into [Obstacle]"


As you can tell, when a movable object attempts to move, and something stops it from doing this, it will call the Bump() procedure with the argument as the object that stopped them from moving.

A common use is:

atom
Bump(atom/Obstacle)
Obstacle.Bumped(src)

proc
Bumped(atom/Bumper)
world << "[Bumper] bumped into [src]."


Using the Bumped() procedure, any object can have their own action when they're bumped.
In response to Keeth
Can you tell me why this doesn't work?
obj
butterfly
icon = 'player.dmi'
icon_state = "magic butterfly"
liveforever = TRUE
density = 1
isobj = 1
var/mob/M
New()
. = ..()
spawn()
move()
proc/move()
while(src)
step_rand(src)
sleep(10)

Bump(mob/M)
M.hp = M.maxhp
M << sound('sound/heal.wav',,,1,100)
In response to Hellonagol
Why is there a variable on the object called /mob/M?
I'll assume it's confusing priority.
In response to Keeth
I thought thats what its got to bump with...
In response to Hellonagol
obj
butterfly
icon = 'player.dmi'
icon_state = "magic butterfly"
liveforever = TRUE
density = 1
isobj = 1
var/mob/M // why is this here?
New()
. = ..()
spawn()
move()
proc/move()
while(src)
step_rand(src)
sleep(10)

Bump(mob/M)
M.hp = M.maxhp
M << sound('sound/heal.wav',,,1,100)
In response to Keeth
Cause I copy pasted it from my enemies code. took out the attack and the move towards usr. I just forgot that.

btw removing that still doesn't make it work
In response to Hellonagol
step_rand() doesn't count dense areas as areas it can step to, meaning it doesn't attempt to.
step() does, however.
In response to Keeth
well it works now but it only works when the obj bumps into me not when I bump into it... How can I change that?