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 01-30-2004, 11:12 PM
KaneTrinidy KaneTrinidy is offline
Registered User
Join Date: Oct 2003
Posts: 1
KaneTrinidy is on a distinguished road
Question 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.
Reply With Quote
  #2  
Old 01-30-2004, 11:40 PM
ZeLpH_MyStiK ZeLpH_MyStiK is offline
Scripter
ZeLpH_MyStiK's Avatar
Join Date: May 2003
Location: NYC
Posts: 553
ZeLpH_MyStiK is on a distinguished road
Send a message via MSN to ZeLpH_MyStiK Send a message via Yahoo to ZeLpH_MyStiK
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)
__________________
Reply With Quote
  #3  
Old 01-31-2004, 01:54 AM
-Ramirez- -Ramirez- is offline
Registered User
Join Date: Jun 2002
Location: USA, Ohio
Posts: 729
-Ramirez- has a spectacular aura about-Ramirez- has a spectacular aura about
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.
__________________
Kat
Reply With Quote
  #4  
Old 01-31-2004, 02:06 AM
Python523 Python523 is offline
Banned
Join Date: Aug 2001
Location: Illinois
Posts: 3,498
Python523 is on a distinguished road
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
Reply With Quote
  #5  
Old 01-31-2004, 02:40 AM
ZeLpH_MyStiK ZeLpH_MyStiK is offline
Scripter
ZeLpH_MyStiK's Avatar
Join Date: May 2003
Location: NYC
Posts: 553
ZeLpH_MyStiK is on a distinguished road
Send a message via MSN to ZeLpH_MyStiK Send a message via Yahoo to ZeLpH_MyStiK
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?
__________________
Reply With Quote
  #6  
Old 01-31-2004, 02:47 AM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
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
}
}

Reply With Quote
  #7  
Old 01-31-2004, 02:49 AM
adam adam is offline
http://wiki.graal.us/
adam's Avatar
Join Date: Nov 2001
Posts: 2,247
adam has a spectacular aura aboutadam has a spectacular aura about
Send a message via AIM to adam
Hehe, I didn't know there was a getnearestplayers ;-)
cool
__________________
Rogue Shadow (TCN)(NAT)(Global Development Team)

For development help, contact the patrons of the #graaldt irc channel below, I am usually there.
Click Here to Join IRC Chat Now! -- irc.freenode.net Channel: #graaldt
Quote:
<Dustyshouri> no, RogueShadow is always talking about scripts lol
<Dustyshouri> in fact, he pretty much brought Graal back as a topic single-handedly
Reply With Quote
  #8  
Old 01-31-2004, 04:42 AM
ZeLpH_MyStiK ZeLpH_MyStiK is offline
Scripter
ZeLpH_MyStiK's Avatar
Join Date: May 2003
Location: NYC
Posts: 553
ZeLpH_MyStiK is on a distinguished road
Send a message via MSN to ZeLpH_MyStiK Send a message via Yahoo to ZeLpH_MyStiK
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?
__________________
Reply With Quote
  #9  
Old 01-31-2004, 05:03 AM
Python523 Python523 is offline
Banned
Join Date: Aug 2001
Location: Illinois
Posts: 3,498
Python523 is on a distinguished road
Quote:
Originally posted by ZeLpH_MyStiK

Why isnt there a ; at the end of the getnearestplayers?
a typo
Reply With Quote
  #10  
Old 01-31-2004, 06:32 AM
ZeLpH_MyStiK ZeLpH_MyStiK is offline
Scripter
ZeLpH_MyStiK's Avatar
Join Date: May 2003
Location: NYC
Posts: 553
ZeLpH_MyStiK is on a distinguished road
Send a message via MSN to ZeLpH_MyStiK Send a message via Yahoo to ZeLpH_MyStiK
Quote:
Originally posted by Python523


a typo
OMG Stefan, a type?!? lol j/k this proves that everyone makes mistakes
__________________
Reply With Quote
  #11  
Old 01-31-2004, 06:56 AM
-Ramirez- -Ramirez- is offline
Registered User
Join Date: Jun 2002
Location: USA, Ohio
Posts: 729
-Ramirez- has a spectacular aura about-Ramirez- has a spectacular aura about
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.
__________________
Kat
Reply With Quote
  #12  
Old 01-31-2004, 07:25 AM
Nappa Nappa is offline
The Great Nappa
Nappa's Avatar
Join Date: Sep 2003
Location: Florida
Posts: 1,911
Nappa is on a distinguished road
Send a message via AIM to Nappa
I thought we weren't allowed to post full scripts ? Bad stefan. Bad boy.
__________________
Reply With Quote
  #13  
Old 01-31-2004, 07:39 AM
Kristi Kristi is offline
Bowie's Deciple
Kristi's Avatar
Join Date: Dec 2003
Location: Boston, MA
Posts: 748
Kristi has a spectacular aura aboutKristi has a spectacular aura about
Send a message via AIM to Kristi Send a message via MSN to Kristi
Quote:
Originally posted by Python523


a typo
He did it twice though... =o
__________________
Reply With Quote
  #14  
Old 01-31-2004, 09:00 AM
Dach Dach is offline
call me Chad, it's cooler
Dach's Avatar
Join Date: Aug 2002
Posts: 1,899
Dach is on a distinguished road
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*
__________________
Scripting Documents:Old Script Documentation-Movement Tutorial
Reply With Quote
  #15  
Old 01-31-2004, 05:23 PM
R0bin R0bin is offline
Banned
R0bin's Avatar
Join Date: Oct 2002
Location: Wales, UK
Posts: 828
R0bin is on a distinguished road
Send a message via AIM to R0bin
Oh dear god i do.

Add getnearestplayers, command wench.
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 10:02 AM.


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