Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 08-26-2009, 06:00 AM
Sage_Shadowbane Sage_Shadowbane is offline
Graal Developer
Sage_Shadowbane's Avatar
Join Date: Mar 2004
Posts: 585
Sage_Shadowbane will become famous soon enough
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");
}
}
}

Reply With Quote
  #2  
Old 08-26-2009, 06:15 AM
Gambet Gambet is offline
Registered User
Join Date: Oct 2003
Posts: 2,712
Gambet is on a distinguished road
Try:

PHP Code:
triggerAction(this.x+0.5this.y+0.5"Pickup"""); 
Reply With Quote
  #3  
Old 08-26-2009, 06:22 AM
Sage_Shadowbane Sage_Shadowbane is offline
Graal Developer
Sage_Shadowbane's Avatar
Join Date: Mar 2004
Posts: 585
Sage_Shadowbane will become famous soon enough
Quote:
Originally Posted by Gambet View Post
Try:

PHP Code:
triggerAction(this.x+0.5this.y+0.5"Pickup"""); 
Alright, that solves the problem oddly. o.O Thanks Gambet.
Reply With Quote
  #4  
Old 08-26-2009, 06:26 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
Quote:
Originally Posted by Sage_Shadowbane View Post
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.
Reply With Quote
  #5  
Old 08-26-2009, 06:38 AM
salesman salesman is offline
Finger lickin' good.
salesman's Avatar
Join Date: Nov 2008
Location: Colorado
Posts: 1,865
salesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud of
Quote:
Originally Posted by WhiteDragon View Post
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.
Reply With Quote
  #6  
Old 08-26-2009, 06:39 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
Quote:
Originally Posted by salesman View Post
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.
Reply With Quote
  #7  
Old 08-26-2009, 07:22 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
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
__________________
Quote:
Reply With Quote
  #8  
Old 08-26-2009, 07:22 AM
Sage_Shadowbane Sage_Shadowbane is offline
Graal Developer
Sage_Shadowbane's Avatar
Join Date: Mar 2004
Posts: 585
Sage_Shadowbane will become famous soon enough
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?
Reply With Quote
  #9  
Old 08-26-2009, 07:26 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
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.
__________________
Quote:
Reply With Quote
  #10  
Old 08-26-2009, 09:02 PM
[email protected] sid.gottlieb@googlemail.com is offline
Banned
Join Date: Mar 2008
Posts: 861
sid.gottlieb@googlemail.com will become famous soon enough
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
Reply With Quote
  #11  
Old 08-27-2009, 12:38 AM
Gambet Gambet is offline
Registered User
Join Date: Oct 2003
Posts: 2,712
Gambet is on a distinguished road
You can use triggerAction() to communicate from clientside to serverside and from serverside to clientside in level/class npcs as well.
Reply With Quote
Reply


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 06:30 PM.


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