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.
parent
5ab7205dc5
commit
9b2a4e8172
|
@ -436,6 +436,32 @@ namespace OpenSim
|
||||||
this.OutPacket(replytask);
|
this.OutPacket(replytask);
|
||||||
}
|
}
|
||||||
break;
|
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:
|
case PacketType.AgentAnimation:
|
||||||
//Console.WriteLine(Pack.ToString());
|
//Console.WriteLine(Pack.ToString());
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -32,6 +32,7 @@ namespace OpenSim.world
|
||||||
private int storageCount;
|
private int storageCount;
|
||||||
private Dictionary<uint, SimClient> m_clientThreads;
|
private Dictionary<uint, SimClient> m_clientThreads;
|
||||||
private Dictionary<LLUUID, ScriptHandler> m_scriptHandlers;
|
private Dictionary<LLUUID, ScriptHandler> m_scriptHandlers;
|
||||||
|
private Dictionary<string, Script> m_scripts;
|
||||||
private ulong m_regionHandle;
|
private ulong m_regionHandle;
|
||||||
private string m_regionName;
|
private string m_regionName;
|
||||||
private InventoryCache _inventoryCache;
|
private InventoryCache _inventoryCache;
|
||||||
|
@ -44,6 +45,7 @@ namespace OpenSim.world
|
||||||
m_regionName = regionName;
|
m_regionName = regionName;
|
||||||
|
|
||||||
m_scriptHandlers = new Dictionary<LLUUID, ScriptHandler>();
|
m_scriptHandlers = new Dictionary<LLUUID, ScriptHandler>();
|
||||||
|
m_scripts = new Dictionary<string, Script>();
|
||||||
|
|
||||||
OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs - creating new entitities instance");
|
OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs - creating new entitities instance");
|
||||||
Entities = new Dictionary<libsecondlife.LLUUID, Entity>();
|
Entities = new Dictionary<libsecondlife.LLUUID, Entity>();
|
||||||
|
@ -55,6 +57,7 @@ namespace OpenSim.world
|
||||||
// Initialise this only after the world has loaded
|
// Initialise this only after the world has loaded
|
||||||
// Scripts = new ScriptEngine(this);
|
// Scripts = new ScriptEngine(this);
|
||||||
Avatar.LoadAnims();
|
Avatar.LoadAnims();
|
||||||
|
this.SetDefaultScripts();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddScript(Entity entity, Script script)
|
public void AddScript(Entity entity, Script script)
|
||||||
|
@ -63,6 +66,37 @@ namespace OpenSim.world
|
||||||
m_scriptHandlers.Add(scriptHandler.ScriptId, scriptHandler);
|
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
|
public InventoryCache InventoryCache
|
||||||
{
|
{
|
||||||
set
|
set
|
||||||
|
@ -521,6 +555,33 @@ namespace OpenSim.world
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetDefaultScripts()
|
||||||
|
{
|
||||||
|
this.m_scripts.Add("Test", new TestScript1());
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue