Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Triggeraction Difficulties (https://forums.graalonline.com/forums/showthread.php?t=134267070)

scriptless 09-03-2012 02:56 AM

Triggeraction Difficulties
 
I have been playing around with a script, but I am having problems. I try to drag the NPC using this script but it only triggers if I mouseup on the same spot it origonally was.. which is odd.. and when it triggers.. it triggers every NPC that is joined to the class.. anyone got any ideas whats wrong o.O

PHP Code:

function onActionServerside(command, nx, ny) {
  
chat = command;
}

//#CLIENTSIDE
function onCreated() {
  
this.catchEvent(GraalControl, "onMouseDragged", "onMouseDragged");
  
setshape2(1, getimgwidth(this.image), getimgheight(this.image));
}

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;
    
// clicked on it
  
}
}

function 
onMouseUp() {
  
this.candrag = false;
  
triggeraction(mousex, mousey, "Serverside", "test");
}

function 
onMouseDragged(obj, mod, mx, my) {
  if ( 
this.candrag = true ) {
    
//triggeraction(x, y, "Serverside", "test");
    
x = mousex - this.ox;
    
y = mousey - this.oy;
  }
} 

I have tried triggering at the following cords:
PHP Code:

this.ox, this.oy
mousex
, mousey
x
, y 

With no luck, both before and after updating the x/y values.

ffcmike 09-03-2012 03:01 AM

You need to be triggering within the shape of the NPC at the serverside position, you seem to be triggering the new coordinate rather than the existing one.

scriptless 09-03-2012 03:04 AM

Quote:

Originally Posted by ffcmike (Post 1703014)
You need to be triggering within the shape of the NPC at the serverside position, you seem to be triggering the new coordinate rather than the existing one.

Well I tried setshape on both clientside and serverside.. But im confused what you exactly mean by existing one? The old x/y ?

ffcmike 09-03-2012 03:05 AM

Quote:

Originally Posted by scriptless (Post 1703015)
Well I tried setshape on both clientside and serverside.. But im confused what you exactly mean by existing one? The old x/y ?

The position inwhich you expect the NPC to reside serverside.
The problem could also be that you're triggering edge-on with the NPC's shape, afaik you need to be within its shape, such as this.x + 0.5, this.y + 0.5.

scriptless 09-03-2012 03:07 AM

Quote:

Originally Posted by ffcmike (Post 1703017)
The position inwhich you expect the NPC to reside serverside.
The problem could also be that you're triggering edge-on with the NPC's shape, afaik you need to be within its shape, such as this.x + 0.5, this.y + 0.5.

well, what im trying to do is change it's x/y serverisde to follow the mouse.

so when i put the npc using putnpc2, it has an x and a y serverside... when i go to trigger it even tho clientside it changes x and y, i would need to trigger it at the origonal position i placed it?

ffcmike 09-03-2012 03:10 AM

Quote:

Originally Posted by scriptless (Post 1703018)
i would need to trigger it at the origonal position i placed it?

Yes. Then send the new X and Y positions as a parameter.

PHP Code:

function onActionServerSide(temp.x, temp.y){
  
this.x = temp.x;
  
this.y = temp.y;
}

//#CLIENTSIDE
function updatePosition(){
  
triggeraction(this.origx + 0.5, this.origy + 0.5, "Serverside", mousex, mousey);
} 


scriptless 09-03-2012 03:22 AM

Doesn't seem to be working, at all now.

PHP Code:

function onActionServerside(command, nx, ny) {
  
chat = command;
  
this.chat = command;
}

function 
onCreated() {
  
setshape2(1, getimgwidth(this.image), getimgheight(this.image));
  
this.oox = this.x;
  
this.ooy = this.y;
}

//#CLIENTSIDE
function onCreated() {
  
this.catchEvent(GraalControl, "onMouseDragged", "onMouseDragged");
  
setshape2(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 ) {
    
triggeraction(this.oox + .5, this.ooy +.5, "Serverside", "test");
    
this.candrag = fasle;
  }
}

function 
onMouseDragged(obj, mod, mx, my) {
  if ( 
this.candrag == true ) {
    
x = mousex - this.ox;
    
y = mousey - this.oy;
  }
} 

"this.oox" and "this.ooy" are the x and y when created serverrside, it sets shape both clientisde and serverside.. it triggers at the first x/y values serverside.. and now it wont even work retardedly.. =/

I am guessing I am going to need to "showimg()" where it will be shown while dragging, THEN update the x and y?

cbk1994 09-03-2012 03:25 AM

You shouldn't be using triggeraction for this anyway, it's unreliable, especially when you're doing something that involves moving the NPCs. Generally a better way is to setup some way of uniquely identifying your NPCs (easy if they're DB NPCs/putnpcs).

ffcmike 09-03-2012 03:29 AM

Problem might be that you're using 'setshape2' instead of 'setshape'. Setshape2 is for modifying the tiletype's beneath an NPC.

scriptless 09-03-2012 03:30 AM

Quote:

Originally Posted by cbk1994 (Post 1703022)
You shouldn't be using triggeraction for this anyway, it's unreliable, especially when you're doing something that involves moving the NPCs. Generally a better way is to setup some way of uniquely identifying your NPCs (easy if they're DB NPCs/putnpcs).

They are put npc's,

PHP Code:

function onActionServerside(command) {
  if ( 
params[0] == "puts" ) {
    
temp.obj = putnpc2(params[1], params[2], "");
    
temp.obj.image = "block.png";
    
temp.obj.join("personal_mewtoo18_test");
  }
}
//#CLIENTSIDE
function onWeaponFired() {
  
triggerServer("gui", this.name, "puts", player.x, player.y); 
} 

Is how they are being placed currently. I want to make them draggable, and showing there current position while dragged to other players.. I know Tig has something like this using WNPC's for player dragging but certain commands like "this.trigger()" didn't seem to be working on putnpc's for me.

Quote:

Originally Posted by ffcmike (Post 1703023)
Problem might be that you're using 'setshape2' instead of 'setshape'. Setshape2 is for modifying the tiletype's beneath an NPC.

And that, ladies and gentlemen, solved my problem. I was not aware of the difference in setshape() vs setshape2().

ffcmike 09-03-2012 03:34 AM

Quote:

Originally Posted by scriptless (Post 1703024)
PHP Code:

//#CLIENTSIDE
function onWeaponFired() {
  
triggerServer("gui", this.name, "puts", player.x, player.y); 
} 


While that would be fine for a weapon script, there is no 'this.name' within a local NPC on Clientside. You can however store it as an attr Serverside. The first parameter should also be 'npc' rather than 'gui'.

PHP Code:

function onCreated(){
  
this.attr[1] = this.name;
}
//#CLIENTSIDE
function sendTrigger(){
  
triggerserver("npc", this.attr[1], mousex, mousey);
} 


scriptless 09-03-2012 03:44 AM

Quote:

Originally Posted by ffcmike (Post 1703027)
While that would be fine for a weapon script, there is no 'this.name' within a local NPC on Clientside. You can however store it as an attr Serverside. The first parameter should also be 'npc' rather than 'gui'.

PHP Code:

function onCreated(){
  
this.attr[1] = this.name;
}
//#CLIENTSIDE
function sendTrigger(){
  
triggerserver("npc", this.attr[1], mousex, mousey);
} 


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.

ffcmike 09-03-2012 03:50 AM

Quote:

Originally Posted by scriptless (Post 1703029)
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.

scriptless 09-03-2012 03:57 AM

I send those parameters and then it breaks.. im thinking i need to reupdate the cord im triggering at maybe?

also, thanks for letting me know that about getimg...()... does that only apply to clientside or serverside as well?


EDIT: (Fixed, and working, now to clean it up)

PHP Code:

function onActionServerside(command, nx, ny) {
  if ( 
command == "move" ) {
    
x = nx;
    
y = ny;
    
this.oox = this.x;
    
this.ooy = this.y;
    
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", mousex, mousey);
    
this.oox = mousex;
    
this.ooy = mousey;
  }
}

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;
  }
} 

I had to set new cord's when i moved it, and then it worked fine.

ffcmike 09-03-2012 04:08 AM

Quote:

Originally Posted by scriptless (Post 1703031)
im thinking i need to reupdate the cord im triggering at maybe?

Yeah.

Quote:

Originally Posted by scriptless (Post 1703031)
also, thanks for letting me know that about getimg...()... does that only apply to clientside or serverside as well?

Only clientside.

I just noticed this too:

Quote:

Originally Posted by scriptless (Post 1703031)
PHP Code:

  if ( this.candrag == true ) {
    
this.candrag = fasle; 



scriptless 09-03-2012 04:21 AM

Yeah, if it's true, it does stuff and makes it not true. That way it wont let me do it again. Nothing wrong with that. However in the first post, I did "if ( this.candrag = true ) {" by mistake. I need to go ahead and clean the script up now that I have learned some new things about triggeractions, setshape, and image sizes.

Thanks for the help. Much appreciated.

ffcmike 09-03-2012 04:23 AM

I was referring to a slight typo of 'fasle'.

scriptless 09-03-2012 04:30 AM

Opps. Yeah I noticed that earlier, and fixed it. Broke the script and pasted the one from the forums I had posted previous but I guess I failed to fix it. Thanks for pointing that out.

cbk1994 09-03-2012 05:25 AM

Quote:

Originally Posted by scriptless (Post 1703024)
They are put npc's

In that case just use the NPC's name to identify it and don't try to trigger at some position which is inherently unreliable.

scriptless 09-03-2012 05:34 AM

Quote:

Originally Posted by cbk1994 (Post 1703046)
In that case just use the NPC's name to identify it and don't try to trigger at some position which is inherently unreliable.

Could you elaborate just a bit more? Putnpc NPC's have names?

cbk1994 09-03-2012 06:12 AM

Quote:

Originally Posted by scriptless (Post 1703048)
Putnpc NPC's have names?

Yes. A putnpc is just a more temporary database NPC. If you know an NPC's name, you can easily trigger it:

PHP Code:

triggerServer("npc", npc.attr[2], "poke"); 

note that the npc's name isn't available clientside (iirc) so you'll need to stuff it in an attribute or similar so that you can access it clientside (just do this.attr[2] = this.name serverside in onCreated).

Now you no longer have to worry about shapes or overlapping or any of that other junk.

scriptless 09-03-2012 06:15 PM

Quote:

Originally Posted by cbk1994 (Post 1703051)
Yes. A putnpc is just a more temporary database NPC. If you know an NPC's name, you can easily trigger it:

PHP Code:

triggerServer("npc", npc.attr[2], "poke"); 

note that the npc's name isn't available clientside (iirc) so you'll need to stuff it in an attribute or similar so that you can access it clientside (just do this.attr[2] = this.name serverside in onCreated).

Now you no longer have to worry about shapes or overlapping or any of that other junk.

Interesting to know, thanks. However, didn't you say there would be a better way then using triggeractions to do this? Because I'm not sure what you would be referring to. Unless you ment "triggeraction" being changed to "triggerserver" ?

And rather then a new thread for a 2 second fix, I have the above code also setting a variable after joining:

PHP Code:

temp.obj.placedby = player.account; 

The variable reads serverside from the class, but not clientside. Any idea other then a serverside to clientside trigger?

It seems attr's work but was wondering if theres any other way.

cbk1994 09-03-2012 09:43 PM

Quote:

Originally Posted by scriptless (Post 1703063)
Interesting to know, thanks. However, didn't you say there would be a better way then using triggeractions to do this? Because I'm not sure what you would be referring to. Unless you ment "triggeraction" being changed to "triggerserver" ?

There is a big difference between triggering at a coordinate and praying that it hits the NPC you're aiming for, and triggering the NPC by name.

scriptless 09-04-2012 12:36 AM

Quote:

Originally Posted by cbk1994 (Post 1703069)
There is a big difference between triggering at a coordinate and praying that it hits the NPC you're aiming for, and triggering the NPC by name.

All I asked was a yes or no question. Pretty sure the answer was yes tho.

And actually, there were to be multiple npc's placed in the level. Ounce clicked they would do something. So mouse down it still needs to know which one is to be focused on. So I don't know how you were suggesting graal determin "what I was clicking" based on one of many copies of the same npc in the level.

cbk1994 09-04-2012 12:54 AM

Quote:

Originally Posted by scriptless (Post 1703086)
All I asked was a yes or no question. Pretty sure the answer was yes tho.

If you're going to be a pedantic ****, at least do it right. I said there is a way to do it without triggeraction, not without triggers:

Quote:

Originally Posted by cbk1994 (Post 1703022)
You shouldn't be using triggeraction for this anyway

Quote:

Originally Posted by scriptless (Post 1703086)
And actually, there were to be multiple npc's placed in the level. Ounce clicked they would do something. So mouse down it still needs to know which one is to be focused on. So I don't know how you were suggesting graal determin "what I was clicking" based on one of many copies of the same npc in the level.

Not sure what you're saying or how that affects anything I said about triggering by name; with multiple NPCs in a level my point is even more valid since they provide additional things to get in the way of a coordinate trigger reaching its intended destination.

scriptless 09-04-2012 01:04 AM

Quote:

Originally Posted by cbk1994 (Post 1703089)
If you're going to be a pedantic ****, at least do it right. I said there is a way to do it without triggeraction, not without triggers:





Not sure what you're saying or how that affects anything I said about triggering by name; with multiple NPCs in a level my point is even more valid since they provide additional things to get in the way of a coordinate trigger reaching its intended destination.

I asked you to elaborate earlier and you didn't really. Which is why I asked specifically triggeraction or trigger.. Because all triggers, are actions o.O.

And you still wont elaborate "how does graal know which npc I click" if not by the mousex and y? Does it just guess? I ask for help you flame me when I ask to elaborate and you don't. Wth man.

Point being said, the mouse has to click anywhere on the npc.. then the npc judges where at you clicked, so it doesnt mess up where the npc is in relation to the mouse, as being dragged. If I just did a trigger for when the mouse is clicked I don't even begin to comprehend how graal is suspose to know "which" npc was clicked.

cbk1994 09-04-2012 02:39 AM

Quote:

Originally Posted by scriptless (Post 1703090)
Because all triggers, are actions o.O.

wat

Quote:

And you still wont elaborate "how does graal know which npc I click" if not by the mousex and y? Does it just guess? I ask for help you flame me when I ask to elaborate and you don't. Wth man.
Just because an NPC appears somewhere on your screen doesn't mean it's necessarily there or that it will still be there when the trigger reaches the server. When the mouse is clicked, figure out if one of your NPC's is being clicked on, get the NPC's name (stored in an attr), then trigger it.

BlueMelon 09-04-2012 04:04 AM

Quote:

Originally Posted by cbk1994 (Post 1703094)
When the mouse is clicked, figure out if one of your NPC's is being clicked on, get the NPC's name (stored in an attr), then trigger it.

Can't get any simpler then that.


All times are GMT +2. The time now is 05:55 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.