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-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
  #2  
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
  #3  
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
  #4  
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
  #5  
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
  #6  
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 01:30 PM.


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