Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Things that stop NPCs (https://forums.graalonline.com/forums/showthread.php?t=68984)

Yen 09-27-2006 01:50 PM

Things that stop NPCs
 
Zodiac's inventory has a major bug.
It randomly stops. By stopping, I mean it doesn't carry out any functions or catch any events.
I have no idea what causes it. The only thing I can think of that stops an NPC like this is when a script exceeds the loop limit. The console log doesn't give a loop limit exceeded error.

I can't fully debug the problem, because I can't make the bug happen to myself. However, a majority of Zodiac has it. These bugged players all seem to have the Stealth skill, but I also have it and I'm not experiencing the bug.

PHP Code:

//Skill: Stealth
function onActionServerside() {
  if (
params[0] == "cast") {
    
player.TakeMP(25,"skill");
  }
}
//#CLIENTSIDE
function onCreated() {
  
join("systemfunctions");
  
join("mudfunctions");
  
this.spelltime .4;
  
this.spellpower 0;
  
this.manacost 25;
  
this.element "Dark";
  
this.description "Makes you invisible to|others for a while.";
  
this.castani "carrystill";
}

function 
onCast() {
  if (
clientr.stat.mp this.manacost) return;
  
setani("carrystill",NULL);
  
this.ftime .5;
  if (
clientr.cmp.shadowblanket 0this.ftime -= clientr.cmp.shadowblanket .1;
  
freezeplayer(this.ftime);
  
findweapon("+System").AddBuff(/*Params clipped*/);
  
sleep(this.ftime);
  
setani("y-animation-hidden",NULL);
  
player.chat " ";
  if (
clientr.element == "Dark") {
    
temp.stealthtime clientr.levels.Thief 1.5;
  }
  else if (
clientr.element == "Light") {
    
temp.stealthtime clientr.levels.Thief .5;
  }
  else {
    
temp.stealthtime clientr.levels.Thief 1.5;
  }
  
temp.modz clientr.mods;
  while (
temp.modz.index("stealthup") >= 0) {
    
temp.stealthtime += temp.modz[temp.modz.index("stealthup")+1];
    
temp.modz.delete(temp.modz.index("stealthup")+1);
    
temp.modz.delete(temp.modz.index("stealthup"));
  }
  
findweapon("+System").AddBuff(/*Params clipped*/);
  
triggerserver("gui",name,"cast");
}

public function 
CanCast() {
  if (
HasBuff("invisible")) return false;
  return 
true;


PHP Code:

//System: Stealth-related functions
public function AddBuff(/*Params clipped*/) {
  switch (
type) {
    case 
"invisible":
      
this.invisible.duration time;
      
replaceani("walk","y-animation-hidden");
      
replaceani("idle","y-animation-hidden");
      
player.attr[3] = "";
      
RemoveEffects();
      break;
  }
}

function 
RemoveEffects() {
  for (
728b++) {
    
player.attr[b] = "";
  }
}

function 
onTimeout() {
  for (
/*Buff stuff*/) {
    if (
a[3] == "invisible") {
      
this.invisible.duration -= .05;
      if (
player.ani != "y-animation-hidden") {
        
this.invisible.duration 0;
      }
      if (
this.invisible.duration <= 0) {
        
RemoveBuff("invisible");
      }
    }
  }
}

public function 
RemoveBuff(/*Params clipped*/) {
  
this.(@type).duration 0;

  switch (
type) {
    case 
"invisible":
      
replaceani("walk",client.gani.walk);
      
replaceani("idle",client.gani.idle);
      
replaceani("sit","sit");
      
this.updateicon 0;
      if (
player.ani == "y-animation-hidden"setani(client.gani.idle,player.attr[2]);
      
UpdateBuffs();
    break;
  }
}

function 
UpdateBuffs() {
  for (
728b++) {
    
player.attr[b] = "";
  }
  for (
/*Buff stuff*/) {
    
player.attr[7+a] = /*Buff effect var clipped*/;
  }


Clipped out not-so-important parts that people-shouldn't-be-seeing.

Chompy 09-27-2006 04:21 PM

temp.modz = clientr.mods;
while (temp.modz.index("stealthup") >= 0) {
temp.stealthtime += temp.modz[temp.modz.index("stealthup")+1];
temp.modz.delete(temp.modz.index("stealthup")+1);
temp.modz.delete(temp.modz.index("stealthup"));
}

if the last member of temp.modz is "stealthup" and you do
temp.modz.delete(temp.modz.index("stealthup")+1);
why delete the member after "stealthup" if that was the last member?

correct me if I am wrong

and why you have two
temp.modz.delete(temp.modz.index("stealthup")+1);
temp.modz.delete(temp.modz.index("stealthup")); ?

or secret?

oh and also, if last member is "stealthup" (again)
why use
temp.stealthtime += temp.modz[temp.modz.index("stealthup")+1];?
(not sure if this would do something that I can't see in the script)

and again, correct me if I am wrong

Yen 09-27-2006 05:06 PM

Quote:

Originally Posted by Chompy (Post 1222855)
temp.modz = clientr.mods;
while (temp.modz.index("stealthup") >= 0) {
temp.stealthtime += temp.modz[temp.modz.index("stealthup")+1];
temp.modz.delete(temp.modz.index("stealthup")+1);
temp.modz.delete(temp.modz.index("stealthup"));
}

if the last member of temp.modz is "stealthup" and you do
temp.modz.delete(temp.modz.index("stealthup")+1);
why delete the member after "stealthup" if that was the last member?

correct me if I am wrong

and why you have two
temp.modz.delete(temp.modz.index("stealthup")+1);
temp.modz.delete(temp.modz.index("stealthup")); ?

or secret?

oh and also, if last member is "stealthup" (again)
why use
temp.stealthtime += temp.modz[temp.modz.index("stealthup")+1];?
(not sure if this would do something that I can't see in the script)

and again, correct me if I am wrong

You're very wrong.
The mod that increases stealth time takes the form of 'stealthup,time' so it deletes both the time and the stealthup

Chompy 09-27-2006 06:00 PM

ah, just wondered :D

but I was thinking of something, doesn't temp. variables get deleted after the ending bracet?

if (clientr.element == "Dark") {
temp.stealthtime = clientr.levels.Thief * 1.5;
}
else if (clientr.element == "Light") {
temp.stealthtime = clientr.levels.Thief * .5;
}
else {


or..?

And again (and again xD) correct me if I am wrong :)

but, do the function onCast() check if it allready has the buff (can't see the ckecking stuff in the script) and is onCast() done outside the same script?
if so;
sleep(this.ftime); if you cast the function from outside the script while the script has sleep wouldn't it stop the script?
That happened too one of my scripts
(everytime it added an showani of players head and used sleep then hide it, but when player died (or have been hitted many times)
the script stopped and I have to update the script)
Well that problem is gone now, but
I dunno if you should use sleep there :O


Correct me if I am wrong,
but I am guessing its wrong but I am trying atleast ^^

contiga 09-27-2006 06:09 PM

Sleep sometimes breaks timeout.

Chompy 09-27-2006 06:20 PM

ah

xXziroXx 09-27-2006 08:51 PM

Quote:

Originally Posted by contiga (Post 1222891)
Sleep sometimes breaks timeout.

Correct. Always re-initiate a timeout after a sleep have been carried out.

Chompy 09-27-2006 08:59 PM

hmm, not weird my script stopped, well I made an count variable and when it went under 0 it hided the showani.. xD

oh well ^^

Admins 09-28-2006 12:14 AM

Where is the timer started? A common error in scripts is to start the timer in onCreated(), but the timer is stopped in various situations when switching levels, so you need to start the timer in onPlayerEnters, on clientside, always.

xXziroXx 09-28-2006 12:34 AM

I have experienced this error alot while scripting the Malorian baddy.

NOTE FOR SENSITIVE READERS: GS1





PHP Code:

if (created) {
  
// Stuff
  
timeout .1;
}

if (
timeout) {
  
// stuff...
  
Move();
  
timeout .1;
}

function 
Move() {
  
// stuff...
  
move dxdytime8;
}

if (
movementfinished) {
  
//STUFF
  
timeout .1;


And unless the timeout in the 'movementfinished' is there, it wont execute the timeout.

Another example:

PHP Code:

if (created) {
  
// Stuff
  
timeout .1;
}

if (
timeout) {
  
// stuff...
  
Attack();
  
timeout .1;
}

function 
Attack() {
  
//stuff..
  
sleep 3;
  
timeout .1;


Unless the timeout is there after the sleep, well, you get the point by now.

Admins 09-28-2006 12:44 AM

I remember such problems with GS1 on serverside yes (sleep is using a timeout event internally), that's not happening with new scripting engine though.

Yen 09-28-2006 02:10 AM

It doesn't seem to be timer related. I don't see how the Stealth NPC can cause it to bug, either, because nothing Stealth does is related to the Inventory.

The +Inventory NPC stops responding, like when an NPC exceeds the loop limit.
It can't catch any events, such as onPlayerChats, and it can't do anything.

_Z3phyr_ 09-28-2006 07:28 AM

When I was first learning to script I realized that whenever I used a while() command without making it a continuous loop my script and game would freeze. Just on the off-chance that it does this maybe you'd want to try using something other than while()?

Yen 09-28-2006 01:45 PM

while () causes it to freeze when you don't have a limiter on it. In my case, it deletes each instance of 'stealthup' it finds, so it can't be go on forever.
A lot of other NPCs use while() as well, but only Stealth seems to cause the problem. :(

Admins 09-28-2006 07:17 PM

Normally the only thing that can stop the script completely from running is to do "this.ispaused = true" (or destroy() of course).
An exceeded loop-limited is just ending the current script execution, but other events are still working.
Other than that, most of the time when a clientside script is not doing anything it is because of the timer is not set.

Yen 09-28-2006 08:22 PM

Hmm, that's weird.
I can't see why the NPC would do this.. I had thought maybe it was breaking out of the timer or the on/off variable was getting stuck, but then I added a function to echo when the player chats. When the inventory broke, it stopped echoing.

_Z3phyr_ 09-28-2006 09:10 PM

*shrug*
Maybe its not the Stealth NPC that these players all have in common? If it is something relating to Stealth, maybe there's something in the Inventory NPC? If neither of those two then it has to be something else, if all of this stuff is wrong...

*puffs pipe and plays violin*


All times are GMT +2. The time now is 09:18 PM.

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