From 9939f94f08b33e3dd9eeea65b730f0ddc80275a5 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 27 Jan 2012 23:05:48 +0000 Subject: Implement osNpcGetOwner(key npc):key. This returns the owner for an 'owned' NPC, the npc's own key for an 'unowned' NPC and NULL_KEY is the input key was not an npc. llGetOwnerKey() could also be extended but this does not allow one to distinguish between an unowned NPC and some other result (e.g. 'no such object' if NULL_KEY is the return. Also, any future extensions to LSL functions by Linden Lab are unpredictable and OpenSim-specific extensions could clash. --- OpenSim/Region/Framework/Interfaces/INPCModule.cs | 2 +- .../Shared/Api/Implementation/OSSL_Api.cs | 21 ++++++++++ .../ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs | 48 +++++++++++++--------- .../ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs | 5 +++ 4 files changed, 56 insertions(+), 20 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/Framework/Interfaces/INPCModule.cs b/OpenSim/Region/Framework/Interfaces/INPCModule.cs index c50e734..b428c40 100644 --- a/OpenSim/Region/Framework/Interfaces/INPCModule.cs +++ b/OpenSim/Region/Framework/Interfaces/INPCModule.cs @@ -134,4 +134,4 @@ namespace OpenSim.Region.Framework.Interfaces /// UUID of owner if the NPC exists, UUID.Zero if there was no such agent, the agent is unowned or the agent was not an NPC UUID GetOwner(UUID agentID); } -} +} \ No newline at end of file diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs index 7792ab5..ba96ad8 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs @@ -2313,6 +2313,27 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api } } + public LSL_Key osNpcGetOwner(LSL_Key npc) + { + CheckThreatLevel(ThreatLevel.None, "osNpcGetOwner"); + + INPCModule npcModule = World.RequestModuleInterface(); + if (npcModule != null) + { + UUID npcId; + if (UUID.TryParse(npc.m_string, out npcId)) + { + UUID owner = npcModule.GetOwner(npcId); + if (owner != UUID.Zero) + return new LSL_Key(owner.ToString()); + else + return npc; + } + } + + return new LSL_Key(UUID.Zero.ToString()); + } + public LSL_Vector osNpcGetPos(LSL_Key npc) { CheckThreatLevel(ThreatLevel.High, "osNpcGetPos"); diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs index 0f8cbdc..ee48ec4 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs @@ -173,25 +173,35 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces LSL_List osGetLinkPrimitiveParams(int linknumber, LSL_List rules); - key osNpcCreate(string user, string name, vector position, string notecard); - key osNpcCreate(string user, string name, vector position, string notecard, int options); - LSL_Key osNpcSaveAppearance(key npc, string notecard); - void osNpcLoadAppearance(key npc, string notecard); - vector osNpcGetPos(key npc); - void osNpcMoveTo(key npc, vector position); - void osNpcMoveToTarget(key npc, vector target, int options); - rotation osNpcGetRot(key npc); - void osNpcSetRot(LSL_Key npc, rotation rot); - void osNpcStopMoveToTarget(LSL_Key npc); - void osNpcSay(key npc, string message); - void osNpcSit(key npc, key target, int options); - void osNpcStand(LSL_Key npc); - void osNpcRemove(key npc); - void osNpcPlayAnimation(LSL_Key npc, string animation); - void osNpcStopAnimation(LSL_Key npc, string animation); - - LSL_Key osOwnerSaveAppearance(string notecard); - LSL_Key osAgentSaveAppearance(key agentId, string notecard); + key osNpcCreate(string user, string name, vector position, string notecard); + key osNpcCreate(string user, string name, vector position, string notecard, int options); + LSL_Key osNpcSaveAppearance(key npc, string notecard); + void osNpcLoadAppearance(key npc, string notecard); + vector osNpcGetPos(key npc); + void osNpcMoveTo(key npc, vector position); + void osNpcMoveToTarget(key npc, vector target, int options); + + /// + /// Get the owner of the NPC + /// + /// + /// + /// The owner of the NPC for an owned NPC. The NPC's agent id for an unowned NPC. UUID.Zero if the key is not an npc. + /// + LSL_Key osNpcGetOwner(key npc); + + rotation osNpcGetRot(key npc); + void osNpcSetRot(LSL_Key npc, rotation rot); + void osNpcStopMoveToTarget(LSL_Key npc); + void osNpcSay(key npc, string message); + void osNpcSit(key npc, key target, int options); + void osNpcStand(LSL_Key npc); + void osNpcRemove(key npc); + void osNpcPlayAnimation(LSL_Key npc, string animation); + void osNpcStopAnimation(LSL_Key npc, string animation); + + LSL_Key osOwnerSaveAppearance(string notecard); + LSL_Key osAgentSaveAppearance(key agentId, string notecard); key osGetMapTexture(); key osGetRegionMapTexture(string regionName); diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs index 02efecf..38a814d 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs @@ -513,6 +513,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase m_OSSL_Functions.osNpcLoadAppearance(npc, notecard); } + public LSL_Key osNpcGetOwner(LSL_Key npc) + { + return m_OSSL_Functions.osNpcGetOwner(npc); + } + public vector osNpcGetPos(LSL_Key npc) { return m_OSSL_Functions.osNpcGetPos(npc); -- cgit v1.1