From 9b2a4e81722d49ddb6552e279c355e13b8ed2b63 Mon Sep 17 00:00:00 2001
From: MW
Date: Tue, 3 Apr 2007 18:15:11 +0000
Subject: Added easier way to add "scripts" to prims: to add Libsa71's test
script, create a new note and delete the contents of the created note and
then add "" (without the quotes) , then save that and
then drag it from your inventory to the prim you want to add the script to.
---
OpenSim.RegionServer/SimClient.cs | 26 +++++++++++++++
OpenSim.RegionServer/world/World.cs | 63 ++++++++++++++++++++++++++++++++++++-
2 files changed, 88 insertions(+), 1 deletion(-)
(limited to 'OpenSim.RegionServer')
diff --git a/OpenSim.RegionServer/SimClient.cs b/OpenSim.RegionServer/SimClient.cs
index 58cc625..6c64731 100644
--- a/OpenSim.RegionServer/SimClient.cs
+++ b/OpenSim.RegionServer/SimClient.cs
@@ -436,6 +436,32 @@ namespace OpenSim
this.OutPacket(replytask);
}
break;
+ case PacketType.UpdateTaskInventory:
+ Console.WriteLine(Pack.ToString());
+ UpdateTaskInventoryPacket updatetask = (UpdateTaskInventoryPacket)Pack;
+ AgentInventory myinventory = this.m_inventoryCache.GetAgentsInventory(this.AgentID);
+ if (myinventory != null)
+ {
+ if (myinventory.InventoryItems[updatetask.InventoryData.ItemID] != null)
+ {
+ if (myinventory.InventoryItems[updatetask.InventoryData.ItemID].Type == 7)
+ {
+ LLUUID noteaid = myinventory.InventoryItems[updatetask.InventoryData.ItemID].AssetID;
+ AssetBase assBase = this.m_assetCache.GetAsset(noteaid);
+ if (assBase != null)
+ {
+ foreach (Entity ent in m_world.Entities.Values)
+ {
+ if (ent.localid == updatetask.UpdateData.LocalID)
+ {
+ this.m_world.AddScript(ent, Helpers.FieldToString(assBase.Data));
+ }
+ }
+ }
+ }
+ }
+ }
+ break;
case PacketType.AgentAnimation:
//Console.WriteLine(Pack.ToString());
break;
diff --git a/OpenSim.RegionServer/world/World.cs b/OpenSim.RegionServer/world/World.cs
index 6bc485f..408f68d 100644
--- a/OpenSim.RegionServer/world/World.cs
+++ b/OpenSim.RegionServer/world/World.cs
@@ -32,18 +32,20 @@ namespace OpenSim.world
private int storageCount;
private Dictionary m_clientThreads;
private Dictionary m_scriptHandlers;
+ private Dictionary m_scripts;
private ulong m_regionHandle;
private string m_regionName;
private InventoryCache _inventoryCache;
private AssetCache _assetCache;
public World(Dictionary clientThreads, ulong regionHandle, string regionName)
- {
+ {
m_clientThreads = clientThreads;
m_regionHandle = regionHandle;
m_regionName = regionName;
m_scriptHandlers = new Dictionary();
+ m_scripts = new Dictionary();
OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs - creating new entitities instance");
Entities = new Dictionary();
@@ -55,6 +57,7 @@ namespace OpenSim.world
// Initialise this only after the world has loaded
// Scripts = new ScriptEngine(this);
Avatar.LoadAnims();
+ this.SetDefaultScripts();
}
public void AddScript(Entity entity, Script script)
@@ -63,6 +66,37 @@ namespace OpenSim.world
m_scriptHandlers.Add(scriptHandler.ScriptId, scriptHandler);
}
+ public void AddScript(Entity entity, string scriptData)
+ {
+ int scriptstart = 0;
+ int scriptend = 0;
+ string substring;
+ scriptstart = scriptData.LastIndexOf("");
+ substring = scriptData.Substring(scriptstart + 8, scriptend - scriptstart - 8);
+ substring = substring.Trim();
+ Console.WriteLine("searching for script to add: " + substring);
+ if (this.m_scripts.ContainsKey(substring))
+ {
+ Console.WriteLine("added script");
+ this.AddScript(entity, this.m_scripts[substring]);
+ }
+ /*string delimStr = " ";
+ char[] delimiter = delimStr.ToCharArray();
+ string[] line;
+ line = scriptData.Split(delimiter);
+ if (line.Length > 1)
+ {
+ if (line[0] == "script:")
+ {
+ if (this.m_scripts.ContainsKey(line[1]))
+ {
+ this.AddScript(entity, this.m_scripts[line[1]]);
+ }
+ }
+ }*/
+ }
+
public InventoryCache InventoryCache
{
set
@@ -521,6 +555,33 @@ namespace OpenSim.world
return true;
}
+ public void SetDefaultScripts()
+ {
+ this.m_scripts.Add("Test", new TestScript1());
+ }
+
#endregion
}
+
+ public class TestScript1 : Script
+ {
+ int toggle = 0;
+
+ public TestScript1()
+ : base(LLUUID.Random())
+ {
+ OnFrame += MyOnFrame;
+ }
+
+ private void MyOnFrame(IScriptContext context)
+ {
+ toggle = 2 - toggle;
+
+ LLVector3 pos = context.GetPos();
+
+ pos.X += (toggle - 1);
+
+ context.MoveTo(pos);
+ }
+ }
}
--
cgit v1.1