Graal Forums

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

excaliber7388 09-25-2005 09:43 PM

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


Skyld 09-25-2005 09:49 PM

Be more specific. What about it doesn't work around an npc baddy?

Also, please make your script readable.

excaliber7388 09-26-2005 02:37 AM

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


ZeLpH_MyStiK 09-26-2005 02:40 AM

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?

Torankusu_2002 09-26-2005 02:51 AM

I changed it around and organized it better.

Offline it works fine, but online it doesn't put an explosion.

Hydrel 09-26-2005 09:15 AM

Click here for free enlightenment!

excaliber7388 09-26-2005 08:59 PM

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 x_x

Skyld 09-26-2005 09:27 PM

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 x_x

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.

Torankusu_2002 09-26-2005 11:43 PM

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.

napo_p2p 09-27-2005 01:03 AM

'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.

ZeLpH_MyStiK 09-27-2005 01:14 AM

replace toweapons with
NPC Code:

addweapon Lightning 2;


leave it serverside though.

napo_p2p 09-27-2005 01:19 AM

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

Torankusu_2002 09-27-2005 08:45 AM

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.

excaliber7388 09-27-2005 08:54 PM

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 x_x

ZeLpH_MyStiK 09-28-2005 03:22 AM

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


All times are GMT +2. The time now is 12:47 PM.

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