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 03-05-2006, 10:56 PM
projectigi projectigi is offline
Registered User
Join Date: Jan 2004
Posts: 403
projectigi is an unknown quantity at this point
If Problem

ok
its like this
NPC Code:

chat=thiso.newtarget;
if(thiso.newtarget!=-1)this.target=thiso.newtarget;
chat=this.target;


now when i make it
NPC Code:

chat=thiso.newtarget;
if(thiso.newtarget!=-1)this.target=thiso.newtarget;
//chat=this.target;


it says a acc, like projectigi
when i make it
NPC Code:

chat=thiso.newtarget;
if(thiso.newtarget!=-1)this.target=thiso.newtarget;
chat=this.target;


it says -1(this.target is set to -1 before this)
__________________
Reply With Quote
  #2  
Old 03-05-2006, 11:46 PM
ZeLpH_MyStiK ZeLpH_MyStiK is offline
Scripter
ZeLpH_MyStiK's Avatar
Join Date: May 2003
Location: NYC
Posts: 553
ZeLpH_MyStiK is on a distinguished road
Send a message via MSN to ZeLpH_MyStiK Send a message via Yahoo to ZeLpH_MyStiK
I don't see any difference between the scripts other than the fact that the second one has the chat= commented out. What are you trying to say? Mind providing some more detail other than "its like this" and "i make it"?
__________________
Reply With Quote
  #3  
Old 03-05-2006, 11:50 PM
projectigi projectigi is offline
Registered User
Join Date: Jan 2004
Posts: 403
projectigi is an unknown quantity at this point
i say that thiso.newtarget is not -1
but it dont sets this.target to thiso.newtarget
__________________
Reply With Quote
  #4  
Old 03-06-2006, 01:47 AM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
When describing a problem you should also describe the input and output, then we can help checking if the actualy program is correct.
Input = values of this.target and thiso.target before the program runs
Output = value of 'chat' after the program is ran
Reply With Quote
  #5  
Old 03-06-2006, 03:42 PM
projectigi projectigi is offline
Registered User
Join Date: Jan 2004
Posts: 403
projectigi is an unknown quantity at this point
ok maybe i should post the whole script XD
maybe theres something wrong with with() or so

NPC Code:

function onCreated(){
this.cur_target=-1;
this.walkgani="hex-metalspider-walk";
this.idlegani="hex-metalspider-idle";
this.hitgani="hex-metalspider-attack";
showcharacter();
setCharAni(this.idlegani,"");
setTimer(0.05);
}
function onTimeout(){
//chat=playerscount;
if(playerscount>0){
if(this.cur_target==-1){
this.pindexes=getnearestplayers(x,y);
thiso.newdistance=10;
thiso.newtarget=-1;
thiso.baddy_x=x;
thiso.baddy_y=y;
for(i: this.pindexes){
with(players[i]){
this.ddb_dx=player.x-thiso.baddy_x;
this.ddb_dy=player.y-thiso.baddy_y;
this.dist=(this.ddb_dx*this.ddb_dx+this.ddb_dy*thi s.ddb_dy)^.5;
if(this.dist<thiso.newdistance){
thiso.newtarget=player.account;
thiso.newdistance=this.dist;
player.chat="targeted";
}
}
}
chat=thiso.newtarget;
if(thiso.newtarget!=-1)this.cur_target=thiso.newtarget;
chat=this.cur_target;
}else{
this.tmp_plr=findplayer(this.target);
if(this.tmp_plr.level==level){
}else{

this.target=-1;
this.tmp_plr=null;
}
}
setTimer(0.05);
}
}
function onPlayerEnters(){
setTimer(0.05);
}
function onPlayerChats(){
if(player.chat="/dbb")
destroy();
}
//#CLIENTSIDE
function onCreated(){
// chat="test";
}



well as i said, this three lines
NPC Code:

chat=thiso.newtarget;
if(thiso.newtarget!=-1)this.cur_target=thiso.newtarget;
chat=this.cur_target;


it says -1 (means this.cur_target is till -1)
NPC Code:

chat=thiso.newtarget;
if(thiso.newtarget!=-1)this.cur_target=thiso.newtarget;
// chat=this.cur_target;


there it says an acc (means thiso.newtarget must be a acc);
__________________
Reply With Quote
  #6  
Old 03-06-2006, 03:45 PM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
.account is the default parameter to the player object, I believe. If you just do player.chat = player; I believe it shows their account. Try doing: player.chat = this.cur_target.getdynamicvarnames();
__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
Reply With Quote
  #7  
Old 03-06-2006, 04:44 PM
projectigi projectigi is offline
Registered User
Join Date: Jan 2004
Posts: 403
projectigi is an unknown quantity at this point
chat=this.cur_target.getdynamicvarnames();
now it says nothing XD
at
chat=thiso.newtarget.getdynamicvarnames();
it dont say anything either
__________________
Reply With Quote
  #8  
Old 03-06-2006, 06:28 PM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
Quote:
Originally Posted by projectigi
chat=this.cur_target.getdynamicvarnames();
now it says nothing XD
at
chat=thiso.newtarget.getdynamicvarnames();
it dont say anything either
What about

PHP Code:
if(this.cur_target != NULL) {
  
chat "Hmm, something is in it.";
} else {
  
chat "x_x nothing here.";

__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
Reply With Quote
  #9  
Old 03-06-2006, 08:26 PM
projectigi projectigi is offline
Registered User
Join Date: Jan 2004
Posts: 403
projectigi is an unknown quantity at this point
it says
"Hmm, something is in it."
but why this check? i mean it cant be null
because its set to -1
__________________
Reply With Quote
  #10  
Old 03-06-2006, 08:58 PM
jake13jake jake13jake is offline
Former Classic Staff
jake13jake's Avatar
Join Date: Dec 2002
Location: Northwest Vermont
Posts: 1,452
jake13jake will become famous soon enough
Okay, the lack of commenting in that script makes me want to run and hide (just being honest).
Reply With Quote
  #11  
Old 03-06-2006, 11:04 PM
projectigi projectigi is offline
Registered User
Join Date: Jan 2004
Posts: 403
projectigi is an unknown quantity at this point
well im not good at explaining but here:
NPC Code:

function onCreated(){

this.cur_target=-1; // reset current target

this.walkgani="hex-metalspider-walk"; // set the walk

this.idlegani="hex-metalspider-idle"; //idle

this.hitgani="hex-metalspider-attack"; //and hit gani

showcharacter(); //well lol

setCharAni(this.idlegani,""); // set the current gani to the idlegani

setTimer(0.05); // start the timeout

}

function onTimeout(){

//chat=playerscount;

if(playerscount>0){ //when there still are players in the room

if(this.cur_target==-1){ //if no target is set

this.pindexes=getnearestplayers(x,y); // get the indexes of the players

thiso.newdistance=10; // set the newdistance to 10 so everything under a distance of 10 gets targeted

thiso.newtarget=-1; // set the new target to -1

thiso.baddy_x=x; // store baddy

thiso.baddy_y=y; // & y

for(i: this.pindexes){ // loop through the indexes

with(players[i]){ //get the player

this.ddb_dx=player.x-thiso.baddy_x; //calculate dx

this.ddb_dy=player.y-thiso.baddy_y; // & dy

this.dist=(this.ddb_dx*this.ddb_dx+this.ddb_dy*thi s.ddb_dy)^.5; //calculate distance

if(this.dist<thiso.newdistance){ //when the distance is smaller than the newdistance

thiso.newtarget=player.account; //set new target to the players account

thiso.newdistance=this.dist; //set newdistance to the current distance(to target the players, whos nearest at the baddie)

player.chat="targeted"; //debug help

}

}

}

chat=thiso.newtarget; // tel the newtarget

if(thiso.newtarget!=-1)this.cur_target=thiso.newtarget; //when newtarget is not -1 then set current target to the newtarget

chat=this.cur_target; // tell the current target

}else{

this.tmp_plr=findplayer(this.target); //get targeted player
if(this.tmp_plr.level==level){ // if player is in baddie level
//to be done later
}else{ // if not



this.cur_target=-1; //reset target

this.tmp_plr=null; // delete the temp player object

}

}

setTimer(0.05); // start timeout again

}

}

function onPlayerEnters(){

setTimer(0.05); (restart the timeout if an player enters)

}

function onPlayerChats(){

if(player.chat="/dbb")

destroy(); //to destroy them (only temp until its finished)

}

//#CLIENTSIDE

function onCreated(){

// chat="test";

}

__________________
Reply With Quote
  #12  
Old 03-06-2006, 11:12 PM
Codein Codein is offline
jwd
Codein's Avatar
Join Date: Oct 2005
Location: Greater Manchester
Posts: 2,423
Codein has a spectacular aura aboutCodein has a spectacular aura about
Send a message via AIM to Codein Send a message via MSN to Codein
I would have set the newtarget value to 0 on created and done:
if (!this.newtarget) instead :P

Might be the same thing though, not sure.
Reply With Quote
  #13  
Old 03-06-2006, 11:40 PM
projectigi projectigi is offline
Registered User
Join Date: Jan 2004
Posts: 403
projectigi is an unknown quantity at this point
i always used -1
xD
__________________
Reply With Quote
  #14  
Old 03-06-2006, 11:54 PM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to Skyld
Quote:
Originally Posted by projectigi
i always used -1
xD
0 technically equates to false, which is more useful.
__________________
Skyld
Reply With Quote
  #15  
Old 03-07-2006, 01:52 AM
Ajira Ajira is offline
Poont.
Join Date: Oct 2004
Location: NY, USA
Posts: 477
Ajira is on a distinguished road
You're doing a .05 timeout on serverside?
__________________
Liek omigosh.

Reply With Quote
  #16  
Old 03-07-2006, 07:14 PM
projectigi projectigi is offline
Registered User
Join Date: Jan 2004
Posts: 403
projectigi is an unknown quantity at this point
yeah I do lol
give me another way to make a baddy smooth =D
also this thread was supposed to talk about why the if doesnt work and not to talk about .05 serverside timeouts
its not even done xD
__________________
Reply With Quote
  #17  
Old 03-07-2006, 10:09 PM
napo_p2p napo_p2p is offline
oh snaps
napo_p2p's Avatar
Join Date: Sep 2003
Location: Pismo Beach, California
Posts: 2,118
napo_p2p has a spectacular aura aboutnapo_p2p has a spectacular aura about
Send a message via AIM to napo_p2p Send a message via MSN to napo_p2p
I haven't scripting movement in a long time, but I remember that the 'move' command had ways to cache movement so that serverside NPCs didn't look so "laggy."

Perhaps look into that? I'm sure there are threads in the forums about it.

EDIT: Found this, might help (for move command's last param):
Quote:
- cachingmode:
- 0: previous movements will be finished immediatelly
- 1: movements will be cached, the previous movements
will only be finished when the cache is too large
(distance to go >5);
this caching can be used on server-side npcs to
make the movement look like non-laggy even when
there are little delays sometimes
- 2: the movement will just be appended to the movement
list; you can add up to 100 movements
- blockcheck: add 4 to the options when you want the
npc to stop when there is a wall blocking the npc
- informmewhendone: if you add 8 to the options then the
script will be called with a 'movementfinished' flag
when the the npc has stopped walking; catch this event
with
if (movementfinished) {...}
if you want to do something when the npc has stopped
(e.g. walking in a different direction)
- applydirection: add 16 to the options if you want the
game to automatically set the direction of the npc
depending on the movement direction (can be good
when using movement caching)
__________________
Scito hoc super omnia.
Haec vita est tua una sola.
Dum vita superest, utere maxime quoque puncto, momento, et hora quae habes.
Tempus neminem non manet.
Noli manere tempus.
Carpe Diem

Seize the Day.

Last edited by napo_p2p; 03-08-2006 at 01:38 AM..
Reply With Quote
  #18  
Old 03-07-2006, 11:37 PM
projectigi projectigi is offline
Registered User
Join Date: Jan 2004
Posts: 403
projectigi is an unknown quantity at this point
as i said this thread is NOT supposed to talk about timeouts/lags
it supposed to talk about why this if doesnt works
and as i said it isnt done
__________________
Reply With Quote
  #19  
Old 03-08-2006, 01:28 AM
napo_p2p napo_p2p is offline
oh snaps
napo_p2p's Avatar
Join Date: Sep 2003
Location: Pismo Beach, California
Posts: 2,118
napo_p2p has a spectacular aura aboutnapo_p2p has a spectacular aura about
Send a message via AIM to napo_p2p Send a message via MSN to napo_p2p
Quote:
Originally Posted by projectigi
as i said this thread is NOT supposed to talk about timeouts/lags
it supposed to talk about why this if doesnt works
and as i said it isnt done
Hmm...

Quote:
give me another way to make a baddy smooth =D
Didn't you say that? Was just trying to help.
__________________
Scito hoc super omnia.
Haec vita est tua una sola.
Dum vita superest, utere maxime quoque puncto, momento, et hora quae habes.
Tempus neminem non manet.
Noli manere tempus.
Carpe Diem

Seize the Day.
Reply With Quote
  #20  
Old 03-08-2006, 01:32 AM
Ajira Ajira is offline
Poont.
Join Date: Oct 2004
Location: NY, USA
Posts: 477
Ajira is on a distinguished road
Quote:
Originally Posted by projectigi
as i said this thread is NOT supposed to talk about timeouts/lags
it supposed to talk about why this if doesnt works
and as i said it isnt done
I think someone needs to understand that the minimum timeout on serverside is .1.
__________________
Liek omigosh.

Reply With Quote
  #21  
Old 03-08-2006, 02:31 AM
jake13jake jake13jake is offline
Former Classic Staff
jake13jake's Avatar
Join Date: Dec 2002
Location: Northwest Vermont
Posts: 1,452
jake13jake will become famous soon enough
Quote:
Originally Posted by Ajira
I think someone needs to understand that the minimum timeout on serverside is .1.
Actually, you can have any timeout serverside now, it's just not wise to have a small timeout, not even 0.1.

However, there's still a bit of functionality in small timeouts. Let's say that you had an object you laid, you trigger it to activate, and then there's a time until deactivation required in the parameters of the trigger. Perhaps you'd want that to be 0.05, or perhaps 0.1. In most cases it probably wouldn't make sense, but there's probably a scenario that exists in which it does.

Now, looping timeouts serverside is a different story. I'd say 0.6 is the highest I'd go for them, and then only if the level has players in it. Such the case for Baddies.

A looping 0.05 serverside timeout is certainly enough to seriously risk crashing the NPC server.
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 12:13 AM.


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