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 09-25-2005, 09:43 PM
excaliber7388 excaliber7388 is offline
Banned
excaliber7388's Avatar
Join Date: Jul 2005
Location: US
Posts: 5,229
excaliber7388 can only hope to improve
Send a message via AIM to excaliber7388
hmmmm

okay, this is a script that I'm using, and it works, however when it's used around an npc baddie, it doesn't work, why yould this be happening? (baddies are both the pre-defined ones, and other ones made in similar fashions, which is most of the baddies on the sever, so i'd rather change this script)
NPC Code:
//NPC made By Excaliber
//#CLIENTSIDE
if(isweapon&&weaponfired&&playermp>4||isweapon&&mo usedown&&playermp>4){
disabledefmovement;
showimg 300,dr-crosshairs.png,mousex-.5,mousey-.35;
set shooting;
timeout=.05;
}
if(isweapon && shooting && timeout){
replaceani idle,grab;
setani grab,;
showimg 300,dr-crosshairs.png,mousex-.5,mousey-.35;
timeout=.05;
}
if(shooting&&keypressed&&strequals(#p(1),A)){
unset shooting;
hideimg 300;
enabledefmovement;
replaceani idle,idle;
setani idle,;
}

if(strequals(#w,Lightning 2)&&shooting && mousedown && leftmousebutton){
unset shooting;
playermp=playermp-5;
showimg 400,dr-lightning.png,mousex-.5,mousey-8;
newx2 = mousex;
newy2 = mousey;
for(i=1;i<100;i=i+25){
changeimgpart 400,0,0,35,i;
sleep .05;
}
putexplosion2 3,4,newx2-.75,newy2-.75;
hideimg 400;
hitobjects 2,mousex,mousey;
hitobjects 2,mousex-.25,mousey-.25;
hitobjects 2,mousex+.25,mousey-.25;
hitobjects 2,mousex-.25,mousey+.25;
hideimg 300;
timeout=.05;
replaceani idle,idle;
setani idle,;
enabledefmovement;
hideimg 302;
sleep 3;
hideimg 301;
}
if(timeout&&!shooting){
hideimg 300;
}

Reply With Quote
  #2  
Old 09-25-2005, 09:49 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
Be more specific. What about it doesn't work around an npc baddy?

Also, please make your script readable.
__________________
Skyld
Reply With Quote
  #3  
Old 09-26-2005, 02:37 AM
excaliber7388 excaliber7388 is offline
Banned
excaliber7388's Avatar
Join Date: Jul 2005
Location: US
Posts: 5,229
excaliber7388 can only hope to improve
Send a message via AIM to excaliber7388
well, dr-lightning is a lightning gfx that, when the weapon is fired, seams to strike the ground, however, when around a baddie, it only shows the top of the gfx, and the lighning doesn't strike, unless you hurt the baddie. There's something in the script that 'pauses' it untill the baddie's hurt:here's a basic script of a baddie, and a better looking version of my script for the lightning:
lightning:
NPC Code:
//NPC made By Excaliber
//#CLIENTSIDE
if(isweapon&&weaponfired&&playermp>4||isweapon&&mo usedown&&playermp>4){
disabledefmovement;
showimg 300,dr-crosshairs.png,mousex-.5,mousey-.35;
set shooting;
timeout=.05;
}
if(isweapon && shooting && timeout){
replaceani idle,grab;
setani grab,;
showimg 300,dr-crosshairs.png,mousex-.5,mousey-.35;
timeout=.05;
}
if(shooting&&keypressed&&strequals(#p(1),A)){
unset shooting;
hideimg 300;
enabledefmovement;
replaceani idle,idle;
setani idle,;
}

if(strequals(#w,Lightning 2)&&shooting && mousedown && leftmousebutton){
unset shooting;
playermp=playermp-5;
showimg 400,dr-lightning.png,mousex-.5,mousey-8;
newx2 = mousex;
newy2 = mousey;
for(i=1;i<100;i=i+25){
changeimgpart 400,0,0,35,i;
sleep .05;
}
putexplosion2 3,4,newx2-.75,newy2-.75;
hideimg 400;
hitobjects 2,mousex,mousey;
hitobjects 2,mousex-.25,mousey-.25;
hitobjects 2,mousex+.25,mousey-.25;
hitobjects 2,mousex-.25,mousey+.25;
hideimg 300;
timeout=.05;
replaceani idle,idle;
setani idle,;
enabledefmovement;
hideimg 302;
sleep 3;
hideimg 301;
}
if(timeout&&!shooting){
hideimg 300;
}


a basic baddie script:
NPC Code:
// Graal2002 NPC by Stefan Knorr
//#CLIENTSIDE
if (created) {
// Initialize the attributes
showcharacter;
setcharprop #3,head0.png;
setcharprop #C0,orange;
setcharprop #C1,white;
setcharprop #C2,blue;
setcharprop #C3,red;
setcharprop #C4,black;
setcharprop #2,shield1.gif;
shieldpower = 1;
dir = 2;
swordpower = 1;
hurtdx = 0;
hurtdy = 0;
hearts = 3;
}
if (playerenters || wasthrown) {
// Initialize the this. variables
message;
this.huntspeed = 0.4;
timeout = 0.05;
if (hearts<=0) {
this.mode = 5; // RESPAWN
this.runcounter = 0;
timeout = 5;
} else {
this.mode = 0;
setcharani idle,;
this.runcounter = int(random(10,40));
}
}

// Sword attacking stuff
if (timeout && (this.mode==0 || this.mode==2)) {
// Look for players
mindist = 1000;
for (i=0; i<playerscount; i++)
if (players[i].hearts>0 && players[i].id>=0) {
dx = players[i].x - x;
dy = players[i].y - y;
if (abs(dx)>abs(dy)) {
if (dx>0) pdir=3; else pdir=1;
} else {
if (dy>0) pdir=2; else pdir=0;
}
if (pdir==dir) {
dist = (dx*dx+dy*dy)^0.5;
if (dist<mindist) {
cansee = 1;
if (abs(dx)>abs(dy)) k = int(abs(dx));
else k = int(abs(dy));
for (j=0; j<=k-2; j++)
if (onwall(x+1.5+dx*j/k,y+2+dy*j/k)) cansee = 0;
if (cansee!=0) {
mindist = dist;
aimplayer = i;
this.aimx = players[i].x;
this.aimy = players[i].y;
}
}
}
}
if (mindist<=3) {
this.runcounter = -1;
this.mode = 3; // SLAYING
setcharani sword,;
timeout = 0.05;
} else if (mindist<20) {
if (this.mode!=2) message Stop!;
this.runcounter = 100;
this.mode = 2; // HUNTING
} else timeout = 0.05;
}
if (timeout && this.mode==3) { // SLAYING
this.runcounter++;
if (this.runcounter>4) {
this.runcounter = 100;
this.mode = 2; // HUNTING
setcharani idle,;
}
message;
timeout = 0.05;
}
if (timeout && this.mode==2) { // HUNTING
setcharani walk,;
this.runcounter--;
if (this.runcounter>0 && aimplayer<playerscount && players[aimplayer].hearts>0) {
// Get new direction
dx = players[aimplayer].x-x;
dy = players[aimplayer].y-y;
if (abs(dx)>abs(dy)) {
if (dx>0) dir=3; else dir=1;
} else {
if (dy>0) dir=2; else dir=0;
}

// Test if we can do a step
dx = this.aimx-x;
dy = this.aimy-y;
if (abs(dx)<=1 && abs(dy)<=1) {
this.aimx = players[aimplayer].x;;
this.aimy = players[aimplayer].y;
dx = this.aimx-x;
dy = this.aimy-y;
}
if (abs(dx)>abs(dy)) {
if (dx>0) testdir=3; else testdir=1;
} else {
if (dy>0) testdir=2; else testdir=0;
}
len = (dx*dx+dy*dy)^0.5;
addx = (dx/len)*this.huntspeed;
addy = (dy/len)*this.huntspeed;
testx = x + 1.5;
testy = y + 2;
if (!onwall(testx+addx,testy+addy)) {
// Do a step
x += addx;
y += addy;
} else if (!onwall(testx+addx,testy)) x += addx;
else if (!onwall(testx,testy+addy)) y += addy;
} else {
this.mode = 0; // WALKING
this.walkmode = 1; // RANDOM
this.runcounter = int(random(10,40));
setcharani idle,;
dir = (dir+2)%4;
message;
}
timeout = 0.05;
}

// Hurting stuff
if (wa**** && this.mode!=1 && hearts>0) {
dx = x-playerx;
dy = y-playery;
len = (dx*dx+dy*dy)^0.5;
hurtdx = dx/len;
hurtdy = dy/len;
setcharani hurt,;
hideimg 1;
hearts -= playerswordpower/2;
}
if ((exploded || waspelt || wasshot) &&
this.mode!=1 && hearts>0 && isleader) {
hurtdx = -vecx(dir)*0.2;
hurtdy = -vecy(dir)*0.2;
setcharani hurt,;
if (peltwithsign || peltwithvase || peltwithstone || peltwithnpc) hearts -= 1;
else if (peltwithblackstone) hearts -= 1.5;
else hearts -= 0.5;
}
if ((hurtdx!=0 || hurtdy!=0) && isleader && this.mode!=4) {
this.hurtdx = hurtdx;
this.hurtdy = hurtdy;
hurtdx = 0;
hurtdy = 0;
if (hearts<=0) {
this.mode = 4; // DYING
message;
setcharani dead,;
timeout = 1.2;
} else {
this.mode = 1; // HURTED
this.runcounter = 20;
setcharani hurt,;
timeout = 0.05;
}
}
if (timeout && this.mode==1) { // HURTED
this.runcounter--;
if (this.runcounter>10) {
testx = x + 1.5 + this.hurtdx*2;
testy = y + 2 + this.hurtdy*2;
if (!onwall(testx,testy)) {
x += this.hurtdx;
y += this.hurtdy;
}
}
if (this.runcounter<=0) {
if (swordpower>0) this.mode = 2; // HUNTING
else this.mode = 0; // WALKING
this.runcounter = 100;
setcharani idle,;
}
timeout = 0.05;
}
if (timeout && this.mode==5) { // RESPAWN
this.mode = 0;
this.runcounter = int(random(10,40));
timeout = 0.05;
hearts = 3;
setcharani idle,;
}
if (timeout && this.mode==4) { // DYING
i = random(0,100);
if (i<10) lay greenrupee;
else if (i<15) lay bluerupee;
else if (i<30) lay heart;
this.mode = 5; // RESPAWN
timeout = 5;
}

Reply With Quote
  #4  
Old 09-26-2005, 02:40 AM
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
Quote:
NPC Code:

putexplosion2 3,4,newx2-.75,newy2-.75;
hideimg 400;
hitobjects 2,mousex,mousey;
hitobjects 2,mousex-.25,mousey-.25;
hitobjects 2,mousex+.25,mousey-.25;
hitobjects 2,mousex-.25,mousey+.25;
hideimg 300;
timeout=.05;
replaceani idle,idle;
setani idle,;
enabledefmovement;
hideimg 302;
sleep 3;
hideimg 301;
}

maybe because that portion of your script is not inside an event block?

EDIT: oh you fixed it, nvm. it seems that you're using
Quote:
NPC Code:

strequals(#w,Lightning 2)

in the portion that shoots the lightning as opposed to the "isweapon"s you used in the other portions (i'm assuming the name of this wepaon is "Lightning 2" of course it doesn't have to be). Are you sure the weapon name is correct? Are you doing this offline or online?
__________________
Reply With Quote
  #5  
Old 09-26-2005, 02:51 AM
Torankusu_2002 Torankusu_2002 is offline
'been round.
Torankusu_2002's Avatar
Join Date: Nov 2001
Posts: 1,246
Torankusu_2002 is on a distinguished road
I changed it around and organized it better.

Offline it works fine, but online it doesn't put an explosion.
__________________
torankusu's
Reply With Quote
  #6  
Old 09-26-2005, 09:15 AM
Hydrel Hydrel is offline
Registered User
Join Date: Sep 2005
Posts: 1
Hydrel is on a distinguished road
Click here for free enlightenment!
Reply With Quote
  #7  
Old 09-26-2005, 08:59 PM
excaliber7388 excaliber7388 is offline
Banned
excaliber7388's Avatar
Join Date: Jul 2005
Location: US
Posts: 5,229
excaliber7388 can only hope to improve
Send a message via AIM to excaliber7388
okay okay, not the best formatting, but you can still read it easily XD this really bugs me though, I can't find the connection between the 2 NPCs
Reply With Quote
  #8  
Old 09-26-2005, 09:27 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 excaliber7388
okay okay, not the best formatting, but you can still read it easily XD this really bugs me though, I can't find the connection between the 2 NPCs
No, it's not very easily read.

Seriously, preserving a good format will make it easier for you to find bugs and to work with your code at a later date.

Do something about that, and then continue.
__________________
Skyld
Reply With Quote
  #9  
Old 09-26-2005, 11:43 PM
Torankusu_2002 Torankusu_2002 is offline
'been round.
Torankusu_2002's Avatar
Join Date: Nov 2001
Posts: 1,246
Torankusu_2002 is on a distinguished road
formatted/compacted better:

NPC Code:

//NPC made By Excaliber
//edited by Torankusu

if (playerenters){
playermp +=100;
toweapons Lightning 2;
}


//#CLIENTSIDE

//Checking to see if the weapon should be fired when the
//left mouse button is clicked down or not.

if(isweapon){
if (strequals(#w,Lightning 2)){
if (weaponfired && playermp>4 || mousedown && playermp>4){
set shooting;
timeout=.05;
}
}
}

if (timeout){
if (shooting){
disabledefmovement;
showimg 300,dr-crosshairs.png,mousex-.5,mousey-.35;
}
if (shooting){
if (keypressed){
if (strequals(#p(1),a)){
unset shooting;
hideimg 300;
enabledefmovement;
setani idle,;
}
}
}
timeout=.05;
}


if (mousedown && leftmousebutton && shooting){
unset shooting;
playermp=playermp-5; //remember to do this serverside.
newx2 = mousex;
newy2 = mousey;
putexplosion2 3,4,mousex-.75,mousey-.75;

for(i=1;i<100;i=i+25){
changeimgpart 400,0,0,35,i;
sleep .05;
}
hideimg 400;

hideimg 300;
setani idle,;

enabledefmovement;
hideimg 302;
sleep 3;
hideimg 301;
}



It won't shoot lightning online, but it works fine offline.
__________________
torankusu's
Reply With Quote
  #10  
Old 09-27-2005, 01:03 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
'toweapons' is bad with an NPC server...

Make sure your MP is set at 99 and try.

Also:
PHP Code:
if(isweapon){
  if (
strequals(#w,Lightning 2)){
    
if (weaponfired && playermp>|| mousedown && playermp>4){
      
set shooting;
      
timeout=.05;
    }
  }

Having 'isweapon' and 'strequals(#w,Lightning2)' is redundant.

I would try instead:
PHP Code:
if (weaponfired || (mousedown && isweapon)) {
  if (
playermp 4) {
    
//stuff
  
}

I would also test this weapon on a level that is not on a gmap, as putexplosion2 coordinates often have to be adjusted if you are on a gmap.
__________________
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
  #11  
Old 09-27-2005, 01:14 AM
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
replace toweapons with
NPC Code:

addweapon Lightning 2;


leave it serverside though.
__________________
Reply With Quote
  #12  
Old 09-27-2005, 01:19 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 ZeLpH_MyStiK
replace toweapons with
NPC Code:

addweapon Lightning 2;


leave it serverside though.
I think he left that 'toweapons' part from when the weapon was tested in a level.

I'm assuming that the weapon name is 'Lightning 2'...

If that is the case, he can eliminate the serverside part entirely (but just make sure he has playermp set to 99 via editing attributes).
__________________
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
  #13  
Old 09-27-2005, 08:45 AM
Torankusu_2002 Torankusu_2002 is offline
'been round.
Torankusu_2002's Avatar
Join Date: Nov 2001
Posts: 1,246
Torankusu_2002 is on a distinguished road
keep in mind 2 things.

Everything you guys just posted, I already knew. They were for offline purposes.

Not to mention, I didn't script this NPC, Excaliber did, all I did was take what he had and formatted it better, and tried to condense it with redundant things (but I did miss taking out the strequals(#w,etc) part. Aside from that, everything you guys posted was of no help at all. The level is not on a gmap, it's just a regular level.
__________________
torankusu's
Reply With Quote
  #14  
Old 09-27-2005, 08:54 PM
excaliber7388 excaliber7388 is offline
Banned
excaliber7388's Avatar
Join Date: Jul 2005
Location: US
Posts: 5,229
excaliber7388 can only hope to improve
Send a message via AIM to excaliber7388
it is a weapon in fact, and is is used online, however, i out some stuff in it, so you could see how it works offline, but not online. anyway, what you guys said, not the problem, it's gotta be something else, but I can't figure it out
Reply With Quote
  #15  
Old 09-28-2005, 03:22 AM
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
maybe there are conflicting variables between the npc and the baddy, i doubt this is the problem, but it's worth a try.
change the variables in the npc to this. vars.
and try changing "shooting" to something else like "lightningshoot" or something
it's worth a try =)
__________________
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 04:30 AM.


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