If anyone can help with this it should complete my NPC Target button im trying to finish to move on to the rest of my project.
Script So Far ( I made some changes so I can have a Player and NPC Detection menus:
Main Script (The button or HUD Button):
integer PING_CHANNEL = -893397710;
string PING_QUERY_NPC = "querynpc";
string PING_RESPONSE_NPC = "responsenpc";
string PING_QUERY_PC = "querypc";
string PING_RESPONSE_PC = "responsepc";
float PING_TIMEOUT_SECONDS = 0.4;
integer MAX_TARGETS = 12;
integer DIALOG_CHANNEL = -893397711;
list NPC_MENU = ["NPC Target", "PC Target"]; // the main menu
list targetKeys = [];
list targetNames = [];
integer nTargets = 0;
giveDialog()
{
list choices = [];
integer i;
for (i = 0; i < nTargets; ++i)
{
string choice = (string)(i+1)+" "+llList2String(targetNames, i);
choices = (choices=[])+choices+choice;
}
llDialog(
llGetOwner(),
"Choose a target",
choices,
DIALOG_CHANNEL
);
}
default
{
state_entry()
{
DIALOG_CHANNEL = (integer)llFrand(2147483647);
llListen(PING_CHANNEL, "", NULL_KEY, PING_RESPONSE_NPC);
llListen(PING_CHANNEL, "", NULL_KEY, PING_RESPONSE_PC);
llListen(DIALOG_CHANNEL, "", llGetOwner(), ""

}
touch_start(integer total_number)
{
llDialog(llDetectedKey(0), "What do you want to do?", NPC_MENU, DIALOG_CHANNEL); // present dialog on click
}
timer()
{
llSetTimerEvent(0.0);
giveDialog();
}
listen(integer channel, string name, key id, string message)
{
if (channel == PING_CHANNEL && message == PING_RESPONSE_NPC)
{
if (nTargets < MAX_TARGETS &&
llListFindList(targetKeys, [ id ]) < 0)
{
targetKeys = (targetKeys=[])+targetKeys+[ id ];
targetNames = (targetNames=[])+targetNames+[ name ];
++nTargets;
if (nTargets >= MAX_TARGETS)
{
llSetTimerEvent(0.0);
giveDialog();
}
}
}
else if (channel == PING_CHANNEL && message == PING_RESPONSE_PC)
{
if (nTargets < MAX_TARGETS &&
llListFindList(targetKeys, [ id ]) < 0)
{
targetKeys = (targetKeys=[])+targetKeys+[ id ];
targetNames = (targetNames=[])+targetNames+[ name ];
++nTargets;
if (nTargets >= MAX_TARGETS)
{
llSetTimerEvent(0.0);
giveDialog();
}
}
}
if (channel == DIALOG_CHANNEL && message == "NPC Target"

{
llSay(PING_CHANNEL, PING_QUERY_NPC);
llSetTimerEvent(PING_TIMEOUT_SECONDS);
}
else if (channel == DIALOG_CHANNEL && message == "PC Target"

{
llSay(PING_CHANNEL, PING_QUERY_PC);
llSetTimerEvent(PING_TIMEOUT_SECONDS);
}
else if (channel == DIALOG_CHANNEL && id == llGetOwner())
{
string spacePos = llGetSubString(" ", 0, -1);
integer index = (integer)(llGetSubString(message, 0, (integer)spacePos-1))-1;
key targetKey = llList2Key(targetKeys, index);
key targetName = llList2Key(targetNames, index);
llSay(0, "Chosen target: "+ (string)targetName +" "+ (string)targetKey);
llResetScript();
}
}
changed(integer change)
{
if (change & CHANGED_OWNER)
{
llResetScript();
}
}
}
The NPC Script:
integer PING_CHANNEL = -893397710;
string PING_QUERY_NPC = "querynpc";
string PING_RESPONSE_NPC = "responsenpc";
default
{
state_entry()
{
llListen(PING_CHANNEL, "", "", PING_QUERY_NPC);
}
listen(integer channel, string name, key id, string message)
{
llSay(PING_CHANNEL, PING_RESPONSE_NPC);
}
}
Thank you very much,
-Cherry Hotaling