Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   If Problem (https://forums.graalonline.com/forums/showthread.php?t=64578)

projectigi 03-05-2006 10:56 PM

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)

ZeLpH_MyStiK 03-05-2006 11:46 PM

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"?

projectigi 03-05-2006 11:50 PM

i say that thiso.newtarget is not -1
but it dont sets this.target to thiso.newtarget

Admins 03-06-2006 01:47 AM

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

projectigi 03-06-2006 03:42 PM

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);

ApothiX 03-06-2006 03:45 PM

.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();

projectigi 03-06-2006 04:44 PM

chat=this.cur_target.getdynamicvarnames();
now it says nothing XD
at
chat=thiso.newtarget.getdynamicvarnames();
it dont say anything either

ApothiX 03-06-2006 06:28 PM

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.";



projectigi 03-06-2006 08:26 PM

it says
"Hmm, something is in it."
but why this check? i mean it cant be null
because its set to -1

jake13jake 03-06-2006 08:58 PM

Okay, the lack of commenting in that script makes me want to run and hide (just being honest).

projectigi 03-06-2006 11:04 PM

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";

}


Codein 03-06-2006 11:12 PM

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.

projectigi 03-06-2006 11:40 PM

i always used -1
xD

Skyld 03-06-2006 11:54 PM

Quote:

Originally Posted by projectigi
i always used -1
xD

0 technically equates to false, which is more useful.

Ajira 03-07-2006 01:52 AM

You're doing a .05 timeout on serverside?


All times are GMT +2. The time now is 04:10 AM.

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