Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Need Help - Detection (https://forums.graalonline.com/forums/showthread.php?t=50725)

KaneTrinidy 01-30-2004 11:12 PM

Need Help - Detection
 
I was wondering if there was anyway to detect if a moving NPC touches a player, or is a certain distance from a player so that the NPC can carry out something.
ie.
A moving NPC touches the player and their health is reduced.

If anyone could guide me towards how you would go about doing this it would be appreciated. :)

ZeLpH_MyStiK 01-30-2004 11:40 PM

if (playertouchsme) ?
or
loop through every player using distance formula to check if they're within a distance.
Distance formula: D=((x1-x2)^2 + (y1-y2)^2)^(1/2)
where (x1,y1),(x2,y2) are the coordinates of the two objects (this case npc and player)

-Ramirez- 01-31-2004 01:54 AM

if (playertouchsme) only triggers when the obvious happens: the player touches the NPC, not the other way around. To do what you're wanting, you would need to have a timeout constantly check the distance of the player from the NPC, as was already mentioned. However, use 0.5 at the end of that formula rather than (1/2). There's no need for extra calculation there.

Python523 01-31-2004 02:06 AM

Quote:

Originally posted by -Ramirez-
if (playertouchsme) only triggers when the obvious happens: the player touches the NPC, not the other way around. To do what you're wanting, you would need to have a timeout constantly check the distance of the player from the NPC, as was already mentioned. However, use 0.5 at the end of that formula rather than (1/2). There's no need for extra calculation there.
o_O Why can't you just use testplayer to see if it is close enough to touch the npc

ZeLpH_MyStiK 01-31-2004 02:40 AM

Quote:

Originally posted by Python523


o_O Why can't you just use testplayer to see if it is close enough to touch the npc

What does getting the index of a player...o wait you mean like
testplayer(x,y)? where x and y are the coordinates of the npc?

Admins 01-31-2004 02:47 AM

Serverside scripting functions:

NPC Code:

pindex = getnearestplayer(x,y)
with (players[pindex]) {
distance = ((x-playerx)^2+(y-playery)^2)^0.5;
if (distance<2)
// do stuff
}



or

NPC Code:

pindexes = getnearestplayers(x,y,playerhearts>=3)
for (i=0; i<arraylen(pindexes); i++) {
with (players[pindexes[i]]) {
distance = ((x-playerx)^2+(y-playery)^2)^0.5;
if (distance<2)
// do stuff
}
}


adam 01-31-2004 02:49 AM

Hehe, I didn't know there was a getnearestplayers ;-)
cool

ZeLpH_MyStiK 01-31-2004 04:42 AM

Quote:

Originally posted by Stefan
Serverside scripting functions:

NPC Code:

pindex = getnearestplayer(x,y)
with (players[pindex]) {
distance = ((x-playerx)^2+(y-playery)^2)^0.5;
if (distance<2)
// do stuff
}



or

NPC Code:

pindexes = getnearestplayers(x,y,playerhearts>=3)
for (i=0; i<arraylen(pindexes); i++) {
with (players[pindexes[i]]) {
distance = ((x-playerx)^2+(y-playery)^2)^0.5;
if (distance<2)
// do stuff
}
}


Why isnt there a ; at the end of the getnearestplayers?

Python523 01-31-2004 05:03 AM

Quote:

Originally posted by ZeLpH_MyStiK

Why isnt there a ; at the end of the getnearestplayers?

a typo

ZeLpH_MyStiK 01-31-2004 06:32 AM

Quote:

Originally posted by Python523


a typo

OMG Stefan, a type?!? lol j/k this proves that everyone makes mistakes ;)

-Ramirez- 01-31-2004 06:56 AM

Quote:

Originally posted by Python523
o_O Why can't you just use testplayer to see if it is close enough to touch the npc
Same concept. It's still going to have to be used in a timeout, or in a movementfinished block.

Nappa 01-31-2004 07:25 AM

I thought we weren't allowed to post full scripts ? Bad stefan. Bad boy.

Kristi 01-31-2004 07:39 AM

Quote:

Originally posted by Python523


a typo

He did it twice though... =o

Dach 01-31-2004 09:00 AM

Quote:

Originally posted by Kristi


He did it twice though... =o

Shh! he will smite thee for unmasking his fallous!!
yes I made that word up, it's a very good word if I may add

*gets back to updating commands.rtf* ... *wonders if anyone cares about the updated commands.rtf*

R0bin 01-31-2004 05:23 PM

Oh dear god i do.

Add getnearestplayers, command wench.


All times are GMT +2. The time now is 09:52 AM.

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