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 "<Script>Test</Script>" (without the quotes) , then save that and then drag it from your inventory to the prim you want to add the script to.

0.1-prestable
MW 2007-04-03 18:15:11 +00:00
parent 5ab7205dc5
commit 9b2a4e8172
2 changed files with 88 additions and 1 deletions

View File

@ -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;

View File

@ -32,18 +32,20 @@ namespace OpenSim.world
private int storageCount;
private Dictionary<uint, SimClient> m_clientThreads;
private Dictionary<LLUUID, ScriptHandler> m_scriptHandlers;
private Dictionary<string, Script> m_scripts;
private ulong m_regionHandle;
private string m_regionName;
private InventoryCache _inventoryCache;
private AssetCache _assetCache;
public World(Dictionary<uint, SimClient> clientThreads, ulong regionHandle, string regionName)
{
{
m_clientThreads = clientThreads;
m_regionHandle = regionHandle;
m_regionName = regionName;
m_scriptHandlers = new Dictionary<LLUUID, ScriptHandler>();
m_scripts = new Dictionary<string, Script>();
OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs - creating new entitities instance");
Entities = new Dictionary<libsecondlife.LLUUID, Entity>();
@ -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("<Script>");
scriptend = scriptData.LastIndexOf("</Script>");
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);
}
}
}