Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   function onMousedown problem (https://forums.graalonline.com/forums/showthread.php?t=76670)

PrinceOfKenshin 09-07-2007 02:24 AM

function onMousedown problem
 
Ok so i have two npcs in a level and they both have

PHP Code:

function onMousedown(mode)
{
  if (
mode == "double")
{
 
triggeraction(0,0,"serverside","System/Main","genderset","male");
}


The only difference between the two is instead of "male" it's "female" in the other npc.

My problem is when i click on the male i get set as the female. And i don't want to have to keep it the way i have it now where you right click for male and left click for female.

Googi 09-07-2007 03:03 AM

Quote:

Originally Posted by PrinceOfKenshin (Post 1346206)
My problem is when i click on the male i get set as the female.

Sounds like it could be a problem with the script or part of the script that's being triggered.

DustyPorViva 09-07-2007 03:23 AM

Can't trigger weapons from level NPC's.

PrinceOfKenshin 09-07-2007 03:26 AM

Quote:

Originally Posted by DustyPorViva (Post 1346215)
Can't trigger weapons from level NPC's.

Soo i should make a class?

zokemon 09-07-2007 03:33 AM

Quote:

Originally Posted by DustyPorViva (Post 1346215)
Can't trigger weapons from level NPC's.

Yes you can.

Quote:

Originally Posted by PrinceOfKenshin (Post 1346216)
Soo i should make a class?

CLASSES ARE NOT OBJECTS! :mad:

I think your problem is that you don't have any x,y conditions. Maybe you are thinking of onActionMouseDown() or whatever? I only think that works serverside or so though, forgot (haven't been doing level npc scripting much in the past 6 months).

DustyPorViva 09-07-2007 03:34 AM

They can't either, as far as I know.
I honestly have no idea how to tackle this. Maybe some of the more savvy clientside/serverside scripters will have some advice.

EDIT: I've never been able to triggerserver/clientside from an NPC, at least from putnpc's, maybe you can with NPC's in levels. *shrug*

Inverness 09-07-2007 03:34 AM

onActionMouseDown() will work on any level object that has a shape. You'll need setshape on both sides to get it to work clientside and serverside.

Edit: onMouseDown() is detecting of the mouse button is pressed at all, you'll need to check where the mouse actually is yourself. Would probably be better to set a shape and use the action event instead.

Edit2: Btw, I believe its actually onActionLeftMouse() and onActionRightMouse()

PHP Code:

// This is an NPC in a level.
function onCreated() {
  
setShape(13232);
}
function 
onActionLeftMouse() {
  echo(
"You have clicked on the serverside.");
}
//#CLIENTSIDE
function onCreated() {
  
setShape(13232);
}
function 
onActionLeftMouse() {
  echo(
"You have clicked on the clientside.");


Theres also:
PHP Code:

//#CLIENTSIDE
function onMouseDown(mode) {
  if (
mousex in |xx+2| && mousey in |yy+2|) {
    if (
mode == "left") {
      
// You left clicked it
    
}
    else if (
mode == "right") {
      
// you right clicked it.
    
}
  }


You would also want to check if the GraalControl is the GUI thats focused.

DustyPorViva 09-07-2007 03:41 AM

function onActionleftmouse() {}

Inverness 09-07-2007 03:45 AM

Quote:

Originally Posted by DustyPorViva (Post 1346225)
function onActionleftmouse() {}

Indeed, this is basically what Graal is doing automatically for you:
PHP Code:

//#CLIENTSIDE
function onMouseDown(mode) {
  if (
mode == "left") {
    
triggerAction(mousexmousey"LeftMouse"null);
  }
  else if (
mode == "right") {
    
triggerAction(mousexmousey"RightMouse"null); 
  }



Googi 09-07-2007 04:50 AM

Quote:

Originally Posted by PrinceOfKenshin (Post 1346216)
Soo i should make a class?

No. First, try disabling or deleting the female-setting NPC to see whether or not the problem is that both are executing. Also, post the code that's being triggered.

Inverness 09-07-2007 05:16 AM

Quote:

Originally Posted by Googi (Post 1346239)
No. First, try disabling or deleting the female-setting NPC to see whether or not the problem is that both are executing. Also, post the code that's being triggered.

His problem is that hes executing code when onMouseDown() is triggered without actually checking where the mouse is clicking, so both NPCs run when the mouse is clicked anywhere rather than checking if the mouse clicked on them.

onMouseDown() is called on all objects on the clientside whenever the mouse button is clicked regardless of where.

Googi 09-07-2007 05:30 AM

Quote:

Originally Posted by Inverness (Post 1346244)
onMouseDown() is called on all objects on the clientside whenever the mouse button is clicked regardless of where.

I've never seen a script with mousex/mousey conditions following the onMouseDown event, so I assumed this wasn't the case, but indeed it is.

PrinceOfKenshin 09-07-2007 05:30 AM

Hmm i feel a feature request coming.

Googi 09-07-2007 05:32 AM

Quote:

Originally Posted by PrinceOfKenshin (Post 1346250)
Hmm i feel a feature request coming.

Huh? Why?

DustyPorViva 09-07-2007 06:26 AM

You can either do what Inverness posted, or simply use the function I posted.

Inverness 09-07-2007 07:04 AM

You should be using onActionLeftMouse() or onActionRightMouse() for level npcs, remember to define the shape.

Kyranki 09-07-2007 09:32 PM

PHP Code:

function GraalControl.onMouseDown(modifierxyclickcount) {


Are the proper number of params.

zokemon 09-07-2007 09:41 PM

Quote:

Originally Posted by Kyranki (Post 1346336)
PHP Code:

function GraalControl.onMouseDown(modifierxyclickcount) {


Are the proper number of params.

No, That's for onMouseDown. We are talking about triggering a "click" on a npc here.

Kyranki 09-07-2007 10:12 PM

Quote:

Originally Posted by zokemon (Post 1346341)
No, That's for onMouseDown. We are talking about triggering a "click" on a npc here.

Ahhh. Wasn't really paying attention to much here. xD

PrinceOfKenshin 09-07-2007 10:37 PM

Alright thank you my problem is fixed :D

EDIT: Umm how can i make a bigger range for the person to click?

would i do?
PHP Code:

if (mousex in |xx+2| && mousey in |y,y+2| && mousex in |,x,x+2| && mousey in |y,y+2|){ 


Inverness 09-07-2007 10:54 PM

|0, 5| would mean 0 or 5 or anything between those.
|x, x+5| would mean anything from the NPC's x coordinate to 5 tiles to the right of the x coordinate.

And like I said before, if you're clicking on NPCs in levels you should use setShape() and onActionLeftMouse()

PrinceOfKenshin 09-07-2007 11:39 PM

Gotcha makes since, yea i changed to onActionDoublemouse()


All times are GMT +2. The time now is 11:20 AM.

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