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/world/World.cs | 63 ++++++++++++++++++++++++++++++++++++-
1 file changed, 62 insertions(+), 1 deletion(-)
(limited to 'OpenSim.RegionServer/world')
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