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-04-2005, 12:08 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
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;
}

Reply With Quote
  #2  
Old 09-04-2005, 12:41 AM
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
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.
Reply With Quote
  #3  
Old 09-04-2005, 02:08 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
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
Reply With Quote
  #4  
Old 09-04-2005, 08:10 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
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.
__________________
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
  #5  
Old 09-04-2005, 09:34 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
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. i've avoided it for so long how would I make this work?
Reply With Quote
  #6  
Old 09-10-2005, 04:41 AM
konidias konidias is offline
Old Bee
konidias's Avatar
Join Date: Jul 2001
Location: Orlando, FL
Posts: 7,222
konidias will become famous soon enough
Send a message via AIM to konidias
*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.
__________________

Put this image in your sig if you support Bomy Island! (g2k1 revision)
play bomberman while you wait!


Reply With Quote
  #7  
Old 09-10-2005, 05:23 AM
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 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.

The rest of your advice was good.
Reply With Quote
  #8  
Old 09-10-2005, 06:21 AM
calani calani is offline
Scriptess
calani's Avatar
Join Date: Aug 2003
Location: asmgarden.gmap
Posts: 606
calani is on a distinguished road
Send a message via AIM to calani
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 )
__________________
Reply With Quote
  #9  
Old 09-12-2005, 03:05 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
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
}

Reply With Quote
  #10  
Old 09-12-2005, 09:14 AM
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
NPC Code:
if(this.mode=4){

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



Second, put those checks inside an event block.
__________________
Skyld
Reply With Quote
  #11  
Old 09-12-2005, 11:40 AM
Sildae Sildae is offline
Elven sorceress!
Sildae's Avatar
Join Date: Dec 2001
Location: Lothlòrien
Posts: 159
Sildae is on a distinguished road
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? ****

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.
__________________
"The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore all progress depends on the unreasonable man."
-- George Bernard Shaw
Reply With Quote
  #12  
Old 09-12-2005, 06:00 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 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?
__________________
Skyld
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 12:31 AM.


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