Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Server (https://forums.graalonline.com/forums/forumdisplay.php?f=14)
-   -   Follow player (https://forums.graalonline.com/forums/showthread.php?t=2590)

Admins 05-11-2001 06:56 AM

Here an example for a class 'followers'.
First an NPC that joins that class:

NPC Code:

if (created) {
showcharacter;
}
if (playerchats) {
if (strequals(#c,follow)) {
setstring this.owner,#a;
followPlayer();
}
if (strequals(#c,stop)) {
setstring this.owner,;
stopingFollow();
}
}
function stopingFollow() {
setcharani idle,;
message STOP;
sleep 3;
message;
}
join followers;



And here the class file:

NPC Code:

function followPlayer() {
cannotwarp;
setarray this.followpos,0;
while (true) {
noowner = true;
with (getplayer(#s(this.owner))) {
noowner = false;
if (!strequals(#F,#L)) {
// Player leaved the level, so follow him
setarray this.followpos,0;
dir = playerdir;
warpto #F,playerx,playery;
} else {
//
// Follow the player
//
px = playerx;
py = playery;

// Add one step to the list if the player has moved
alen = arraylen(this.followpos);
if (alen<2 || this.followpos[alen-2]!=px || this.followpos[alen-1]!=py) {
setarray this.followpos,alen+2;
this.followpos[alen] = px;
this.followpos[alen+1] = py;
}
// Only save 4 steps, so delete one entry at the beginning
// if there are too many
if (arraylen(this.followpos)>4*2) {
for (i=0; i<4; i++) {
this.followpos[i*2] = this.followpos[(i+1)*2];
this.followpos[i*2+1] = this.followpos[(i+1)*2+1];
}
setarray this.followpos,4*2;
}

// Get the new position (oldest saved step)
nx = this.followpos[0];
ny = this.followpos[1];

// Setting direction
if (abs(nx-x)>abs(ny-y)) {
if (nx<x) dir = 1; else dir = 3;
} else if (abs(nx-x)<abs(ny-y)) {
if (ny<y) dir = 0; else dir = 2;
}
if (nx==px && ny==py) dir = playerdir;

// Setting animation
if (onwater(nx+1.5,ny+2))
this.animode = 2;
else if (x==nx && y==ny)
this.animode = 0;
else
this.animode = 1;
setAnimation();

// Applying the new position
x = nx;
y = ny;
}
}
if (noowner==true)
break;
sleep 0.1;
}
stopingFollow();
}
function stopingFollow() {
this.animode = 0;
setAnimation();
}
function setAnimation() {
if (startswith(bomy,#3(-1))) {
if (this.animode==0)
setcharani bomy_idle,;
else if (this.animode==1)
setcharani bomy_walk,;
else if (this.animode==2)
setcharani bomy_kick,;
} else {
if (this.animode==0)
setcharani idle,;
else if (this.animode==1)
setcharani walk,;
else if (this.animode==2)
setcharani swim,;
}
}



The follow script uses the array this.followpos
to remember the walking position of the
player. You can see that the NPC is overwriting
the function stopingFollow() to implement
its own code (saying 'STOP' for 3 seconds).
You can see that using the followers script
is very simple, you only need to set this.owner,
then call followPlayer()

If you have questions or improvements then
let me know

KJS 05-11-2001 08:55 AM

what does?
 
what does the function 'join' do?
you used it like this
join followers;
and I am just wondering if you could give me a small tatoral on how to use it and what it does

Admins 05-11-2001 08:27 PM

Yes classes are saved in text files, but
you need the npccontrol to change the
class script

KJS 05-11-2001 08:55 PM

so I am guessing
 
I am guessing it would be a good idea to put a system weapon inside of a txt file and join it. So then you dont have to have a function in the npc weapon to warp them to a level to get the new update of the system weapon?
am I correct?

kyle0654 05-11-2001 09:54 PM

Actually, if you just stored the system script as a server NPC with the name System-NPC I think you could use:

addweapon System-NPC;

And it should update every logon.


Question: Can NPCWs join a server script? Like for a bow, you have the local script with all the shooting stuff, but for a few global functions like possibly how arrows move you want to join a server script instead of having to write it in every single weapon that's a bow-type.

KJS 05-11-2001 10:11 PM

Quote:

Originally posted by kyle0654
[B]Actually, if you just stored the system script as a server NPC with the name System-NPC I think you could use:

addweapon System-NPC;

And it should update every logon.
well see the thing is, like that doesn't make the weapon invisable if I name it that. I am naming my weapon
-system
so it is invisable and no one can delete it.
and fyi it is 'toweapons <weapon name>' not addweapon

Admins 05-12-2001 02:35 AM

weapons are something different,
join is not possible yet for weapons

kyle0654 05-12-2001 06:10 AM

You could probably name the server npc -system too...not sure if the '-' would work. I was just giving an example for you to build off of though, I expected you to try at least to change the name. addweapon adds a script that's on the server as a weapon with the name of the NPC on the server.

As for joining with NPCWs, could that PLEASE be added soon?
Something like:
NPC Code:

if (created) {
join BowFunctions;
join ArrowProperties;
toweapons Mega-Bow;
}
// rest of weapon here


Not really a text file...those are kinda outta date...

Hawk 05-12-2001 06:55 AM

yes yes!

Immitat0r 05-14-2001 06:04 PM

(James205)

http://www.sonicunderground.net/shq/smilies/ninja.gif
http://dbadvanced.com/kurt.gif

Metal-Slug 06-26-2001 03:47 AM

can i use the top script wihtou using the bottom 1?

Metal-Slug 06-26-2001 11:08 PM

im not makinf a class, im trying to make and image follow a player, one image, not different angles and everything, just bleh

ArmadeusWarlock 06-28-2001 03:10 AM

Well
 
Im not exactly sure what you want that image to do, but since im not the greatest scripter, heres meh script!
if(playertouchsme){
followplayer;
}

I havent quite figured out how to make them follow you into different levels. I could do a really bugged up script that would works but it wont do anything spectacularly special.

Admins 06-30-2001 03:51 AM

Thats a client-side thing that is taken out in the
next Graal version

06-30-2001 04:07 AM

Stefan, I can't get weapons to add to your list. Since you said weapons can't be a class, should I make the NPC on NPC Control, thenm put the weapon script on Edit Script?

Otaku is confused.:confused:


All times are GMT +2. The time now is 07:26 AM.

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