Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Serverside baddy (https://forums.graalonline.com/forums/showthread.php?t=54085)

sparkers 07-28-2004 07:36 PM

Serverside baddy
 
Hey can someone help me with this script?
There's a few problems.
1.It staggers when it walks and wont show the full gani. x_x
2.It can walk through anything.
3.When its hit its supposed to show text of its damage go up and a bit down.
NPC Code:


if (created) {setcharani popie,;initialize();setcharprop #P(1),hat#v(int(random(0,100))).png;
}
if (timeout&&this.found==0) {
for (i=-1;this.found==0;i+=1) {
this.found=1;
if (i>playerscount) i=-1;
}
timeout=.3
}
if (timeout&&this.found==1) {

if (abs(players[i].x-x)<=20&&abs(players[i].y-y)<=20) {
dir=getdir(players[i].x-x,players[i].y-y);
setcharani podies-walk,;
tx=players[i].x - x;
ty=players[i].y - y;
dist= (tx*tx+ty*ty)^0.5;
nx= (tx/dist)*1.2;
ny= (ty/dist)*1.2;
move nx,ny,1.2,4;
} else {setcharani podies,;message;this.found=0;timeout=.1}
if (players[i].x in |x-2,x+2|&&players[i].y in |y-2,y+2|) {setcharani podies-attack,;with(players[i]) {setani hurt,;playerhearts-=.5};sleep .5;timeout=1;}
timeout=.3;}

if (waS**t) {
message;setcharani podies,;

hearts-=.5;message #v(hearts);sleep 1;
checkdead()}

if (actionprojectile&&!hearts<=0) {
message;setcharani podies-hurt,;
hearts-=strtofloat(#p(1))*2;this.number=strtofloat(#p(1)) *2;
if (this.number != 0){
this.temp ++;
showtext 13,x,y-2*this.temp,veranda,r,#v(this.number);
if (this.temp = 4) this.number = 0;
}else{
hideimg 13;
this.temp = 0;
}




sleep 1;
checkdead();}
function initialize() {
setcharani podies,;setshape 1,50,50;
this.found=0;
hearts=30;
setcharani podies,;
timeout=.3;
}
function checkdead() {
if (hearts<=0) {setcharani podies-dead,;
with (players[i]) {
setplayerprop#c, I got some experience, yay!;
setstring client.playerexp,#v(strtofloat(#s(client.playerexp ))+3);
}
with (players[i+1]) {
setplayerprop#c, I got some experience, yay!;
setstring client.playerexp,#v(strtofloat(#s(client.playerexp ))+3);
}
with (players[i+2]) {
setplayerprop#c, I got some experience, yay!;
setstring client.playerexp,#v(strtofloat(#s(client.playerexp ))+3);
}

timeout=0;setcharani podies-dead,;sleep 2;hide;sleep 30; show;initialize()}
else timeout=.3;

}


xManiamaNx 07-28-2004 07:43 PM

Style your script, than I may attempt to help.

Lance 07-28-2004 08:23 PM

A few suggestions:

1) Code tags are relatively useless if you do not properly indent your code.
2) Focus on one problem at a time
3) Please refer to the KSI-GS thread. The link can be found in Loriel's 'Advice' thread.

Dach 07-28-2004 08:46 PM

red text added by Chad
Quote:

Originally Posted by sparkers
NPC Code:


if (created) {
setcharani popie,;
initialize();
setcharprop #P(1),hat#v(int(random(0,100))).png;//this should be done before calling the initialize function
}
if (timeout) {
if (this.found==0) {
for (i=-1;this.found==0;i+=1) {
this.found=1;
if (i>playerscount) i=-1;
}
}
if (this.found==1) {//don't make two separate timeout checks, redundancy is bad in scripts

if (abs(players[i].x-x)<=20&&abs(players[i].y-y)<=20) {
dir=getdir(players[i].x-x,players[i].y-y);
setcharani podies-walk,;
tx=players[i].x - x;
ty=players[i].y - y;
dist= (tx*tx+ty*ty)^0.5;
nx= (tx/dist)*1.2;
ny= (ty/dist)*1.2;
move nx,ny,1.2,4;
} else {setcharani podies,;message;this.found=0;timeout=.1}
if (players[i].x in |x-2,x+2|&&players[i].y in |y-2,y+2|) {
setcharani podies-attack,;
with(players[i]) {
setani hurt,;
playerhearts-=.5;
}
sleep .5;//sleep has been known to interrupt timeout loops
timeout=1;
}
}
timeout=.3;
}

if (waS**t) {
message;
setcharani podies,;
hearts-=.5;
message #v(hearts);
sleep 1;
checkdead();
}

if (actionprojectile&&!hearts<=0) {
message;setcharani podies-hurt,;
hearts-=strtofloat(#p(1))*2;
this.number=strtofloat(#p(1))*2;
if (this.number != 0) {
this.temp ++;
showtext 13,x,y-2*this.temp,veranda,r,#v(this.number);
if (this.temp = 4) this.number = 0;
}else{
hideimg 13;
this.temp = 0;
}
sleep 1;
checkdead();
}
function initialize() {
setcharani podies,;
setshape 1,50,50;
this.found=0;
hearts=30;
setcharani podies,;
timeout=.3;
}
function checkdead() {
if (hearts<=0) {
setcharani podies-dead,;
for(a=i;a<i+3;a++) {
with (players[a]) {//use a for loop with like operations
setplayerprop#c, I got some experience, yay!;
setstring client.playerexp,#v(strtofloat(#s(client.playerexp ))+3);
}
}
timeout = 0;
setcharani podies-dead,;
sleep 2;
hide;
sleep 30;
show;
initialize();
}
else timeout=.3;

}


as for the ani not showing, you are setting it over in the script, check to see if the ani is already set before resetting it

and please do follow the rules
edit: I didn't see that ! by the =, my bad

GoZelda 07-28-2004 08:58 PM

Mistaking = with == does not cause any problems, it's just adviced not too, as can be find in npcprogramming.rtf

Quote:

You can also use some other symbols like ':=' for assignment and a single '=' for checking equality, but it's not recommended (to keep compability to the Java/C++ syntax).

Lance 07-28-2004 09:28 PM

Quote:

Originally Posted by Dach
!==

Except != is the valid "not equals" comparison operator.

Ningnong 07-28-2004 10:29 PM

Why use a .3 timeout?

GoZelda 07-28-2004 11:10 PM

Quote:

Originally Posted by Ningnong
Why use a .3 timeout?

For the baddy's speed I'd say.


All times are GMT +2. The time now is 08:51 PM.

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