fix some small bugs

This commit is contained in:
Christopher 2021-08-07 16:35:21 +02:00
parent 2170ce351b
commit 6080ad3890
1 changed files with 98 additions and 21 deletions

View File

@ -2,8 +2,8 @@
yoptions; yoptions;
//=================== //===================
//Version: 0.1.7 //Version: 0.1.7.1
//Datum: 01.08.2021 //Datum: 07.08.2021
//UpdateRAW: https://clatza.dev/Christopher/OpenSim.Script.Chris.MultiNPC/raw/branch/master/Chris.MultiNPC.lsl //UpdateRAW: https://clatza.dev/Christopher/OpenSim.Script.Chris.MultiNPC/raw/branch/master/Chris.MultiNPC.lsl
//Made by: Chris Resident @ inc.li:8002 //Made by: Chris Resident @ inc.li:8002
//Dependencies: //Dependencies:
@ -165,7 +165,10 @@ doNextScriptStep()
currentStuck++; currentStuck++;
if(currentStuck >= 5) if(currentStuck >= 5)
{
osTeleportAgent(currentNPCKey, targetPosition, <0, 0, 0>); osTeleportAgent(currentNPCKey, targetPosition, <0, 0, 0>);
currentStuck = 0;
}
}else{ }else{
currentStuck = 0; currentStuck = 0;
} }
@ -182,7 +185,7 @@ doNextScriptStep()
m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + currentNPCSlot + ".state", ""); m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + currentNPCSlot + ".state", "");
m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + currentNPCSlot + ".walkPath", ""); m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + currentNPCSlot + ".walkPath", "");
}else{ }else{
m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + currentNPCSlot + ".walkPath", llList2CSV(newPathList)); m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + currentNPCSlot + ".walkPath", llList2CSV(newPathList));
targetKey = llList2Key(llCSV2List(getDataEntryFromDataList(m_npcdata, "npc." + currentNPCSlot + ".walkPath")), 0); targetKey = llList2Key(llCSV2List(getDataEntryFromDataList(m_npcdata, "npc." + currentNPCSlot + ".walkPath")), 0);
targetPosition = llList2Vector(llGetObjectDetails(targetKey, [OBJECT_POS]), 0); targetPosition = llList2Vector(llGetObjectDetails(targetKey, [OBJECT_POS]), 0);
osNpcMoveToTarget(currentNPCKey, targetPosition, OS_NPC_NO_FLY); osNpcMoveToTarget(currentNPCKey, targetPosition, OS_NPC_NO_FLY);
@ -241,7 +244,6 @@ doNextScriptStep()
m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + currentNPCSlot + ".data." + storageKey, data); m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + currentNPCSlot + ".data." + storageKey, data);
continue; continue;
} }
switch(llList2String(lineCommandData, 0)) switch(llList2String(lineCommandData, 0))
{ {
@ -314,6 +316,14 @@ doNextScriptStep()
if(!script_profileText(currentNPCSlot, currentNPCKey, replaceVars(currentNPCSlot, lineCommandData))) if(!script_profileText(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; break;
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;
default: default:
llSay(0, "Unknown command '" + llList2String(lineCommandData, 0) + "' in nc '"+ currentncname +"' on line '" + currentLine + "' failed."); llSay(0, "Unknown command '" + llList2String(lineCommandData, 0) + "' in nc '"+ currentncname +"' on line '" + currentLine + "' failed.");
} }
@ -339,7 +349,7 @@ integer script_create(integer slot, key npc, list command)
return FALSE; return FALSE;
} }
npc = osNpcCreate(llList2String(command, 1), llList2String(command, 2), llList2Vector(llGetObjectDetails(llList2Key(objects, 0), [OBJECT_POS]), 0), llList2String(command, 3) + ".appearance"); npc = osNpcCreate(llList2String(command, 1), llList2String(command, 2), llList2Vector(llGetObjectDetails(llList2Key(objects, 0), [OBJECT_POS]), 0), llList2String(command, 3) + ".appearance", OS_NPC_CREATOR_OWNED);
m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + slot, npc); m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + slot, npc);
createNPCTempStorage(); createNPCTempStorage();
return TRUE; return TRUE;
@ -360,6 +370,52 @@ integer script_say(integer slot, key npc, list command)
return TRUE; return TRUE;
} }
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;
}
integer script_sit(integer slot, key npc, list command) integer script_sit(integer slot, key npc, list command)
{ {
list objects = osGetSearchableObjectPartList(llList2String(command, 1)); list objects = osGetSearchableObjectPartList(llList2String(command, 1));
@ -388,33 +444,54 @@ integer script_wait(integer slot, key npc, list command)
integer script_path(integer slot, key npc, list command) integer script_path(integer slot, key npc, list command)
{ {
list objects = osGetSearchableObjectPartList(llList2String(command, 1)); key startNode = NULL_KEY;
if(llGetListLength(objects) == 0) key endNode = NULL_KEY;
{ list nodes = [];
llSay(0, "Cant find the path start '" + llList2String(command, 1) + "'.");
return FALSE;
}
objects = osGetSearchableObjectPartList(llList2String(command, 2)); if(llGetListLength(command) >= 3)
if(llGetListLength(objects) == 0)
{ {
llSay(0, "Cant find the path target '" + llList2String(command, 1) + "'."); list objects = osGetSearchableObjectPartList(llList2String(command, 1));
return FALSE; 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);
} }
list nodes = [];
try try
{ {
nodes = osGetNodeListToTarget(llList2Key(osGetSearchableObjectPartList(llList2String(command, 1)), 0), llList2Key(osGetSearchableObjectPartList(llList2String(command, 2)), 0)); nodes = osGetNodeListToTarget(startNode, endNode);
} }
catch(scriptexception ex) catch(scriptexception ex)
{ {
llSay(0, "Cant find the path to target '" + llList2String(command, 1) + "'."); llSay(0, "Cant find the path to target '" + llKey2Name(endNode) + "'.");
return FALSE; return FALSE;
} }
list targetDataList = llGetObjectDetails(llList2Key(osGetSearchableObjectPartList(llList2String(command, 1)), 0), [OBJECT_POS]); list targetDataList = llGetObjectDetails(startNode, [OBJECT_POS]);
vector targetPosition = llList2Vector(targetDataList, 0); vector targetPosition = llList2Vector(targetDataList, 0);
osNpcMoveToTarget(npc, targetPosition, OS_NPC_NO_FLY); osNpcMoveToTarget(npc, targetPosition, OS_NPC_NO_FLY);