Quote:
Originally Posted by scriptless
I was using it in a Weapon Script. I was just showing how I was placing them.. now oddly. I can drag the npc.. it changes the chat above the npc.. but its not sending the right cords or something.. every time i move it it says the same x/y...
PHP Code:
function onActionServerside(command, nx, ny) { if ( command == "move" ) { x = nx; y = ny; chat = "moved" SPC nx SPC ny; } }
//#CLIENTSIDE function onCreated() { this.catchEvent(GraalControl, "onMouseDragged", "onMouseDragged"); setshape(1, getimgwidth(this.image), getimgheight(this.image)); this.oox = this.x; this.ooy = this.y; }
function onMouseDown() { if ( mousex in |x,x+getimgwidth(this.image)/16| && mousey in |y,y+getimgheight(this.image)/16| ) { this.ox = mousex - x; this.oy = mousey - y; this.candrag = true; } }
function onMouseUp() { if ( this.candrag == true ) { this.candrag = fasle; triggeraction(this.oox + .5, this.ooy +.5, "Serverside", "move", this.nnx, this.nny); } }
function onMouseDragged(obj, mod, mx, my) { if ( this.candrag == true ) { x = mousex - this.ox; y = mousey - this.oy; this.nnx = mousex - this.ox; this.nny = mousey - this.oy; } }
First time it's moved it fine after that it breaks.
|
It looks like it would be fine to send mousex and mousey as coordinate parameters, rather than using this.nnx and this.nny.
Also should use this.ox and this.oy to store this.x and this.y rather than factoring in the mouse position.
It's also worth mentioning that if the image hasn't been downloaded to your client yet, getimgwidth() and getimgheight() would return 0.