Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 07-28-2004, 07:36 PM
sparkers sparkers is offline
Yojumisto Online
sparkers's Avatar
Join Date: Jun 2004
Location: Why does anyone care about that?
Posts: 111
sparkers is on a distinguished road
Send a message via AIM to sparkers
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.
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;

}

Reply With Quote
  #2  
Old 07-28-2004, 07:43 PM
xManiamaNx xManiamaNx is offline
Supreme Dictator
xManiamaNx's Avatar
Join Date: Nov 2002
Location: 127.0.0.1
Posts: 385
xManiamaNx is on a distinguished road
Send a message via MSN to xManiamaNx Send a message via Yahoo to xManiamaNx
Style your script, than I may attempt to help.
__________________
Maniaman

Play Maloria Now: [2.3] [3]
Maloria Website

Reply With Quote
  #3  
Old 07-28-2004, 08:23 PM
Lance Lance is offline
dark overlord
Lance's Avatar
Join Date: Sep 2003
Location: Space Jam Mountain
Posts: 5,072
Lance is on a distinguished road
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.
Reply With Quote
  #4  
Old 07-28-2004, 08:46 PM
Dach Dach is offline
call me Chad, it's cooler
Dach's Avatar
Join Date: Aug 2002
Posts: 1,899
Dach is on a distinguished road
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
__________________
Scripting Documents:Old Script Documentation-Movement Tutorial

Last edited by Dach; 07-28-2004 at 09:32 PM..
Reply With Quote
  #5  
Old 07-28-2004, 08:58 PM
GoZelda GoZelda is offline
Mister 1,000,000
GoZelda's Avatar
Join Date: Jan 2003
Location: Brussels, capital of Europe.
Posts: 5,396
GoZelda will become famous soon enough
Send a message via AIM to GoZelda Send a message via MSN to GoZelda
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).
__________________

Quote:
Originally Posted by Lance
stefan is satan
I am the best.
[URL removed]Music or aural pollution?
Reply With Quote
  #6  
Old 07-28-2004, 09:28 PM
Lance Lance is offline
dark overlord
Lance's Avatar
Join Date: Sep 2003
Location: Space Jam Mountain
Posts: 5,072
Lance is on a distinguished road
Quote:
Originally Posted by Dach
!==
Except != is the valid "not equals" comparison operator.
Reply With Quote
  #7  
Old 07-28-2004, 10:29 PM
Ningnong Ningnong is offline
Registered User
Ningnong's Avatar
Join Date: Nov 2002
Location: < -- way
Posts: 262
Ningnong is on a distinguished road
Why use a .3 timeout?
__________________
Former Global Scripting Team Member


Reply With Quote
  #8  
Old 07-28-2004, 11:10 PM
GoZelda GoZelda is offline
Mister 1,000,000
GoZelda's Avatar
Join Date: Jan 2003
Location: Brussels, capital of Europe.
Posts: 5,396
GoZelda will become famous soon enough
Send a message via AIM to GoZelda Send a message via MSN to GoZelda
Quote:
Originally Posted by Ningnong
Why use a .3 timeout?
For the baddy's speed I'd say.
__________________

Quote:
Originally Posted by Lance
stefan is satan
I am the best.
[URL removed]Music or aural pollution?
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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:05 AM.


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