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.
iar_mods
Justin Clark-Casey (justincc) 2012-01-27 23:05:48 +00:00
parent 093469c33c
commit 9939f94f08
4 changed files with 55 additions and 19 deletions

View File

@ -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<INPCModule>();
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) public LSL_Vector osNpcGetPos(LSL_Key npc)
{ {
CheckThreatLevel(ThreatLevel.High, "osNpcGetPos"); CheckThreatLevel(ThreatLevel.High, "osNpcGetPos");

View File

@ -180,6 +180,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
vector osNpcGetPos(key npc); vector osNpcGetPos(key npc);
void osNpcMoveTo(key npc, vector position); void osNpcMoveTo(key npc, vector position);
void osNpcMoveToTarget(key npc, vector target, int options); void osNpcMoveToTarget(key npc, vector target, int options);
/// <summary>
/// Get the owner of the NPC
/// </summary>
/// <param name="npc"></param>
/// <returns>
/// 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.
/// </returns>
LSL_Key osNpcGetOwner(key npc);
rotation osNpcGetRot(key npc); rotation osNpcGetRot(key npc);
void osNpcSetRot(LSL_Key npc, rotation rot); void osNpcSetRot(LSL_Key npc, rotation rot);
void osNpcStopMoveToTarget(LSL_Key npc); void osNpcStopMoveToTarget(LSL_Key npc);

View File

@ -513,6 +513,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
m_OSSL_Functions.osNpcLoadAppearance(npc, notecard); 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) public vector osNpcGetPos(LSL_Key npc)
{ {
return m_OSSL_Functions.osNpcGetPos(npc); return m_OSSL_Functions.osNpcGetPos(npc);