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 02-05-2011, 05:11 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
Well the client has the (+90%) same functions so you can apply the concepts of getareanpcs on the client-side of the script.
__________________
Quote:
Reply With Quote
  #2  
Old 02-05-2011, 05:16 AM
kingcj kingcj is offline
Registered User
kingcj's Avatar
Join Date: Apr 2006
Location: TN
Posts: 114
kingcj will become famous soon enough
Send a message via MSN to kingcj
So something like this would work? I had been trying to work with that as well but I can't seem to get it working either. Maybe my syntax is wrong? I dunno..

PHP Code:
function onCreated() {
    for (
temp.ilevel.findareanpcs(this.xthis.y33)) {
      if (
temp.i.isinclass("bomb")) continue;
      echo(
"bombs?");
      
      
temp.i.trigger("Bombover"this);

    }

__________________
Zie

"It is not necessary to change. Survival is not mandatory." - W. Edwards Deming
Reply With Quote
  #3  
Old 02-16-2011, 01:42 AM
kingcj kingcj is offline
Registered User
kingcj's Avatar
Join Date: Apr 2006
Location: TN
Posts: 114
kingcj will become famous soon enough
Send a message via MSN to kingcj
Bump (sorta)
This is what I am working with, and everything works Except calling the function from the SwitchDB to the door.

This is the Switch Database

PHP Code:
function onCreated() {
  
SwitchDB this;
  
this.switches = new TStaticVar();
  
this.doors = new TStaticVar();
  
this.connections = new TStaticVar(); 
  
this.connections.switch_a "door_a";
}

public function 
addSwitch(temp.snametemp.sobj) {
  
this.switches.(@temp.sname) = temp.sobj;
  echo(
"added touch "@temp.sname);
}

public function 
addDoor(temp.dnametemp.obj) {
  
this.doors.(@temp.dname) = temp.obj;
  echo(
"added door " @temp.dname);
}

public function 
switchHit(temp.switchName) {
  echo(@ 
temp.switchName);
   
temp.doorName this.connections.(@temp.switchName); 
  
temp.door this.doors.(@temp.doorName);   
  echo(@
temp.doorName);
  
temp.door.doorOpen();   

The Switch

PHP Code:
function onCreated() {
  
SwitchDB findnpc("SwitchDB");
  
SwitchDB.addSwitch("switch_a"this);
  
setshape(1,32,32);
}

function 
onPlayerTouchsMe() {
  
SwitchDB.switchHit("switch_a");
  
this.chat "touched!";
  
sleep(1);
  
this.chat "";

And the door

PHP Code:
function onCreated() {
  
SwitchDB findnpc("SwitchDB");
  
SwitchDB.addDoor("door_a"this);
}


public function 
doorOpen() {
  
this.hide();
  
sleep(3);
  
this.show();

I've placed the public function in both the door and switchDB but doesn't work any which way i place it. Any help would be appreciated.
__________________
Zie

"It is not necessary to change. Survival is not mandatory." - W. Edwards Deming
Reply With Quote
  #4  
Old 02-16-2011, 01:52 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
does it echo anything in doorOpen? I would also recommend opening the door with a trigger instead of a public function. trigger forces the NPC to update to clients and what not.
__________________
Quote:
Reply With Quote
  #5  
Old 02-16-2011, 04:27 AM
kingcj kingcj is offline
Registered User
kingcj's Avatar
Join Date: Apr 2006
Location: TN
Posts: 114
kingcj will become famous soon enough
Send a message via MSN to kingcj
right but i can't use trigger beecause i want this to be able to be clientside as well. It gives me an error and says it can't find function doorOpen.
__________________
Zie

"It is not necessary to change. Survival is not mandatory." - W. Edwards Deming
Reply With Quote
  #6  
Old 02-16-2011, 05:42 AM
MrOmega MrOmega is offline
One More Time
MrOmega's Avatar
Join Date: Aug 2010
Location: TN, USA
Posts: 631
MrOmega is an unknown quantity at this point
Send a message via AIM to MrOmega Send a message via MSN to MrOmega Send a message via Yahoo to MrOmega
Are you putting 'on' before the function name. You need to put that with trigger

Such as

PHP Code:
trigger"foo"""); 
Would call...
PHP Code:
function onFoo() 
__________________
Time is the fire in which we burn...
Up, Up, Down, Down, Left, Right, Left, Right, B, A, Select, Start! Now I got 99 LIVES!!!
Reply With Quote
  #7  
Old 02-17-2011, 12:14 AM
kingcj kingcj is offline
Registered User
kingcj's Avatar
Join Date: Apr 2006
Location: TN
Posts: 114
kingcj will become famous soon enough
Send a message via MSN to kingcj
Quote:
Originally Posted by MrOmega View Post
Are you putting 'on' before the function name. You need to put that with trigger

Such as

PHP Code:
trigger"foo"""); 
Would call...
PHP Code:
function onFoo() 
Sorry I mis-read your quote. I tried placing on before the function, and I still get the error message.
__________________
Zie

"It is not necessary to change. Survival is not mandatory." - W. Edwards Deming
Reply With Quote
  #8  
Old 02-17-2011, 03:04 AM
kingcj kingcj is offline
Registered User
kingcj's Avatar
Join Date: Apr 2006
Location: TN
Posts: 114
kingcj will become famous soon enough
Send a message via MSN to kingcj
Sorry for like the triple post, but this seems to call the echo just don't know how to update the object now...

PHP Code:
public function door.doorOpen() {
  echo(
"crap");
  
this.hide();
  
sleep(3);
  
this.show();

Also in the SwitchDB I echo temp.door and it returns a 0 in RC Chat
__________________
Zie

"It is not necessary to change. Survival is not mandatory." - W. Edwards Deming

Last edited by kingcj; 02-17-2011 at 03:46 AM.. Reason: New Development
Reply With Quote
  #9  
Old 02-17-2011, 03:57 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
That last post is definitely going in the wrong direction.


One thing I can think of is that the onCreated() of the door or switch is getting called before the database's.

For debugging, echoing an object doesn't really make much sense, try echoing temp.door.type() instead to see if anything is actually there.
Reply With Quote
  #10  
Old 02-16-2011, 05:57 AM
kingcj kingcj is offline
Registered User
kingcj's Avatar
Join Date: Apr 2006
Location: TN
Posts: 114
kingcj will become famous soon enough
Send a message via MSN to kingcj
A trigger won't work clientside from the DB I don't think, but I don't really know. I don't understand why it won't pick this up as a function though? A trigger would be great if I could work it server to client and client to server without it being a weapon, unfortunately I have tried this.
__________________
Zie

"It is not necessary to change. Survival is not mandatory." - W. Edwards Deming
Reply With Quote
  #11  
Old 02-17-2011, 05:01 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
Quote:
Originally Posted by kingcj View Post
A trigger won't work clientside from the DB I don't think, but I don't really know. I don't understand why it won't pick this up as a function though? A trigger would be great if I could work it server to client and client to server without it being a weapon, unfortunately I have tried this.
Leads me to believe your door script looks like..

PHP Code:
//#CLIENTSIDE
function onCreated() { 
  
SwitchDB findnpc("SwitchDB"); 
  
SwitchDB.addDoor("door_a"this); 



public function 
doorOpen() { 
  
this.hide(); 
  
sleep(3); 
  
this.show(); 

which won't work because you can't call directly from server-side to client-side like that.
__________________
Quote:
Reply With Quote
  #12  
Old 02-17-2011, 06:06 AM
kingcj kingcj is offline
Registered User
kingcj's Avatar
Join Date: Apr 2006
Location: TN
Posts: 114
kingcj will become famous soon enough
Send a message via MSN to kingcj
Yea I know but I am trying to get it to work severside first. If it works severside I can put all the public functions clientside and get the same result clientside only, right? Plus my door script is at the top of this page with no //#CLIENTSIDE, and that's how it is in the script as well.
__________________
Zie

"It is not necessary to change. Survival is not mandatory." - W. Edwards Deming
Reply With Quote
  #13  
Old 02-17-2011, 06:34 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
Well for the most part because it is server-side you don't have to do the..

SwitchDB = findnpc("SwitchDB");

because the NPC is accessible via it's name without having to declare a global variable.

Following KISS theory...

SwitchDB

PHP Code:
// Empty Script
// Just using it to hold variables for now. 
Switch

PHP Code:
function onCreated() {
  
this.doorid "door_1";
  
this.image "block.png";
  echo(
this.doorid "'s switch has been created!");
}

function 
onPlayerTouchsMe() {
  echo(
player.account " touched the switch for door " this.doorid);
  
SwitchDB.door.(@this.switchid).trigger("DoorOpened"player.account);

Door

PHP Code:
function onCreated() {
  
this.doorid "door_1";
  
this.image "door.png";
  
SwitchDB.door.(@this.doorid) = this;
  echo(
this.doorid "'s door has been created!");
}

function 
onDoorOpened(acct) {
  echo(
this.doorid " has been opened by " acct "!");
  
hide();
  
sleep(3);
  
show();

From there we can work off the base and create the proper SwitchDB and classes that we require.

In my own "switch" system I store the main controller object (i.e: the door) and it's respective array of switches, and send a trigger to the main controller when a switch is updated (pressed on and off for instance) and the controller loops through the switches and performs the necessary logic (all switches are pressed down) and acts accordingly.
__________________
Quote:

Last edited by fowlplay4; 02-17-2011 at 07:45 PM..
Reply With Quote
  #14  
Old 02-17-2011, 06:57 AM
kingcj kingcj is offline
Registered User
kingcj's Avatar
Join Date: Apr 2006
Location: TN
Posts: 114
kingcj will become famous soon enough
Send a message via MSN to kingcj
That seems easy enough. Thanks for the help, but will it work clientside. I was trying to avoid the trigger because i didn't think i could call one clientside to clientside? I will try it and see! Thanks everyone!

I tried fp4's script and it works just gotta change some of it around. Works clientside as well...
__________________
Zie

"It is not necessary to change. Survival is not mandatory." - W. Edwards Deming

Last edited by kingcj; 02-17-2011 at 07:01 AM.. Reason: ...
Reply With Quote
  #15  
Old 02-17-2011, 04:17 PM
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
Quote:
Originally Posted by kingcj View Post
I tried fp4's script and it works just gotta change some of it around. Works clientside as well...
To get it to work client-side you would just have to use a weapon script or a level variable.

I.e:

PHP Code:
//#CLIENTSIDE
function onCreated() {
  
temp.SwitchDB findweapon("-System/DB");

The only issue is that you're trapped to the same level.

Also about your trigger worries, because you're staying on the same side it's really not that big of deal at all and has about the same impact as calling a public function. It's when you're going from client<->server that it becomes important to minimize the amount of triggerserver/clients/actions.
__________________
Quote:
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 07:33 PM.


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