Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 09-03-2012, 02:56 AM
scriptless scriptless is offline
Banned
Join Date: Dec 2008
Location: N-Pulse
Posts: 1,412
scriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to behold
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.
Reply With Quote
  #2  
Old 09-03-2012, 03:01 AM
ffcmike ffcmike is offline
Banned
Join Date: Jul 2004
Location: London
Posts: 2,029
ffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond repute
Send a message via AIM to ffcmike Send a message via MSN to ffcmike
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.
Reply With Quote
  #3  
Old 09-03-2012, 03:04 AM
scriptless scriptless is offline
Banned
Join Date: Dec 2008
Location: N-Pulse
Posts: 1,412
scriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to behold
Quote:
Originally Posted by ffcmike View Post
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 ?
Reply With Quote
  #4  
Old 09-03-2012, 03:05 AM
ffcmike ffcmike is offline
Banned
Join Date: Jul 2004
Location: London
Posts: 2,029
ffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond repute
Send a message via AIM to ffcmike Send a message via MSN to ffcmike
Quote:
Originally Posted by scriptless View Post
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.
Reply With Quote
  #5  
Old 09-03-2012, 03:07 AM
scriptless scriptless is offline
Banned
Join Date: Dec 2008
Location: N-Pulse
Posts: 1,412
scriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to behold
Quote:
Originally Posted by ffcmike View Post
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?
Reply With Quote
  #6  
Old 09-03-2012, 03:10 AM
ffcmike ffcmike is offline
Banned
Join Date: Jul 2004
Location: London
Posts: 2,029
ffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond repute
Send a message via AIM to ffcmike Send a message via MSN to ffcmike
Quote:
Originally Posted by scriptless View Post
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);
} 
Reply With Quote
  #7  
Old 09-03-2012, 03:22 AM
scriptless scriptless is offline
Banned
Join Date: Dec 2008
Location: N-Pulse
Posts: 1,412
scriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to behold
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?
Reply With Quote
  #8  
Old 09-03-2012, 03:25 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
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).
__________________
Reply With Quote
  #9  
Old 09-03-2012, 03:30 AM
scriptless scriptless is offline
Banned
Join Date: Dec 2008
Location: N-Pulse
Posts: 1,412
scriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to behold
Quote:
Originally Posted by cbk1994 View Post
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 View Post
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().
Reply With Quote
  #10  
Old 09-03-2012, 03:34 AM
ffcmike ffcmike is offline
Banned
Join Date: Jul 2004
Location: London
Posts: 2,029
ffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond repute
Send a message via AIM to ffcmike Send a message via MSN to ffcmike
Quote:
Originally Posted by scriptless View Post
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);
} 
Reply With Quote
  #11  
Old 09-03-2012, 03:44 AM
scriptless scriptless is offline
Banned
Join Date: Dec 2008
Location: N-Pulse
Posts: 1,412
scriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to behold
Quote:
Originally Posted by ffcmike View Post
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.
Reply With Quote
  #12  
Old 09-03-2012, 03:50 AM
ffcmike ffcmike is offline
Banned
Join Date: Jul 2004
Location: London
Posts: 2,029
ffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond repute
Send a message via AIM to ffcmike Send a message via MSN to ffcmike
Quote:
Originally Posted by scriptless View Post
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.
Reply With Quote
  #13  
Old 09-03-2012, 05:25 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by scriptless View Post
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.
__________________
Reply With Quote
  #14  
Old 09-03-2012, 05:34 AM
scriptless scriptless is offline
Banned
Join Date: Dec 2008
Location: N-Pulse
Posts: 1,412
scriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to behold
Quote:
Originally Posted by cbk1994 View Post
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?
Reply With Quote
  #15  
Old 09-03-2012, 06:12 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by scriptless View Post
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.
__________________
Reply With Quote
  #16  
Old 09-03-2012, 03:29 AM
ffcmike ffcmike is offline
Banned
Join Date: Jul 2004
Location: London
Posts: 2,029
ffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond repute
Send a message via AIM to ffcmike Send a message via MSN to ffcmike
Problem might be that you're using 'setshape2' instead of 'setshape'. Setshape2 is for modifying the tiletype's beneath an NPC.
Reply With Quote
  #17  
Old 09-03-2012, 03:57 AM
scriptless scriptless is offline
Banned
Join Date: Dec 2008
Location: N-Pulse
Posts: 1,412
scriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to behold
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.
Reply With Quote
  #18  
Old 09-03-2012, 04:08 AM
ffcmike ffcmike is offline
Banned
Join Date: Jul 2004
Location: London
Posts: 2,029
ffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond repute
Send a message via AIM to ffcmike Send a message via MSN to ffcmike
Quote:
Originally Posted by scriptless View Post
im thinking i need to reupdate the cord im triggering at maybe?
Yeah.

Quote:
Originally Posted by scriptless View Post
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 View Post
PHP Code:
  if ( this.candrag == true ) {
    
this.candrag = fasle; 
Reply With Quote
  #19  
Old 09-03-2012, 04:21 AM
scriptless scriptless is offline
Banned
Join Date: Dec 2008
Location: N-Pulse
Posts: 1,412
scriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to behold
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.
Reply With Quote
  #20  
Old 09-03-2012, 04:23 AM
ffcmike ffcmike is offline
Banned
Join Date: Jul 2004
Location: London
Posts: 2,029
ffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond repute
Send a message via AIM to ffcmike Send a message via MSN to ffcmike
I was referring to a slight typo of 'fasle'.
Reply With Quote
  #21  
Old 09-03-2012, 04:30 AM
scriptless scriptless is offline
Banned
Join Date: Dec 2008
Location: N-Pulse
Posts: 1,412
scriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to behold
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.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 08:01 AM.


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