PDA

View Full Version : [K1] PC within a certain range of NPC script.


Stream
01-25-2008, 05:56 PM
First I apologise for the dodgy title, I couldn't think of what to call this.

What I'm wondering is - Is there anyway of having a conditional in a script that checks to see if the PC is within a certain range of an NPC? I have this script so far which works fine but I'd like it to only work if the PC is within say 5 meters of the NPC;


void main() {

object oNPC = GetObjectByTag("kas25_secura");

if ((GetPartyMemberByIndex(1) == OBJECT_INVALID) && (GetPartyMemberByIndex(2) == OBJECT_INVALID) && (GetGlobalBoolean("test_test")==0))
{
AssignCommand(oNPC, ActionStartConversation(GetFirstPC(), "", 0, 0, 0, "", "", "", "", "", "", 0, 0xFFFFFFFF, 0xFFFFFFFF, 0));
SetGlobalBoolean("test_test",1);
}
else {

if ((GetGlobalBoolean("test_test")==0))
ExecuteScript("Deadly_Exit_1", OBJECT_SELF, 1002);
}
}

I'm not sure if this is possible or not, I hope it is do I'll have to rethink how to implement the script.

Kind Regards
--Strean

lactose_
01-25-2008, 11:47 PM
Try this:
void main() {

object oNPC = GetObjectByTag("kas25_secura");

if ((GetPartyMemberByIndex(1) == OBJECT_INVALID) && (GetPartyMemberByIndex(2) == OBJECT_INVALID) && (GetGlobalBoolean("test_test")==0)) && (GetDistanceBetween(oNPC, OBJECT_SELF) <= 5.0)
{
AssignCommand(oNPC, ActionStartConversation(GetFirstPC(), "", 0, 0, 0, "", "", "", "", "", "", 0, 0xFFFFFFFF, 0xFFFFFFFF, 0));
SetGlobalBoolean("test_test",1);
}
else {

if ((GetGlobalBoolean("test_test")==0))
ExecuteScript("Deadly_Exit_1", OBJECT_SELF, 1002);
}
}

Stream
01-26-2008, 05:12 AM
Yeah that's got it working right now, thanks very much for your help

--Stream