Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Class help please. (https://forums.graalonline.com/forums/showthread.php?t=87606)

Sage_Shadowbane 08-26-2009 06:00 AM

Class help please.
 
Hi, im having issues with this script. I'm not really used to using triggeractions so I was wondering if anyone could help me figure out the issue as to why my triggeraction isn't actually being triggered. This code is in a Class. It seems fine as far as the button being called and checking for the player.x/y but when I try to do the trigger to serverside, it doesn't seem to trigger for some odd reason.

NPC Code:
function onCreated() setshape(1, 32, 32);

function onPlayerchats() {
if (player.chat == ":destroy") {

destroy();
}
}

function onActionPickup()
{
destroy();
player.chat = "Pick up item!";
}

//#CLIENTSIDE
function onCreated() {

setImg("block.png");
setshape(1, 32, 32);
dontblock();
drawunderplayer();

onTimeout();
}

function onTimeout()
{
if (player.x in |x - 3, x + 2| && player.y in |y - 3.5, y + 2|) {

client.inPickupRange = true;
} else {
client.inPickupRange = false;
}
setTimer(0.01);
}

function onKeyPressed(keycode, keyname)
{
if (keyname == "A") {
if (client.inPickupRange) {

triggeraction(x + 0.5, y + 0.5, "Pickup");
}
}
}


Gambet 08-26-2009 06:15 AM

Try:

PHP Code:

triggerAction(this.x+0.5this.y+0.5"Pickup"""); 


Sage_Shadowbane 08-26-2009 06:22 AM

Quote:

Originally Posted by Gambet (Post 1518584)
Try:

PHP Code:

triggerAction(this.x+0.5this.y+0.5"Pickup"""); 


Alright, that solves the problem oddly. o.O Thanks Gambet. ^^

WhiteDragon 08-26-2009 06:26 AM

Quote:

Originally Posted by Sage_Shadowbane (Post 1518586)
Alright, that solves the problem oddly. o.O Thanks Gambet. ^^

That's because this.x and this.y refer to the location in the level while x and y refer to the location on the gmap. Yet another artifact of Graal's awesome scoping.

salesman 08-26-2009 06:38 AM

Quote:

Originally Posted by WhiteDragon (Post 1518587)
That's because this.x and this.y refer to the location in the level while x and y refer to the location on the gmap. Yet another artifact of Graal's awesome scoping.

I thought it was because triggerAction() needs 4 parameters...which is why Gambet added the ""

but I didn't know about the scope issues, either.

WhiteDragon 08-26-2009 06:39 AM

Quote:

Originally Posted by salesman (Post 1518592)
I thought it was because triggerAction() needs 4 parameters...which is why Gambet added the ""

Ah, yeah, that would be another problem.

The x/y/this.x/this.y is a problem on Gmaps though, dunno where he was testing it.

fowlplay4 08-26-2009 07:22 AM

Should use keydown(6) instead of hardcoded keys, while your at it. :)

Instead of keeping the last parameter blank, maybe include some sort of unique id to make sure that it receives the right trigger on the serverside, but it shouldn't be a problem, maybe if you have multiple drops stacked in one spot.

Also setTimer(0.01) is too fast and un-needed since Graal operates @ 20 frames / second thus setTimer(0.05) is the shortest time you'll need. But I think you might of just typo'd and intended to use setTimer(0.1); ;)

And.. instead of using a client variable in range, you should probably use a this. variable, then it won't have to update it with the server. Not to mention if you dropped multiple classes you'd pick them all up with one grab. :P

Sage_Shadowbane 08-26-2009 07:22 AM

I have another question, Inside of the class, I am trying to send variables from serverside to clientside in the class, Atm I'm trying to do so with a triggeraction also, but it doesn't seem to work. Any suggestions? :confused:

fowlplay4 08-26-2009 07:26 AM

You can store values in this.attr[] values, like so.

For example purposes:

PHP Code:


function onCreated() {
  
// Put a value in an attribute
  
this.attr[2] = "test!";
}

//#CLIENTSIDE

function onPlayerEnters() {
  
// Would set the NPC text to "test!"
  
this.chat this.attr[2];


You can alter the variables on the clientside, but changes will remain clientside, and will be overwritten/updated if changed on the serverside.

[email protected] 08-26-2009 09:02 PM

Yeah- I use the attribute feature alot to be honest. You can also use

HTML Code:

save[1-9] = value;
save[1] = true;

but I'd stick with attributes if I were you

Gambet 08-27-2009 12:38 AM

You can use triggerAction() to communicate from clientside to serverside and from serverside to clientside in level/class npcs as well.


All times are GMT +2. The time now is 06:15 PM.

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