ID:1131276
 
(See the best response by Jemai1.)
Code:
mob/proc/shake()
sleep(2)
src.client.eye = locate(usr.x,usr.y++,usr.z)
src.client.perspective = EYE_PERSPECTIVE
sleep(2)
src.client.eye = usr
src.client.perspective = EYE_PERSPECTIVE
sleep(2)
src.client.eye = locate(usr.x++,usr.y,usr.z)
src.client.perspective = EYE_PERSPECTIVE
sleep(2)
src.client.eye = usr
src.client.perspective = EYE_PERSPECTIVE
sleep(2)
src.client.eye = locate(usr.x--,usr.y++,usr.z)
src.client.perspective = EYE_PERSPECTIVE
sleep(2)
src.client.eye = usr
src.client.perspective = EYE_PERSPECTIVE
sleep(2)
src.client.eye = locate(usr.x++,usr.y--,usr.z)
src.client.perspective = EYE_PERSPECTIVE
sleep(2)
src.client.eye = usr
src.client.perspective = EYE_PERSPECTIVE


Problem description:
Everytime shake() is called, the mob moves with eye. I don't know why.
Best response
First of all, no usr in procs.

You are moving your mob with src.x++. To create a screen shake effect, better use the client's pixel_x and pixel_y vars.

For example,
mob/proc/shake()
var/i = 1
while(client && i++<= 10)
client.pixel_x = rand(-16,16) // offset the screen randomly from 16 pixels left to 16 pixels right
client.pixel_y = rand(-16,16)
sleep(1)
if(client)
client.pixel_x = 0 // remove the offset
client.pixel_y = 0


EDIT: comments & explanation
Whoops, forgot about that rule briefly. Thank you.
I just tried it with pixel_ variables. It still did the same thing.

mob/proc/look(var/xpos,var/ypos,var/zpos)
client.pixel_x = xpos
client.pixel_y = ypos
client.pixel_z = zpos


mob/proc/shake()
sleep(2)
src.look(src.x+rand(0,1),src.y++,src.z)
sleep(2)
src.look(src.x,src.y,src.z)
sleep(2)
src.look(src.x--,src.y++,src.z)
sleep(2)
src.look(src.x,src.y,src.z)
sleep(2)
src.look(src.x++,src.y--,src.z)
sleep(2)
src.look(src.x,src.y,src.z)
You are doing src.x++ and such. That'll change your mob's x/y/z variable.

The value of pixel_x/y should be in pixels. For pixel_x, positive values will move your screen to the right and negative to the left.

e.g. pixel_x = -32 will offset your screen 32 pixels left. That's 1 tile left if your icon size is 32x32.

See my previous example.
Do I use a + operator for pixel_ var? If not, how do I make it so that the screen goes back to the player?
Setting pixel_x/y to 0 will remove the offsets.
Hmm... I get runtime errors when I do it with the = method.

Error:
runtime error: list index out of bounds
proc name: shake (/mob/proc/shake)
usr: Gavyn (/mob)
src: Gavyn (/mob)
call stack:
Gavyn (/mob): shake()
the sidewalk (25,7,1) (/turf/muggle/road/sidewalk): >Click(the sidewalk (25,7,1) (/turf/muggle/road/sidewalk), >"default.map1", "icon-x=13;icon-y=20;left=1;scr...")

Note that for testing purposes, I have made clicking a "sidewalk" turf activate shake(). Here's the updated code for shake():

mob/proc/shake()
sleep(4)
src.look(client.pixel_x = rand(0,1),client.pixel_y = 1,client.pixel_z = 0)
sleep(4)
src.look(client.pixel_x = 0,client.pixel_y = 0,client.pixel_z = 0)


The look() proc has remained untouched.

You can't do stuff like that.

Just.. do it like how I did.
I'm not sure how to do it with the look() proc, though.

EDIT: Nevermind, fixed it.
Why do you need a look proc?
I wanted a look proc in there because I had planned to have the player see other places in other scenarios, as well. Unfortunately, I don't want to go through the trouble of typing pixel_vars for each time.
If that's the case, you can make your look proc BUT you don't need to incorporate it with shake
mob/proc/look(x,y,z)
if(client)
client.eye = locate(x,y,z)
client.perspective = EYE_PERSPECTIVE

mob/proc/shake() // unchanged
var/i = 1
while(client && i++<= 10)
client.pixel_x = rand(-16,16) // offset the screen randomly from 16 pixels left to 16 pixels right
client.pixel_y = rand(-16,16)
sleep(1)
if(client)
client.pixel_x = 0 // remove the offset
client.pixel_y = 0