Graal Forums

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

excaliber7388 09-04-2005 12:08 AM

Bad baddies
 
Im having trouble with my baddie, it's supposed to warp you after he dies, whats wrong?
NPC Code:
if (actionserverside) {
if (strequals(#p(0),warp)) {
setlevel2 whule7_darkrival2.nw,31,59;
}
}if (timeout && this.mode==4) {
setlevel2 whule7_darkrival2.nw,29.5,57;
}if(playeronline){if (this.mode==4) {
setlevel2 whule7_darkrival2.nw,29.5,57;
}}
//#CLIENTSIDE
// Graal2002 NPC by Stefan Knorr,
//i know, this is a premade baddie
//just testing ^_^
// Initialize the attributes
showcharacter;
setcharprop #3,head27.png;
setcharprop #8, Bodysage2.mng;
setcharprop #C0,black;
setcharprop #C1,black;
setcharprop #C2,gray;
setcharprop #C3,gray;
setcharprop #C4,black;
setcharprop #n,Dark Mage;
setcharprop #2,darkman-shield.gif;
shieldpower = 1;
dir = 2;
swordpower = 2;
hurtdx = 0;
hurtdy = 0;
hearts = 15;
}
if (playerenters || wasthrown) {
// Initialize the this. variables
message;
this.huntspeed = 0.8;
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 Mwha ha ha;
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==4) { timeout=1;triggeraction 0,0,serverside,warp;
}


Lance 09-04-2005 12:41 AM

Some things to keep in mind:

1) Triggeractions beginning with 'server' are reserved.

The triggeraction 'serverside' is reserved for weapon NPCS.
Triggeractions in the form of 'server(anythingelse)' are reserved for the Control-NPC.

2) This NPC is moving around clientside but it is still in the same place serverside. You will need to rectify this somehow if you want the trigger to go through.

excaliber7388 09-04-2005 02:08 AM

so it would be just triggeraction 0,0,warp; and how would i make the comp move on both serverside and clientside, without coping the scrip to both sides? btw, Lance, thanks :D

napo_p2p 09-04-2005 08:10 AM

If you can get the script to move serverside, you do not need to make it move clientside as well.

If you do not wish to make a serverside baddy, it is possible to make this baddy trigger another NPC in the level that is at a fixed x and y.

excaliber7388 09-04-2005 09:34 PM

I can't get it to work the way it is, but the script doesn't move clientside. I'm also never sure how to work triggeraction. For weapons it's easy, but i never did it for something like this. x_x i've avoided it for so long :\ how would I make this work?

konidias 09-10-2005 04:41 AM

*sigh* This script is a mess. Why do you have multiple timeout events? Also, you can't just setlevel2 like that serverside... You aren't specifying a player. How is the npc supposed to know who to warp? It would probably be good to specify the player account to warp in the triggeraction parameter, and then on serverside use getplayer.

edit: and I'm almost positive that timeout does not transcend clientside to serverside... Meaning you can't have a clientside timeout and then do an "if (timeout)" serverside.

Lance 09-10-2005 05:23 AM

Quote:

Originally Posted by konidias
It would probably be good to specify the player account to warp in the triggeraction parameter, and then on serverside use getplayer.

Please, no. This is not secure. :frown:

The rest of your advice was good.

calani 09-10-2005 06:21 AM

Quote:

Originally Posted by Old Bee
edit: and I'm almost positive that timeout does not transcend clientside to serverside... Meaning you can't have a clientside timeout and then do an "if (timeout)" serverside

You are correct.
The only thing that 'transcends,' as you put it, the //#CLIENTSIDE bounardy is triggers ( onCreated too, if you want to get technical )

excaliber7388 09-12-2005 03:05 AM

would a flag addition work? like:
NPC Code:
if(killed&&this.mode=4){
unset killed;
script for warp
}
//#CLIENTSIDE
if(this.mode=4){
set killed
}


Skyld 09-12-2005 09:14 AM

Quote:

Originally Posted by excaliber7388
NPC Code:
if(this.mode=4){


Use == while comparing things.
NPC Code:
if (this.mode == 4) {



Second, put those checks inside an event block.

Sildae 09-12-2005 11:40 AM

Quote:

Originally Posted by excaliber7388
would a flag addition work? like: *snip*

Nope.
  1. flags belong to a player's account, and not to the current NPC. The serverside part would not know which player to check. Also, this would not work for more than one NPC of this type, even if it was not broken for other reasons.
  2. the only type of flags that you can set on the clientside that the server will get told about are client. flags. You cannot set regular flags.
  3. Toplevel if-clauses should exclusively check for events. I suppose this is just mock code, but still, when exactly are you going to check whether the flag is set? In a tight timeout loop? **** :mad:

Move a lot more of your logic to the serverside. The clientside of a regular baddy has almost nothing to do. Chances are you will not be able to use the premade NPC baddies for this, though.



Other than that, I am laughing too hard at if (washit) being censored.

Skyld 09-12-2005 06:00 PM

Quote:

Originally Posted by Sildae
flags belong to a player's account, and not to the current NPC.

I fear that you have no idea as to what you are talking about.
Quote:

Originally Posted by Sildae
The serverside part would not know which player to check. Also, this would not work for more than one NPC of this type, even if it was not broken for other reasons.

What?


All times are GMT +2. The time now is 12:17 AM.

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