diff --git a/Chris.MultiNPC.lsl b/Chris.MultiNPC.lsl index f2e1d52..6ff3d4a 100644 --- a/Chris.MultiNPC.lsl +++ b/Chris.MultiNPC.lsl @@ -14,18 +14,37 @@ yoptions; // Read the readme at https://clatza.dev/Christopher/OpenSim.Script.Chris.MultiNPC/src/branch/master/README.md //=================== -list m_npcdata = []; +list m_npcdata = []; +integer m_lastTimeCheck = 0; default { state_entry() { + m_lastTimeCheck = llGetUnixTime(); checkOSPermissions(); readAllNPCPathNC(); - state running; - } + state waitingForPlayers; + } } +state waitingForPlayers +{ + state_entry() + { + llSetTimerEvent(0.1); + } + + timer() + { + llSetTimerEvent(2); + m_lastTimeCheck = llGetUnixTime(); + llOwnerSay(getRealAgentCount()); + if(getRealAgentCount() != 0) + state running; + } +} + state running { state_entry() @@ -35,6 +54,14 @@ state running timer() { + if((m_lastTimeCheck + 2) <= llGetUnixTime()) + hardReset(); + + m_lastTimeCheck = llGetUnixTime(); + + if(getRealAgentCount() == 0) + hardReset(); + doNextScriptStep(); } @@ -154,6 +181,23 @@ integer script_appearance(integer slot, key npc, list command) return TRUE; } +integer script_include(integer slot, key npc, list command) +{ + if(llGetInventoryType(llList2String(command, 1) + ".path") != INVENTORY_NOTECARD) + { + llSay(0, "Cant find path '" + llList2String(command, 1) + "'."); + return FALSE; + } + + integer newLine = llList2Integer(command, 2); + + string newnc = osStringReplace(osGetNotecard(llList2String(command, 1) + ".path"), "\n", ""); + m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + slot + ".path", newnc); + m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + slot + ".line", newLine); + m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + slot + ".ncname", llList2String(command, 1) + ".path"); + + return TRUE; +} //Internal functions doNextScriptStep() @@ -234,6 +278,10 @@ doNextScriptStep() if(!script_walk(currentNPCSlot, currentNPCKey, lineCommandData)) llSay(0, "Script execution in '" + llList2String(lineCommandData, 0) + "' in nc '"+ currentncname +"' on line '" + currentLine + "' failed."); break; + case "include": + if(!script_include(currentNPCSlot, currentNPCKey, lineCommandData)) + llSay(0, "Script execution in '" + llList2String(lineCommandData, 0) + "' in nc '"+ currentncname +"' on line '" + currentLine + "' failed."); + break; case "touch": if(!script_touch(currentNPCSlot, currentNPCKey, lineCommandData)) llSay(0, "Script execution in '" + llList2String(lineCommandData, 0) + "' in nc '"+ currentncname +"' on line '" + currentLine + "' failed."); @@ -317,6 +365,12 @@ hardReset() } //Generic Helpers +integer getRealAgentCount() +{ + list users = llGetAgentList(AGENT_LIST_EXCLUDENPC, []); + return llGetListLength(users); +} + integer checkDataEntryInDataList(list _dataList, string _key) { integer _inListPosition = llListFindList(_dataList, [_key]);