OpenSim.Script.Chris.MultiNPC/Chris.MultiNPC.lsl

786 lines
28 KiB
Plaintext
Raw Normal View History

2021-01-30 05:34:43 +00:00
//YEngine:lsl
yoptions;
//===================
2021-08-07 20:45:13 +00:00
//Version: 0.1.7.2
2021-08-07 14:35:21 +00:00
//Datum: 07.08.2021
2021-01-30 05:34:43 +00:00
//Made by: Chris Resident @ inc.li:8002
//Dependencies:
2021-01-31 05:10:43 +00:00
// - https://github.com/Sahrea/Chris.OS.Additions
2021-01-30 05:34:43 +00:00
//Bescheibung:
// Create and controll a hord of npc at once.
// Read the readme at https://clatza.dev/Christopher/OpenSim.Script.Chris.MultiNPC/src/branch/master/README.md
//===================
2021-10-18 08:18:05 +00:00
2021-01-30 18:07:56 +00:00
list m_npcdata = [];
2021-10-18 08:18:05 +00:00
2021-07-31 18:41:37 +00:00
readNPCPathNC(string ncName)
2021-01-30 05:34:43 +00:00
{
2021-07-31 18:41:37 +00:00
string nc = osStringReplace(osGetNotecard(ncName), "\n", "");
integer npcslot = getNextFreeNPCSlot();
2021-07-29 07:22:52 +00:00
2021-07-31 18:41:37 +00:00
m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + npcslot, NULL_KEY);
m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + npcslot + ".path", nc);
m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + npcslot + ".ncname", ncName);
2021-01-30 05:34:43 +00:00
}
2021-08-01 14:41:28 +00:00
2021-07-31 18:41:37 +00:00
integer getNextFreeNPCSlot()
2021-01-30 18:07:56 +00:00
{
2021-07-31 18:41:37 +00:00
integer currentNPCSlot = 0;
for (currentNPCSlot = 0; currentNPCSlot < llGetListLength(m_npcdata); currentNPCSlot++)
2021-01-30 18:07:56 +00:00
{
2021-07-31 18:41:37 +00:00
if(!checkDataEntryInDataList(m_npcdata, "npc." + currentNPCSlot))
return currentNPCSlot;
2021-07-29 07:31:08 +00:00
}
2021-07-31 18:41:37 +00:00
return 0;
}
readAllNPCPathNC()
{
list fullInventoryItemList = osGetInventoryList();
integer fullInventoryItemListCount = llGetListLength(fullInventoryItemList);
while(fullInventoryItemListCount--)
2021-01-30 18:07:56 +00:00
{
2021-07-31 18:41:37 +00:00
string itemElementName = llList2String(fullInventoryItemList, fullInventoryItemListCount);
if(osStringEndsWith(llToLower(itemElementName), ".path", 1))
readNPCPathNC(itemElementName);
2021-01-30 18:07:56 +00:00
}
}
2021-07-29 07:31:08 +00:00
2021-07-31 18:41:37 +00:00
createNPCTempStorage()
2021-01-30 05:34:43 +00:00
{
2021-07-31 18:41:37 +00:00
list npcKeys = [];
integer currentNPCSlot = 0;
for (currentNPCSlot = 0; currentNPCSlot < llGetListLength(m_npcdata); currentNPCSlot++)
2021-01-30 05:34:43 +00:00
{
2021-07-31 18:41:37 +00:00
key currentNPCKey = getDataEntryFromDataList(m_npcdata, "npc." + currentNPCSlot);
npcKeys += [currentNPCKey];
2021-01-30 05:34:43 +00:00
}
2021-07-29 07:31:08 +00:00
2021-07-31 18:41:37 +00:00
osSetPrivateDataValue("tmpNPCList." + llGetKey(), llList2CSV(npcKeys));
}
2021-07-29 07:31:08 +00:00
2021-07-31 18:41:37 +00:00
removeOldNPC()
{
list npcdata = llCSV2List(osGetPrivateDataValue("tmpNPCList." + llGetKey()));
integer count = llGetListLength(npcdata);
2021-07-29 07:31:08 +00:00
2021-07-31 18:41:37 +00:00
while(count--)osNpcRemove(llList2Key(npcdata, count));
}
2021-07-29 07:31:08 +00:00
2021-07-31 18:41:37 +00:00
hardReset(string message)
{
if(message != "")
llSay(0, "Hard reset: " + message);
llSetTimerEvent(0);
integer dataListCount = llGetListLength(m_npcdata);
while(dataListCount--)
if(checkDataEntryInDataList(m_npcdata, "npc." + dataListCount))
osNpcRemove((key)getDataEntryFromDataList(m_npcdata, "npc." + dataListCount));
2021-07-29 07:31:08 +00:00
2021-07-31 18:41:37 +00:00
llResetScript();
}
2021-07-29 07:31:08 +00:00
2021-07-31 18:59:27 +00:00
integer getGoToLine(integer slot, string target)
{
integer currentLine = 0;
string currentPath = getDataEntryFromDataList(m_npcdata, "npc." + slot + ".path");
list pathLineData = llParseString2List(currentPath, [";"], []);
for (currentLine = 0; currentLine < llGetListLength(pathLineData); currentLine++)
{
string line = llList2String(pathLineData, currentLine);
if(line == target)
2021-08-01 00:04:04 +00:00
return currentLine + 1;
2021-07-31 18:59:27 +00:00
}
return 0;
}
2021-08-01 00:04:04 +00:00
list replaceVars(integer slot, list commands)
{
return commands;
}
2021-07-31 18:41:37 +00:00
//Script Engine
doNextScriptStep()
{
integer currentNPCSlot = 0;
for (currentNPCSlot = 0; currentNPCSlot < llGetListLength(m_npcdata); currentNPCSlot++)
2021-07-29 07:43:08 +00:00
{
2021-07-31 18:41:37 +00:00
if(!checkDataEntryInDataList(m_npcdata, "npc." + currentNPCSlot))
continue;
key currentNPCKey = getDataEntryFromDataList(m_npcdata, "npc." + currentNPCSlot);
2021-10-18 08:18:05 +00:00
integer currentLine = (integer)getDataEntryFromDataList(m_npcdata, "npc." + currentNPCSlot + ".line");
2021-07-31 18:41:37 +00:00
string currentPath = getDataEntryFromDataList(m_npcdata, "npc." + currentNPCSlot + ".path");
string currentState = getDataEntryFromDataList(m_npcdata, "npc." + currentNPCSlot + ".state");
string currentncname = getDataEntryFromDataList(m_npcdata, "npc." + currentNPCSlot + ".ncname");
2021-08-01 00:04:04 +00:00
vector lastPosition = (vector)getDataEntryFromDataList(m_npcdata, "npc." + currentNPCSlot + ".lastPos");
integer currentStuck = (integer)getDataEntryFromDataList(m_npcdata, "npc." + currentNPCSlot + ".stuckCounter");
2021-07-31 18:41:37 +00:00
list pathLineData = llParseString2List(currentPath, [";"], []);
string currentCommand = llList2String(pathLineData, currentLine);
list lineCommandData = llParseString2List(currentCommand, ["=", "|"], []);
2021-08-01 00:04:04 +00:00
list lineCommands = llParseString2List(currentCommand, [" "], []);
2021-07-31 18:41:37 +00:00
list currentNPCDataList = llGetObjectDetails(currentNPCKey, [OBJECT_POS]);
vector currentNPCPosition = llList2Vector(currentNPCDataList, 0);
2021-08-01 00:04:04 +00:00
//llOwnerSay(llKey2Name(currentNPCKey) + ": Current " + currentNPCPosition + "; Last " + lastPosition + "; " + llVecDist(currentNPCPosition, lastPosition));
2021-07-31 18:41:37 +00:00
if(currentState == "wait")
{
2021-10-18 08:18:05 +00:00
integer waitTime = (integer)getDataEntryFromDataList(m_npcdata, "npc." + currentNPCSlot + ".waittime");
2021-07-31 18:41:37 +00:00
if(llGetUnixTime() < waitTime)
continue;
m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + currentNPCSlot + ".state", "");
}
2021-08-01 14:41:28 +00:00
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");
2021-08-01 15:04:08 +00:00
if(llVecDist(currentNPCPosition, lastPosition) <= 0.1)
{
currentStuck++;
if(currentStuck >= 5)
2021-08-07 14:35:21 +00:00
{
2021-08-01 15:04:08 +00:00
osTeleportAgent(currentNPCKey, targetPosition, <0, 0, 0>);
2021-08-07 14:35:21 +00:00
currentStuck = 0;
}
2021-08-01 15:04:08 +00:00
}else{
currentStuck = 0;
}
m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + currentNPCSlot + ".lastPos", currentNPCPosition);
m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + currentNPCSlot + ".stuckCounter", currentStuck);
2021-08-01 14:41:28 +00:00
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{
2021-08-07 14:35:21 +00:00
m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + currentNPCSlot + ".walkPath", llList2CSV(newPathList));
2021-08-01 14:41:28 +00:00
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;
}
2021-07-31 18:41:37 +00:00
if(currentState == "walk")
{
vector targetPosition = (vector)getDataEntryFromDataList(m_npcdata, "npc." + currentNPCSlot + ".targetPosition");
if(llGetListLength(currentNPCDataList) == 0)
hardReset("NPC not found");
2021-08-01 00:04:04 +00:00
if(llVecDist(currentNPCPosition, lastPosition) <= 0.1)
{
currentStuck++;
if(currentStuck >= 5)
2021-08-01 15:04:08 +00:00
osTeleportAgent(currentNPCKey, targetPosition, <0, 0, 0>);
2021-08-01 00:04:04 +00:00
}else{
currentStuck = 0;
2021-08-01 14:41:28 +00:00
}
2021-08-01 00:04:04 +00:00
m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + currentNPCSlot + ".lastPos", currentNPCPosition);
m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + currentNPCSlot + ".stuckCounter", currentStuck);
2021-07-31 18:41:37 +00:00
if(llVecDist(currentNPCPosition, targetPosition) >= 1)
continue;
m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + currentNPCSlot + ".state", "");
}
currentLine = currentLine + 1;
if(currentLine >= llGetListLength(pathLineData))
{
currentLine = 0;
}
m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + currentNPCSlot + ".line", currentLine);
2021-08-01 00:04:04 +00:00
2021-07-31 18:59:27 +00:00
if(llGetSubString(llList2String(lineCommandData, 0), 0, 0) == ":")
{
currentNPCSlot--;
continue;
}
2021-07-31 18:41:37 +00:00
if(llGetSubString(llList2String(lineCommandData, 0), 0, 0) == "%")
{
string storageKey = llMD5String(llList2String(lineCommandData, 0), 0);
string data = lineCommandData;
m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + currentNPCSlot + ".data." + storageKey, data);
continue;
}
switch(llList2String(lineCommandData, 0))
{
case "create":
2021-08-01 00:04:04 +00:00
if(!script_create(currentNPCSlot, currentNPCKey, replaceVars(currentNPCSlot, lineCommandData)))
2021-07-31 18:41:37 +00:00
llSay(0, "Script execution in '" + llList2String(lineCommandData, 0) + "' in nc '"+ currentncname +"' on line '" + currentLine + "' failed.");
break;
case "remove":
2021-08-01 00:04:04 +00:00
if(!script_remove(currentNPCSlot, currentNPCKey, replaceVars(currentNPCSlot, lineCommandData)))
2021-07-31 18:41:37 +00:00
llSay(0, "Script execution in '" + llList2String(lineCommandData, 0) + "' in nc '"+ currentncname +"' on line '" + currentLine + "' failed.");
break;
case "say":
2021-08-01 00:04:04 +00:00
if(!script_say(currentNPCSlot, currentNPCKey, replaceVars(currentNPCSlot, lineCommandData)))
2021-07-31 18:41:37 +00:00
llSay(0, "Script execution in '" + llList2String(lineCommandData, 0) + "' in nc '"+ currentncname +"' on line '" + currentLine + "' failed.");
break;
case "sit":
2021-08-01 00:04:04 +00:00
if(!script_sit(currentNPCSlot, currentNPCKey, replaceVars(currentNPCSlot, lineCommandData)))
2021-07-31 18:41:37 +00:00
llSay(0, "Script execution in '" + llList2String(lineCommandData, 0) + "' in nc '"+ currentncname +"' on line '" + currentLine + "' failed.");
break;
case "wait":
2021-08-01 00:04:04 +00:00
if(!script_wait(currentNPCSlot, currentNPCKey, replaceVars(currentNPCSlot, lineCommandData)))
2021-07-31 18:41:37 +00:00
llSay(0, "Script execution in '" + llList2String(lineCommandData, 0) + "' in nc '"+ currentncname +"' on line '" + currentLine + "' failed.");
break;
case "stand":
2021-08-01 00:04:04 +00:00
if(!script_stand(currentNPCSlot, currentNPCKey, replaceVars(currentNPCSlot, lineCommandData)))
2021-07-31 18:41:37 +00:00
llSay(0, "Script execution in '" + llList2String(lineCommandData, 0) + "' in nc '"+ currentncname +"' on line '" + currentLine + "' failed.");
break;
case "walk":
2021-08-01 00:04:04 +00:00
if(!script_walk(currentNPCSlot, currentNPCKey, replaceVars(currentNPCSlot, lineCommandData)))
2021-07-31 18:41:37 +00:00
llSay(0, "Script execution in '" + llList2String(lineCommandData, 0) + "' in nc '"+ currentncname +"' on line '" + currentLine + "' failed.");
break;
2021-08-01 14:41:28 +00:00
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;
2021-07-31 18:41:37 +00:00
case "fly":
2021-08-01 00:04:04 +00:00
if(!script_fly(currentNPCSlot, currentNPCKey, replaceVars(currentNPCSlot, lineCommandData)))
2021-08-01 14:41:28 +00:00
llSay(0, "Script execution in '" + llList2String(lineCommandData, 0) + "' in nc '"+ currentncname +"' on line '" + currentLine + "' failed.");
2021-07-31 18:41:37 +00:00
break;
case "include":
2021-08-01 00:04:04 +00:00
if(!script_include(currentNPCSlot, currentNPCKey, replaceVars(currentNPCSlot, lineCommandData)))
2021-07-31 18:41:37 +00:00
llSay(0, "Script execution in '" + llList2String(lineCommandData, 0) + "' in nc '"+ currentncname +"' on line '" + currentLine + "' failed.");
break;
case "touch":
2021-08-01 00:04:04 +00:00
if(!script_touch(currentNPCSlot, currentNPCKey, replaceVars(currentNPCSlot, lineCommandData)))
2021-07-31 18:41:37 +00:00
llSay(0, "Script execution in '" + llList2String(lineCommandData, 0) + "' in nc '"+ currentncname +"' on line '" + currentLine + "' failed.");
currentNPCSlot--;
break;
case "goto":
2021-08-01 00:04:04 +00:00
if(script_goto(currentNPCSlot, currentNPCKey, replaceVars(currentNPCSlot, lineCommandData)))
2021-07-31 18:41:37 +00:00
currentNPCSlot--;
break;
case "appearance":
2021-08-01 00:04:04 +00:00
if(script_appearance(currentNPCSlot, currentNPCKey, replaceVars(currentNPCSlot, lineCommandData)))
2021-07-31 18:41:37 +00:00
currentNPCSlot--;
break;
case "animation":
2021-08-01 00:04:04 +00:00
if(!script_animation(currentNPCSlot, currentNPCKey, replaceVars(currentNPCSlot, lineCommandData)))
2021-07-31 18:41:37 +00:00
llSay(0, "Script execution in '" + llList2String(lineCommandData, 0) + "' in nc '"+ currentncname +"' on line '" + currentLine + "' failed.");
break;
case "stopAnimation":
2021-08-01 00:04:04 +00:00
if(!script_StopAnimation(currentNPCSlot, currentNPCKey, replaceVars(currentNPCSlot, lineCommandData)))
2021-07-31 18:41:37 +00:00
llSay(0, "Script execution in '" + llList2String(lineCommandData, 0) + "' in nc '"+ currentncname +"' on line '" + currentLine + "' failed.");
break;
case "profileImage":
2021-08-01 00:04:04 +00:00
if(!script_profileImage(currentNPCSlot, currentNPCKey, replaceVars(currentNPCSlot, lineCommandData)))
2021-07-31 18:41:37 +00:00
llSay(0, "Script execution in '" + llList2String(lineCommandData, 0) + "' in nc '"+ currentncname +"' on line '" + currentLine + "' failed.");
break;
case "profileText":
2021-08-01 00:04:04 +00:00
if(!script_profileText(currentNPCSlot, currentNPCKey, replaceVars(currentNPCSlot, lineCommandData)))
2021-07-31 18:41:37 +00:00
llSay(0, "Script execution in '" + llList2String(lineCommandData, 0) + "' in nc '"+ currentncname +"' on line '" + currentLine + "' failed.");
break;
2021-08-07 14:35:21 +00:00
case "give":
if(!script_give(currentNPCSlot, currentNPCKey, replaceVars(currentNPCSlot, lineCommandData)))
llSay(0, "Script execution in '" + llList2String(lineCommandData, 0) + "' in nc '"+ currentncname +"' on line '" + currentLine + "' failed.");
break;
case "rez":
if(!script_rez(currentNPCSlot, currentNPCKey, replaceVars(currentNPCSlot, lineCommandData)))
llSay(0, "Script execution in '" + llList2String(lineCommandData, 0) + "' in nc '"+ currentncname +"' on line '" + currentLine + "' failed.");
break;
2021-07-31 18:41:37 +00:00
default:
llSay(0, "Unknown command '" + llList2String(lineCommandData, 0) + "' in nc '"+ currentncname +"' on line '" + currentLine + "' failed.");
}
2021-07-29 07:43:08 +00:00
}
2021-07-29 07:31:08 +00:00
}
2021-01-30 05:34:43 +00:00
//Script commands
integer script_create(integer slot, key npc, list command)
{
if(npc != NULL_KEY)
osNpcRemove(npc);
2021-07-29 07:31:08 +00:00
2021-07-29 19:50:16 +00:00
list objects = osGetSearchableObjectPartList(llList2String(command, 4));
2021-01-30 05:34:43 +00:00
if(llGetListLength(objects) == 0)
{
2021-07-29 07:31:08 +00:00
llSay(0, "Cant find the position for an object with the name '" + llList2String(command, 4) + "'.");
2021-01-30 05:34:43 +00:00
return FALSE;
}
2021-07-29 07:31:08 +00:00
2021-01-30 05:34:43 +00:00
if(llGetInventoryType(llList2String(command, 3) + ".appearance") != INVENTORY_NOTECARD)
{
2021-07-29 07:31:08 +00:00
llSay(0, "Cant find appearance '" + llList2String(command, 3) + "'.");
2021-01-30 05:34:43 +00:00
return FALSE;
}
2021-08-07 14:35:21 +00:00
npc = osNpcCreate(llList2String(command, 1), llList2String(command, 2), llList2Vector(llGetObjectDetails(llList2Key(objects, 0), [OBJECT_POS]), 0), llList2String(command, 3) + ".appearance", OS_NPC_CREATOR_OWNED);
2021-01-30 05:34:43 +00:00
m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + slot, npc);
2021-07-29 07:43:08 +00:00
createNPCTempStorage();
2021-01-30 05:34:43 +00:00
return TRUE;
2021-07-29 07:31:08 +00:00
}
2021-01-30 05:34:43 +00:00
2021-01-30 18:46:13 +00:00
integer script_remove(integer slot, key npc, list command)
{
if(npc != NULL_KEY)
osNpcRemove(npc);
m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + slot, NULL_KEY);
return TRUE;
2021-07-29 07:31:08 +00:00
}
2021-01-30 18:46:13 +00:00
2021-01-30 05:34:43 +00:00
integer script_say(integer slot, key npc, list command)
{
osNpcSay(npc, 0, llList2String(command, 1));
return TRUE;
}
2021-07-29 07:31:08 +00:00
2021-08-07 14:35:21 +00:00
integer script_rez(integer slot, key npc, list command)
{
vector targetPosition = <0, 0, 0>;
vector currentPosition = llGetPos();
if(llList2Vector(command, 1) == <0, 0, 0>)
{
list objects = osGetSearchableObjectPartList(llList2String(command, 1));
if(llGetListLength(objects) == 0)
{
llSay(0, "Cant find the walk target '" + llList2String(command, 1) + "'.");
return FALSE;
}
list targetDataList = llGetObjectDetails(llList2Key(objects, 0), [OBJECT_POS]);
targetPosition = llList2Vector(targetDataList, 0);
}else{
targetPosition = llList2Vector(command, 1);
}
if(llGetInventoryType(llList2String(command, 1)) != INVENTORY_OBJECT)
{
llSay(0, "Cant find object '" + llList2String(command, 1) + "' to rez.");
return FALSE;
}
llSetRegionPos(targetPosition);
llRezAtRoot(llList2String(command, 1), targetPosition, llGetVel(), llGetRot(), 0);
llSetRegionPos(currentPosition);
return TRUE;
}
integer script_give(integer slot, key npc, list command)
{
if(llGetInventoryType(llList2String(command, 1)) != INVENTORY_ALL)
{
llSay(0, "Cant find '" + llList2String(command, 1) + "' to give.");
return FALSE;
}
llGiveInventory(llList2String(command, 0), llList2String(command, 1));
return TRUE;
}
2021-01-30 05:34:43 +00:00
integer script_sit(integer slot, key npc, list command)
{
2021-07-29 19:50:16 +00:00
list objects = osGetSearchableObjectPartList(llList2String(command, 1));
2021-01-30 05:34:43 +00:00
if(llGetListLength(objects) == 0)
{
2021-07-29 07:31:08 +00:00
llSay(0, "Cant find the sit target '" + llList2String(command, 1) + "'.");
2021-01-30 05:34:43 +00:00
return FALSE;
}
2021-07-29 07:31:08 +00:00
2021-01-30 05:34:43 +00:00
osNpcSit(npc, llList2Key(objects, 0), OS_NPC_SIT_NOW);
return TRUE;
}
integer script_stand(integer slot, key npc, list command)
{
osNpcStand(npc);
return TRUE;
}
integer script_wait(integer slot, key npc, list command)
{
m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + slot + ".state", "wait");
m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + slot + ".waittime", llGetUnixTime() + (integer)llList2String(command, 1));
return TRUE;
}
2021-08-01 14:41:28 +00:00
integer script_path(integer slot, key npc, list command)
{
2021-08-07 14:35:21 +00:00
key startNode = NULL_KEY;
key endNode = NULL_KEY;
list nodes = [];
2021-08-01 14:41:28 +00:00
2021-08-07 14:35:21 +00:00
if(llGetListLength(command) >= 3)
2021-08-01 14:41:28 +00:00
{
2021-08-07 14:35:21 +00:00
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;
}
startNode = llList2Key(osGetSearchableObjectPartList(llList2String(command, 1)), 0);
endNode = llList2Key(osGetSearchableObjectPartList(llList2String(command, 2)), 0);
}else{
list objects = osGetSearchableObjectPartList(llList2String(command, 1));
if(llGetListLength(objects) == 0)
{
llSay(0, "Cant find the path target '" + llList2String(command, 1) + "'.");
return FALSE;
}
list targetDataList = llGetObjectDetails(npc, [OBJECT_POS]);
vector startPosition = llList2Vector(targetDataList, 0);
startNode = osGetNextNode(startPosition);
endNode = llList2Key(osGetSearchableObjectPartList(llList2String(command, 1)), 0);
2021-08-01 14:41:28 +00:00
}
try
{
2021-08-07 14:35:21 +00:00
nodes = osGetNodeListToTarget(startNode, endNode);
2021-08-01 14:41:28 +00:00
}
catch(scriptexception ex)
{
2021-08-07 14:35:21 +00:00
llSay(0, "Cant find the path to target '" + llKey2Name(endNode) + "'.");
2021-08-01 14:41:28 +00:00
return FALSE;
}
2021-08-07 14:35:21 +00:00
list targetDataList = llGetObjectDetails(startNode, [OBJECT_POS]);
2021-08-01 14:41:28 +00:00
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;
}
2021-01-30 05:34:43 +00:00
integer script_walk(integer slot, key npc, list command)
{
2021-07-29 08:00:43 +00:00
vector targetPosition = <0, 0, 0>;
if(llList2Vector(command, 1) == <0, 0, 0>)
2021-01-30 05:34:43 +00:00
{
2021-07-29 19:50:16 +00:00
list objects = osGetSearchableObjectPartList(llList2String(command, 1));
2021-07-29 08:00:43 +00:00
if(llGetListLength(objects) == 0)
{
llSay(0, "Cant find the walk target '" + llList2String(command, 1) + "'.");
return FALSE;
}
2021-07-29 07:31:08 +00:00
2021-07-29 08:00:43 +00:00
list targetDataList = llGetObjectDetails(llList2Key(objects, 0), [OBJECT_POS]);
targetPosition = llList2Vector(targetDataList, 0);
}else{
targetPosition = llList2Vector(command, 1);
}
2021-07-29 07:31:08 +00:00
2021-01-30 05:34:43 +00:00
osNpcMoveToTarget(npc, targetPosition, OS_NPC_NO_FLY);
2021-07-29 07:31:08 +00:00
2021-01-30 05:34:43 +00:00
m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + slot + ".state", "walk");
m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + slot + ".targetPosition", targetPosition);
return TRUE;
}
2021-07-29 15:16:27 +00:00
integer script_fly(integer slot, key npc, list command)
{
vector targetPosition = <0, 0, 0>;
if(llList2Vector(command, 1) == <0, 0, 0>)
{
2021-07-29 19:50:16 +00:00
list objects = osGetSearchableObjectPartList(llList2String(command, 1));
2021-07-29 15:16:27 +00:00
if(llGetListLength(objects) == 0)
{
2021-07-29 15:21:31 +00:00
llSay(0, "Cant find the fly target '" + llList2String(command, 1) + "'.");
2021-07-29 15:16:27 +00:00
return FALSE;
}
list targetDataList = llGetObjectDetails(llList2Key(objects, 0), [OBJECT_POS]);
targetPosition = llList2Vector(targetDataList, 0);
}else{
targetPosition = llList2Vector(command, 1);
}
2021-07-29 19:50:16 +00:00
osNpcMoveToTarget(npc, targetPosition, OS_NPC_FLY | OS_NPC_LAND_AT_TARGET );
2021-07-29 15:16:27 +00:00
m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + slot + ".state", "walk");
m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + slot + ".targetPosition", targetPosition);
return TRUE;
}
2021-01-30 05:34:43 +00:00
integer script_touch(integer slot, key npc, list command)
{
2021-07-29 19:50:16 +00:00
list objects = osGetSearchableObjectPartList(llList2String(command, 1));
2021-01-30 05:34:43 +00:00
if(llGetListLength(objects) == 0)
{
2021-07-29 07:31:08 +00:00
llSay(0, "Cant find the touch target '" + llList2String(command, 1) + "'.");
2021-01-30 05:34:43 +00:00
return FALSE;
2021-07-29 07:31:08 +00:00
}
2021-01-30 05:34:43 +00:00
osNpcTouch(npc, llList2Key(objects, 0), LINK_THIS);
return TRUE;
}
integer script_goto(integer slot, key npc, list command)
{
2021-07-31 18:59:27 +00:00
integer targetLine = (integer)llList2String(command, 1);
if(targetLine == 0)
{
targetLine = getGoToLine(slot, ":" + llList2String(command, 1));
}
if(targetLine == 0)
{
llSay(0, "Cant find the GoTo Target '" + llList2String(command, 1) + "'.");
return FALSE;
}
m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + slot + ".line", targetLine - 1);
2021-01-30 05:34:43 +00:00
return TRUE;
}
2021-01-30 05:58:42 +00:00
integer script_appearance(integer slot, key npc, list command)
{
if(llGetInventoryType(llList2String(command, 1) + ".appearance") != INVENTORY_NOTECARD)
{
2021-07-29 07:31:08 +00:00
llSay(0, "Cant find appearance '" + llList2String(command, 1) + "'.");
2021-01-30 05:58:42 +00:00
return FALSE;
}
2021-07-29 07:31:08 +00:00
2021-01-30 05:58:42 +00:00
osNpcLoadAppearance(npc, llList2String(command, 1) + ".appearance");
return TRUE;
}
2021-07-29 07:53:02 +00:00
integer script_animation(integer slot, key npc, list command)
{
if(llGetInventoryType(llList2String(command, 1)) != INVENTORY_ANIMATION)
{
llSay(0, "Cant find animation '" + llList2String(command, 1) + "'.");
return FALSE;
}
osNpcPlayAnimation(npc, llList2String(command, 1));
return TRUE;
}
integer script_StopAnimation(integer slot, key npc, list command)
{
if(llGetInventoryType(llList2String(command, 1)) != INVENTORY_ANIMATION)
{
llSay(0, "Cant find animation '" + llList2String(command, 1) + "'.");
return FALSE;
}
osNpcStopAnimation(npc, llList2String(command, 1));
return TRUE;
}
integer script_profileImage(integer slot, key npc, list command)
{
if(llGetInventoryType(llList2String(command, 1)) != INVENTORY_TEXTURE)
{
llSay(0, "Cant find image '" + llList2String(command, 1) + "'.");
return FALSE;
}
osNpcSetProfileImage(npc, llList2String(command, 1));
return TRUE;
}
integer script_profileText(integer slot, key npc, list command)
{
osNpcSetProfileAbout(npc, llList2String(command, 1));
return TRUE;
}
2021-01-30 18:07:56 +00:00
integer script_include(integer slot, key npc, list command)
{
if(llGetInventoryType(llList2String(command, 1) + ".path") != INVENTORY_NOTECARD)
{
2021-07-29 07:31:08 +00:00
llSay(0, "Cant find path '" + llList2String(command, 1) + "'.");
2021-01-30 18:07:56 +00:00
return FALSE;
}
2021-07-29 07:31:08 +00:00
2021-01-30 18:07:56 +00:00
integer newLine = llList2Integer(command, 2);
2021-07-29 07:31:08 +00:00
2021-01-30 18:07:56 +00:00
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");
2021-07-29 07:31:08 +00:00
2021-01-30 18:07:56 +00:00
return TRUE;
}
2021-01-30 05:58:42 +00:00
2021-07-31 18:41:37 +00:00
//Generic Helpers
integer getRealAgentCount()
2021-01-30 05:34:43 +00:00
{
2021-07-31 18:41:37 +00:00
list users = llGetAgentList(AGENT_LIST_EXCLUDENPC, []);
return llGetListLength(users);
2021-01-30 05:34:43 +00:00
}
2021-07-31 18:41:37 +00:00
integer checkDataEntryInDataList(list _dataList, string _key)
2021-01-30 05:34:43 +00:00
{
2021-07-31 18:41:37 +00:00
integer _inListPosition = llListFindList(_dataList, [_key]);
if(_inListPosition == -1)return FALSE;
return TRUE;
2021-01-30 05:34:43 +00:00
}
2021-07-31 18:41:37 +00:00
string getDataEntryFromDataList(list _dataList, string _key)
2021-01-30 05:34:43 +00:00
{
2021-07-31 18:41:37 +00:00
integer _inListPosition = llListFindList(_dataList, [_key]);
if(_inListPosition == -1)return "";
return llList2String(_dataList, _inListPosition + 1);
}
2021-07-29 07:31:08 +00:00
2021-07-31 18:41:37 +00:00
list setDataEntryInDataList(list _dataList, string _key, string _value)
{
integer _inListPosition = llListFindList(_dataList, [_key]);
if(_inListPosition == -1){
_dataList += [_key, _value];
return _dataList;
2021-01-30 05:34:43 +00:00
}
2021-07-31 18:41:37 +00:00
return llListReplaceList(_dataList, [_value], _inListPosition + 1, _inListPosition + 1);
2021-01-30 05:34:43 +00:00
}
2021-10-18 08:18:05 +00:00
integer Key2Chan(key ID)
{
return 0x80000000 | (integer)("0x"+(string)ID);
}
2021-07-31 18:41:37 +00:00
default
2021-01-30 05:34:43 +00:00
{
2021-07-31 18:41:37 +00:00
state_entry()
2021-01-30 05:34:43 +00:00
{
2021-07-31 18:41:37 +00:00
removeOldNPC();
readAllNPCPathNC();
2021-07-29 07:31:08 +00:00
2021-07-31 18:41:37 +00:00
state waitingForPlayers;
2021-01-30 05:34:43 +00:00
}
}
2021-07-31 18:41:37 +00:00
state waitingForPlayers
2021-01-30 05:34:43 +00:00
{
2021-07-31 18:41:37 +00:00
state_entry()
{
llSetTimerEvent(0.1);
}
2021-07-29 07:31:08 +00:00
2021-07-31 18:41:37 +00:00
timer()
{
llSetTimerEvent(2);
if(getRealAgentCount() != 0)
state running;
}
2021-01-30 05:34:43 +00:00
}
2021-07-31 18:41:37 +00:00
state running
2021-01-30 05:34:43 +00:00
{
2021-07-31 18:41:37 +00:00
state_entry()
{
2021-10-18 08:18:05 +00:00
//llListen(Key2Chan(llGetKey(), "", "", "");
2021-07-31 18:41:37 +00:00
llSetTimerEvent(0.3);
}
2021-07-31 17:48:21 +00:00
2021-07-31 18:41:37 +00:00
touch_start(integer i)
2021-07-29 07:43:08 +00:00
{
2021-07-31 18:41:37 +00:00
if(llDetectedKey(0) != llGetOwner())
return;
osEasyDialog(llDetectedKey(0), "", ["Stop all", "Restart", "Start all"]);
}
listen( integer channel, string name, key id, string message)
{
2021-10-18 08:18:05 +00:00
if(llGetOwnerKey(id) != llGetOwner())
return;
2021-07-31 18:41:37 +00:00
if(message == "Stop all")
{
llSetTimerEvent(0);
2021-10-18 08:18:05 +00:00
return;
2021-07-31 18:41:37 +00:00
}
if(message == "Start all")
{
llSetTimerEvent(0.3);
2021-10-18 08:18:05 +00:00
return;
2021-07-31 18:41:37 +00:00
}
if(message == "Restart")
{
hardReset("");
2021-10-18 08:18:05 +00:00
return;
2021-07-31 18:41:37 +00:00
}
2021-10-18 08:18:05 +00:00
2021-07-29 07:43:08 +00:00
}
2021-07-31 18:41:37 +00:00
timer()
{
if(getRealAgentCount() == 0)
hardReset("region empty");
2021-01-30 18:07:56 +00:00
2021-07-31 18:41:37 +00:00
doNextScriptStep();
}
2021-01-30 05:34:43 +00:00
2021-07-31 18:41:37 +00:00
changed(integer change)
{
if (change & CHANGED_INVENTORY)
hardReset("");
2021-01-30 05:34:43 +00:00
2021-07-31 18:41:37 +00:00
if (change & CHANGED_REGION_START)
hardReset("");
}
on_rez(integer start_param)
{
hardReset("");
2021-01-30 05:34:43 +00:00
}
}