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
  #41  
Old 02-17-2011, 04:59 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 WhiteDragon View Post
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.
Yea Kinda figured that. I tried the temp.door.type() and got nothing in RC. Maybe this should be done a different way? Maybe place everything in one function that connects objects and all with params? I dunno.
__________________
Zie

"It is not necessary to change. Survival is not mandatory." - W. Edwards Deming
Reply With Quote
  #42  
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
  #43  
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
  #44  
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
  #45  
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
  #46  
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
  #47  
Old 02-17-2011, 11:16 PM
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 fowlplay4 View Post
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.
It worked Clientside without a weapon script or level var... I just put //#CLIENTSIDE at the top and it worked for me and my buddy on clientside only. I don't know if it is suppose to work that way or not, but it does I assure you, even without this added scripting. I haven't checked to see yet, but I don't know if I would be trapped to the same level with the trigger or not. Again thanks for the help!
__________________
Zie

"It is not necessary to change. Survival is not mandatory." - W. Edwards Deming
Reply With Quote
  #48  
Old 02-18-2011, 05: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
Ok so the main reason I was trying to use a public function was to make sure that the script could be done clientside. Here is what I am working with now. It works, once but not twice, and is very very slow. Any pointers here would be great

The Switch:
PHP Code:
//#CLIENTSIDE
function onCreated() { 
  
this.switchid "door_2"
  
this.image "block.png"


function 
onPlayerenters() {
  
onTimeOut();
}

function 
onTimeOut() {
  if (
players.size() > 0
    
setTimer(0.1);
    else 
    
setTimer(0);
  for (
temp.findareanpcs(this.x-2this.y-222)) {
    if (
temp.i.isinclass("bomb")) 
      
SwitchDB.door.(@this.switchid).trigger("DoorOpened"null);
      
sleep(3.2);
      
onTimeOut();
     }

And the Door:
PHP Code:
//#CLIENTSIDE
function onCreated() {
  
this.doorid "door_2";
  
this.image "door.png";
  
SwitchDB.door.(@this.doorid) = this;
}

function 
onDoorOpened() {
  
hide();
  
sleep(3.15);
  
show();

__________________
Zie

"It is not necessary to change. Survival is not mandatory." - W. Edwards Deming
Reply With Quote
  #49  
Old 02-18-2011, 08:12 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
If you style your script properly you'll see the following..

PHP Code:
//#CLIENTSIDE
// other code..

function onTimeOut() { 
  if (
players.size() > 0)  // Useless on client-side since script won't run
    
setTimer(0.1);         // if player is in another level.
    
else  
    
setTimer(0);
  
// Loops through all npcs near the switch
  
for (temp.findareanpcs(this.x-2this.y-222)) {
    
// Checks if npc is a bomb
    
if (temp.i.isinclass("bomb")) { // Added the { for clarity
      // Triggers switch
      
SwitchDB.door.(@this.switchid).trigger("DoorOpened"null);
    }
    
// Sleeps for 3.2 seconds
    
sleep(3.2);
    
// Recursively calls onTimeout again, leading to an infinite loop.
    // Without a sleep the script would break quite quickly after hitting
    // the stack/maxloop limit.
    
onTimeOut(); 
  } 

Notice how you're sleeping for every NPC around the switch and then calling onTimeout which causes that nasty loop.

Also something about calling onTimeout directly like that is just unsettling to me, the only time I do that is when I'm hacking around with code.

Recursion crash example:

PHP Code:
//#CLIENTSIDE
function onCreated() {
  
recurse(0);
}

function 
recurse(a) {
  echo(
a);
  
recurse(a+1);

That's as big as hint as I'll give you, I'm sure you can figure out what you need to change.
__________________
Quote:

Last edited by fowlplay4; 02-18-2011 at 08:28 AM..
Reply With Quote
  #50  
Old 02-18-2011, 04:31 PM
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 fowlplay4 View Post
That's as big as hint as I'll give you, I'm sure you can figure out what you need to change.
Thanks for the help again! I was trying to use sleep to wait untill the bomb was off the switch because it triggers the function on every timeout, so while the bomb is on the switch, it continuously triggers the door.

I don't know if that will cause any problems with lag and so forth, but it works fine when sleep and the player.size were removed. Guess i could slow the Timeout down and then speed it up again..lol.. that just came to me as I was typing....

Thanks Again.
__________________
Zie

"It is not necessary to change. Survival is not mandatory." - W. Edwards Deming
Reply With Quote
  #51  
Old 02-21-2011, 10:55 PM
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
Ok on the same subject still... I place the custom bomb on a switch which opens a door, when the bomb explodes the door closes. This part works great except the door opens serverside. The bomb has an owner, and I transfer that info to the switch which has the acct in the trigger that sends it to the door. When it gets to the door the door still opens for everyone serverside. I want it to work clientside so everyone will have to open the door using their own bomb. The owner of the bomb is stored with a var (this.owner), and I don't know if it needs to be a trigger.
__________________
Zie

"It is not necessary to change. Survival is not mandatory." - W. Edwards Deming
Reply With Quote
  #52  
Old 02-21-2011, 11:14 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
Store the owner's account in attr[i]bute and check it like how you're doing it up there..

I.e: (temp.i.isinclass("bomb") && temp.i.attr[1] == player.account)
__________________
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 03:48 PM.


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