From b1ebd37bf9230d7580cd11f45a16bd8dc5c65a34 Mon Sep 17 00:00:00 2001 From: Christopher Date: Sun, 1 Aug 2021 14:41:28 +0000 Subject: [PATCH] =?UTF-8?q?=E2=80=9EChris.MultiNPC.lsl=E2=80=9C=20=C3=A4nd?= =?UTF-8?q?ern?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Chris.MultiNPC.lsl | 76 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 73 insertions(+), 3 deletions(-) diff --git a/Chris.MultiNPC.lsl b/Chris.MultiNPC.lsl index 2d0e600..a05564d 100644 --- a/Chris.MultiNPC.lsl +++ b/Chris.MultiNPC.lsl @@ -25,7 +25,7 @@ readNPCPathNC(string ncName) m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + npcslot + ".path", nc); m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + npcslot + ".ncname", ncName); } - + integer getNextFreeNPCSlot() { integer currentNPCSlot = 0; @@ -151,6 +151,34 @@ doNextScriptStep() m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + currentNPCSlot + ".state", ""); } + + if(currentState == "path") + { + //llOwnerSay("raw: " + getDataEntryFromDataList(m_npcdata, "npc." + currentNPCSlot + ".walkPath")); + key targetKey = llList2Key(llCSV2List(getDataEntryFromDataList(m_npcdata, "npc." + currentNPCSlot + ".walkPath")), 0); + vector targetPosition = llList2Vector(llGetObjectDetails(targetKey, [OBJECT_POS]), 0); + + if(llGetListLength(currentNPCDataList) == 0) + hardReset("target '"+targetKey+"' not found"); + + if(llVecDist(currentNPCPosition, targetPosition) <= 1) + { + list newPathList = llDeleteSubList(llCSV2List(getDataEntryFromDataList(m_npcdata, "npc." + currentNPCSlot + ".walkPath")), 0, 0); + + if(llGetListLength(newPathList) == 0) + { + m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + currentNPCSlot + ".state", ""); + m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + currentNPCSlot + ".walkPath", ""); + }else{ + m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + currentNPCSlot + ".walkPath", llList2CSV(newPathList)); + targetKey = llList2Key(llCSV2List(getDataEntryFromDataList(m_npcdata, "npc." + currentNPCSlot + ".walkPath")), 0); + targetPosition = llList2Vector(llGetObjectDetails(targetKey, [OBJECT_POS]), 0); + osNpcMoveToTarget(currentNPCKey, targetPosition, OS_NPC_NO_FLY); + } + } + + continue; + } if(currentState == "walk") { @@ -168,7 +196,7 @@ doNextScriptStep() hardReset("npc stuck"); }else{ currentStuck = 0; - } + } m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + currentNPCSlot + ".lastPos", currentNPCPosition); m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + currentNPCSlot + ".stuckCounter", currentStuck); @@ -233,9 +261,13 @@ doNextScriptStep() if(!script_walk(currentNPCSlot, currentNPCKey, replaceVars(currentNPCSlot, lineCommandData))) llSay(0, "Script execution in '" + llList2String(lineCommandData, 0) + "' in nc '"+ currentncname +"' on line '" + currentLine + "' failed."); break; + case "path": + if(!script_path(currentNPCSlot, currentNPCKey, replaceVars(currentNPCSlot, lineCommandData))) + llSay(0, "Script execution in '" + llList2String(lineCommandData, 0) + "' in nc '"+ currentncname +"' on line '" + currentLine + "' failed."); + break; case "fly": if(!script_fly(currentNPCSlot, currentNPCKey, replaceVars(currentNPCSlot, lineCommandData))) - llSay(0, "Script execution in '" + llList2String(lineCommandData, 0) + "' in nc '"+ currentncname +"' on line '" + currentLine + "' failed."); + llSay(0, "Script execution in '" + llList2String(lineCommandData, 0) + "' in nc '"+ currentncname +"' on line '" + currentLine + "' failed."); break; case "include": if(!script_include(currentNPCSlot, currentNPCKey, replaceVars(currentNPCSlot, lineCommandData))) @@ -342,6 +374,44 @@ integer script_wait(integer slot, key npc, list command) return TRUE; } +integer script_path(integer slot, key npc, list command) +{ + list objects = osGetSearchableObjectPartList(llList2String(command, 1)); + if(llGetListLength(objects) == 0) + { + llSay(0, "Cant find the path start '" + llList2String(command, 1) + "'."); + return FALSE; + } + + objects = osGetSearchableObjectPartList(llList2String(command, 2)); + if(llGetListLength(objects) == 0) + { + llSay(0, "Cant find the path target '" + llList2String(command, 1) + "'."); + return FALSE; + } + + list nodes = []; + + try + { + nodes = osGetNodeListToTarget(llList2Key(osGetSearchableObjectPartList(llList2String(command, 1)), 0), llList2Key(osGetSearchableObjectPartList(llList2String(command, 2)), 0)); + } + catch(scriptexception ex) + { + llSay(0, "Cant find the path to target '" + llList2String(command, 1) + "'."); + return FALSE; + } + + list targetDataList = llGetObjectDetails(llList2Key(osGetSearchableObjectPartList(llList2String(command, 1)), 0), [OBJECT_POS]); + vector targetPosition = llList2Vector(targetDataList, 0); + osNpcMoveToTarget(npc, targetPosition, OS_NPC_NO_FLY); + + m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + slot + ".state", "path"); + m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + slot + ".walkPath", llList2CSV(nodes)); + + return TRUE; +} + integer script_walk(integer slot, key npc, list command) { vector targetPosition = <0, 0, 0>;