This commit is contained in:
Christopher 2021-07-29 09:31:08 +02:00
parent 4944da6bc0
commit 5e46b101b8
1 changed files with 60 additions and 62 deletions

View File

@ -14,22 +14,22 @@ yoptions;
//=================== //===================
list m_npcdata = []; list m_npcdata = [];
integer m_lastTimeCheck = 0; integer m_lastTimeCheck = 0;
default default
{ {
state_entry() state_entry()
{ {
m_npcdata = llCSV2List(osGetPrivateDataValue("tmp." + llGetKey())); m_npcdata = llCSV2List(osGetPrivateDataValue("tmp." + llGetKey()));
hardReset(); hardReset();
m_lastTimeCheck = llGetUnixTime(); m_lastTimeCheck = llGetUnixTime();
checkOSPermissions(); checkOSPermissions();
readAllNPCPathNC(); readAllNPCPathNC();
state waitingForPlayers; state waitingForPlayers;
} }
} }
state waitingForPlayers state waitingForPlayers
@ -37,8 +37,8 @@ state waitingForPlayers
state_entry() state_entry()
{ {
llSetTimerEvent(0.1); llSetTimerEvent(0.1);
} }
timer() timer()
{ {
llSetTimerEvent(2); llSetTimerEvent(2);
@ -47,60 +47,60 @@ state waitingForPlayers
state running; state running;
} }
} }
state running state running
{ {
state_entry() state_entry()
{ {
llSetTimerEvent(0.3); llSetTimerEvent(0.3);
} }
timer() timer()
{ {
if((m_lastTimeCheck + 2) <= llGetUnixTime()) if((m_lastTimeCheck + 2) <= llGetUnixTime())
hardReset(); hardReset();
m_lastTimeCheck = llGetUnixTime(); m_lastTimeCheck = llGetUnixTime();
if(getRealAgentCount() == 0) if(getRealAgentCount() == 0)
hardReset(); hardReset();
doNextScriptStep(); doNextScriptStep();
} }
changed(integer change) changed(integer change)
{ {
if (change & CHANGED_INVENTORY) if (change & CHANGED_INVENTORY)
hardReset(); hardReset();
if (change & CHANGED_REGION_START) if (change & CHANGED_REGION_START)
hardReset(); hardReset();
} }
} }
//Script commands //Script commands
integer script_create(integer slot, key npc, list command) integer script_create(integer slot, key npc, list command)
{ {
if(npc != NULL_KEY) if(npc != NULL_KEY)
osNpcRemove(npc); osNpcRemove(npc);
list objects = osGetSearchableObjectList(llList2String(command, 4)); list objects = osGetSearchableObjectList(llList2String(command, 4));
if(llGetListLength(objects) == 0) if(llGetListLength(objects) == 0)
{ {
llSay(0, "Cant find the position for an object with the name '" + llList2String(command, 4) + "'."); llSay(0, "Cant find the position for an object with the name '" + llList2String(command, 4) + "'.");
return FALSE; return FALSE;
} }
if(llGetInventoryType(llList2String(command, 3) + ".appearance") != INVENTORY_NOTECARD) if(llGetInventoryType(llList2String(command, 3) + ".appearance") != INVENTORY_NOTECARD)
{ {
llSay(0, "Cant find appearance '" + llList2String(command, 3) + "'."); llSay(0, "Cant find appearance '" + llList2String(command, 3) + "'.");
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");
m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + slot, npc); m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + slot, npc);
return TRUE; return TRUE;
} }
integer script_remove(integer slot, key npc, list command) integer script_remove(integer slot, key npc, list command)
{ {
@ -109,23 +109,23 @@ integer script_remove(integer slot, key npc, list command)
m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + slot, NULL_KEY); m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + slot, NULL_KEY);
return TRUE; return TRUE;
} }
integer script_say(integer slot, key npc, list command) integer script_say(integer slot, key npc, list command)
{ {
osNpcSay(npc, 0, llList2String(command, 1)); osNpcSay(npc, 0, llList2String(command, 1));
return TRUE; return TRUE;
} }
integer script_sit(integer slot, key npc, list command) integer script_sit(integer slot, key npc, list command)
{ {
list objects = osGetSearchableObjectList(llList2String(command, 1)); list objects = osGetSearchableObjectList(llList2String(command, 1));
if(llGetListLength(objects) == 0) if(llGetListLength(objects) == 0)
{ {
llSay(0, "Cant find the sit target '" + llList2String(command, 1) + "'."); llSay(0, "Cant find the sit target '" + llList2String(command, 1) + "'.");
return FALSE; return FALSE;
} }
osNpcSit(npc, llList2Key(objects, 0), OS_NPC_SIT_NOW); osNpcSit(npc, llList2Key(objects, 0), OS_NPC_SIT_NOW);
return TRUE; return TRUE;
} }
@ -148,15 +148,15 @@ integer script_walk(integer slot, key npc, list command)
list objects = osGetSearchableObjectList(llList2String(command, 1)); list objects = osGetSearchableObjectList(llList2String(command, 1));
if(llGetListLength(objects) == 0) if(llGetListLength(objects) == 0)
{ {
llSay(0, "Cant find the walk target '" + llList2String(command, 1) + "'."); llSay(0, "Cant find the walk target '" + llList2String(command, 1) + "'.");
return FALSE; return FALSE;
} }
list targetDataList = llGetObjectDetails(llList2Key(objects, 0), [OBJECT_POS]); list targetDataList = llGetObjectDetails(llList2Key(objects, 0), [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);
m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + slot + ".state", "walk"); m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + slot + ".state", "walk");
m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + slot + ".targetPosition", targetPosition); m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + slot + ".targetPosition", targetPosition);
return TRUE; return TRUE;
@ -167,10 +167,10 @@ integer script_touch(integer slot, key npc, list command)
list objects = osGetSearchableObjectList(llList2String(command, 1)); list objects = osGetSearchableObjectList(llList2String(command, 1));
if(llGetListLength(objects) == 0) if(llGetListLength(objects) == 0)
{ {
llSay(0, "Cant find the touch target '" + llList2String(command, 1) + "'."); llSay(0, "Cant find the touch target '" + llList2String(command, 1) + "'.");
return FALSE; return FALSE;
} }
osNpcTouch(npc, llList2Key(objects, 0), LINK_THIS); osNpcTouch(npc, llList2Key(objects, 0), LINK_THIS);
return TRUE; return TRUE;
} }
@ -185,10 +185,10 @@ integer script_appearance(integer slot, key npc, list command)
{ {
if(llGetInventoryType(llList2String(command, 1) + ".appearance") != INVENTORY_NOTECARD) if(llGetInventoryType(llList2String(command, 1) + ".appearance") != INVENTORY_NOTECARD)
{ {
llSay(0, "Cant find appearance '" + llList2String(command, 1) + "'."); llSay(0, "Cant find appearance '" + llList2String(command, 1) + "'.");
return FALSE; return FALSE;
} }
osNpcLoadAppearance(npc, llList2String(command, 1) + ".appearance"); osNpcLoadAppearance(npc, llList2String(command, 1) + ".appearance");
return TRUE; return TRUE;
} }
@ -197,17 +197,17 @@ integer script_include(integer slot, key npc, list command)
{ {
if(llGetInventoryType(llList2String(command, 1) + ".path") != INVENTORY_NOTECARD) if(llGetInventoryType(llList2String(command, 1) + ".path") != INVENTORY_NOTECARD)
{ {
llSay(0, "Cant find path '" + llList2String(command, 1) + "'."); llSay(0, "Cant find path '" + llList2String(command, 1) + "'.");
return FALSE; return FALSE;
} }
integer newLine = llList2Integer(command, 2); integer newLine = llList2Integer(command, 2);
string newnc = osStringReplace(osGetNotecard(llList2String(command, 1) + ".path"), "\n", ""); 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 + ".path", newnc);
m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + slot + ".line", newLine); m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + slot + ".line", newLine);
m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + slot + ".ncname", llList2String(command, 1) + ".path"); m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + slot + ".ncname", llList2String(command, 1) + ".path");
return TRUE; return TRUE;
} }
@ -215,12 +215,12 @@ integer script_include(integer slot, key npc, list command)
doNextScriptStep() doNextScriptStep()
{ {
integer currentNPCSlot = 0; integer currentNPCSlot = 0;
for (currentNPCSlot = 0; currentNPCSlot < llGetListLength(m_npcdata); currentNPCSlot++) for (currentNPCSlot = 0; currentNPCSlot < llGetListLength(m_npcdata); currentNPCSlot++)
{ {
if(!checkDataEntryInDataList(m_npcdata, "npc." + currentNPCSlot)) if(!checkDataEntryInDataList(m_npcdata, "npc." + currentNPCSlot))
continue; continue;
key currentNPCKey = getDataEntryFromDataList(m_npcdata, "npc." + currentNPCSlot); key currentNPCKey = getDataEntryFromDataList(m_npcdata, "npc." + currentNPCSlot);
integer currentLine = getDataEntryFromDataList(m_npcdata, "npc." + currentNPCSlot + ".line"); integer currentLine = getDataEntryFromDataList(m_npcdata, "npc." + currentNPCSlot + ".line");
string currentPath = getDataEntryFromDataList(m_npcdata, "npc." + currentNPCSlot + ".path"); string currentPath = getDataEntryFromDataList(m_npcdata, "npc." + currentNPCSlot + ".path");
@ -235,33 +235,33 @@ doNextScriptStep()
list currentNPCDataList = llGetObjectDetails(currentNPCKey, [OBJECT_POS]); list currentNPCDataList = llGetObjectDetails(currentNPCKey, [OBJECT_POS]);
vector currentNPCPosition = llList2Vector(currentNPCDataList, 0); vector currentNPCPosition = llList2Vector(currentNPCDataList, 0);
if(currentState == "wait") if(currentState == "wait")
{ {
integer waitTime = getDataEntryFromDataList(m_npcdata, "npc." + currentNPCSlot + ".waittime"); integer waitTime = getDataEntryFromDataList(m_npcdata, "npc." + currentNPCSlot + ".waittime");
if(llGetUnixTime() < waitTime) if(llGetUnixTime() < waitTime)
continue; continue;
m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + currentNPCSlot + ".state", ""); m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + currentNPCSlot + ".state", "");
} }
if(currentState == "walk") if(currentState == "walk")
{ {
vector targetPosition = (vector)getDataEntryFromDataList(m_npcdata, "npc." + currentNPCSlot + ".targetPosition"); vector targetPosition = (vector)getDataEntryFromDataList(m_npcdata, "npc." + currentNPCSlot + ".targetPosition");
if(llGetListLength(currentNPCDataList) == 0) if(llGetListLength(currentNPCDataList) == 0)
hardReset(); hardReset();
if(llVecDist(lastKnownPos, currentNPCPosition) <= 0.5) if(llVecDist(lastKnownPos, currentNPCPosition) <= 0.5)
hardReset(); hardReset();
if(llVecDist(currentNPCPosition, targetPosition) >= 1) if(llVecDist(currentNPCPosition, targetPosition) >= 1)
continue; continue;
m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + currentNPCSlot + ".state", ""); m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + currentNPCSlot + ".state", "");
} }
currentLine = currentLine + 1; currentLine = currentLine + 1;
if(currentLine >= llGetListLength(pathLineData)) if(currentLine >= llGetListLength(pathLineData))
{ {
@ -272,7 +272,7 @@ doNextScriptStep()
m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + currentNPCSlot + ".position", currentNPCPosition); m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + currentNPCSlot + ".position", currentNPCPosition);
switch(llList2String(lineCommandData, 0)) switch(llList2String(lineCommandData, 0))
{ {
case "create": case "create":
if(!script_create(currentNPCSlot, currentNPCKey, lineCommandData)) if(!script_create(currentNPCSlot, currentNPCKey, 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.");
@ -288,7 +288,7 @@ doNextScriptStep()
case "sit": case "sit":
if(!script_sit(currentNPCSlot, currentNPCKey, lineCommandData)) if(!script_sit(currentNPCSlot, currentNPCKey, 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 "wait": case "wait":
if(!script_wait(currentNPCSlot, currentNPCKey, lineCommandData)) if(!script_wait(currentNPCSlot, currentNPCKey, 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.");
@ -308,7 +308,7 @@ doNextScriptStep()
case "touch": case "touch":
if(!script_touch(currentNPCSlot, currentNPCKey, lineCommandData)) if(!script_touch(currentNPCSlot, currentNPCKey, 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.");
currentNPCSlot--; currentNPCSlot--;
break; break;
case "goto": case "goto":
@ -319,7 +319,7 @@ doNextScriptStep()
if(script_appearance(currentNPCSlot, currentNPCKey, lineCommandData)) if(script_appearance(currentNPCSlot, currentNPCKey, lineCommandData))
currentNPCSlot--; currentNPCSlot--;
break; 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.");
} }
} }
@ -331,7 +331,7 @@ readNPCPathNC(string ncName)
{ {
string nc = osStringReplace(osGetNotecard(ncName), "\n", ""); string nc = osStringReplace(osGetNotecard(ncName), "\n", "");
integer npcslot = getNextFreeNPCSlot(); integer npcslot = getNextFreeNPCSlot();
m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + npcslot, NULL_KEY); 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 + ".path", nc);
m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + npcslot + ".ncname", ncName); m_npcdata = setDataEntryInDataList(m_npcdata, "npc." + npcslot + ".ncname", ncName);
@ -340,13 +340,13 @@ readNPCPathNC(string ncName)
integer getNextFreeNPCSlot() integer getNextFreeNPCSlot()
{ {
integer currentNPCSlot = 0; integer currentNPCSlot = 0;
for (currentNPCSlot = 0; currentNPCSlot < llGetListLength(m_npcdata); currentNPCSlot++) for (currentNPCSlot = 0; currentNPCSlot < llGetListLength(m_npcdata); currentNPCSlot++)
{ {
if(!checkDataEntryInDataList(m_npcdata, "npc." + currentNPCSlot)) if(!checkDataEntryInDataList(m_npcdata, "npc." + currentNPCSlot))
return currentNPCSlot; return currentNPCSlot;
} }
return 0; return 0;
} }
@ -358,9 +358,9 @@ readAllNPCPathNC()
while(fullInventoryItemListCount--) while(fullInventoryItemListCount--)
{ {
string itemElementName = llList2String(fullInventoryItemList, fullInventoryItemListCount); string itemElementName = llList2String(fullInventoryItemList, fullInventoryItemListCount);
if(osStringEndsWith(llToLower(itemElementName), ".path", 1)) if(osStringEndsWith(llToLower(itemElementName), ".path", 1))
readNPCPathNC(itemElementName); readNPCPathNC(itemElementName);
} }
} }
@ -369,11 +369,11 @@ checkOSPermissions()
key tempnpc = NULL_KEY; key tempnpc = NULL_KEY;
try{ tempnpc = osNpcCreate("Testi", "Test", llGetPos(), llGetOwner()); }catch(exception ex) { llOwnerSay("You need to enable osNpcCreate in your ossl configuration."); } try{ tempnpc = osNpcCreate("Testi", "Test", llGetPos(), llGetOwner()); }catch(exception ex) { llOwnerSay("You need to enable osNpcCreate in your ossl configuration."); }
try{ osNpcRemove(tempnpc); }catch(exception ex) { llOwnerSay("You need to enable osNpcRemove in your ossl configuration."); } try{ osNpcRemove(tempnpc); }catch(exception ex) { llOwnerSay("You need to enable osNpcRemove in your ossl configuration."); }
try{ osMakeNotecard("Test" + llGetKey(), "Test"); }catch(exception ex) { llOwnerSay("You need to enable osMakeNotecard in your ossl configuration."); } try{ osMakeNotecard("Test" + llGetKey(), "Test"); }catch(exception ex) { llOwnerSay("You need to enable osMakeNotecard in your ossl configuration."); }
try{ osGetNotecard("Test" + llGetKey()); }catch(exception ex) { llOwnerSay("You need to enable osGetNotecard in your ossl configuration."); } try{ osGetNotecard("Test" + llGetKey()); }catch(exception ex) { llOwnerSay("You need to enable osGetNotecard in your ossl configuration."); }
try{ osOwnerSaveAppearance("OwnerAppearance" + llGetKey()); }catch(exception ex) { llOwnerSay("You need to enable osOwnerSaveAppearance in your ossl configuration."); } try{ osOwnerSaveAppearance("OwnerAppearance" + llGetKey()); }catch(exception ex) { llOwnerSay("You need to enable osOwnerSaveAppearance in your ossl configuration."); }
llRemoveInventory("Test" + llGetKey()); llRemoveInventory("Test" + llGetKey());
llRemoveInventory("OwnerAppearance" + llGetKey()); llRemoveInventory("OwnerAppearance" + llGetKey());
} }
@ -385,12 +385,10 @@ hardReset()
while(dataListCount--) while(dataListCount--)
if(checkDataEntryInDataList(m_npcdata, "npc." + dataListCount)) if(checkDataEntryInDataList(m_npcdata, "npc." + dataListCount))
osNpcRemove((key)getDataEntryFromDataList(m_npcdata, "npc." + dataListCount)); osNpcRemove((key)getDataEntryFromDataList(m_npcdata, "npc." + dataListCount));
m_lastTimeCheck = 0; m_lastTimeCheck = 0;
m_npcdata = []; m_npcdata = [];
osDeletePrivateDataValue("tmp." + llGetKey()); osDeletePrivateDataValue("tmp." + llGetKey());
//llResetScript();
} }
//Generic Helpers //Generic Helpers