public ControllerData[] Serialize()
            {
                lock (scriptedcontrols)
                {
                    ControllerData[] controls = new ControllerData[scriptedcontrols.Count];
                    int i = 0;

                    foreach (ScriptControllers c in scriptedcontrols.Values)
                    {
                        controls[i++] = new ControllerData(c.itemID, c.part.UUID, (uint) c.ignoreControls,
                                                           (uint) c.eventControls);
                    }
                    return controls;
                }
            }
        public override void FromOSD(OSDMap args)
        {
            if (args.ContainsKey("region_id"))
            {
                UUID.TryParse(args["region_id"].AsString(), out RegionID);
            }

            if (args["circuit_code"] != null)
            {
                UInt32.TryParse(args["circuit_code"].AsString(), out CircuitCode);
            }

            if (args["agent_uuid"] != null)
            {
                AgentID = args["agent_uuid"].AsUUID();
            }

            if (args["session_uuid"] != null)
            {
                SessionID = args["session_uuid"].AsUUID();
            }

            if (args["position"] != null)
            {
                Vector3.TryParse(args["position"].AsString(), out Position);
            }

            if (args["velocity"] != null)
            {
                Vector3.TryParse(args["velocity"].AsString(), out Velocity);
            }

            if (args["center"] != null)
            {
                Vector3.TryParse(args["center"].AsString(), out Center);
            }

            if (args["size"] != null)
            {
                Vector3.TryParse(args["size"].AsString(), out Size);
            }

            if (args["at_axis"] != null)
            {
                Vector3.TryParse(args["at_axis"].AsString(), out AtAxis);
            }

            if (args["left_axis"] != null)
            {
                Vector3.TryParse(args["left_axis"].AsString(), out AtAxis);
            }

            if (args["up_axis"] != null)
            {
                Vector3.TryParse(args["up_axis"].AsString(), out AtAxis);
            }

            if (args["far"] != null)
            {
                Far = (float)(args["far"].AsReal());
            }

            if (args["aspect"] != null)
            {
                Aspect = (float)args["aspect"].AsReal();
            }

            if (args["throttles"] != null)
            {
                Throttles = args["throttles"].AsBinary();
            }

            if (args["locomotion_state"] != null)
            {
                UInt32.TryParse(args["locomotion_state"].AsString(), out LocomotionState);
            }

            if (args["head_rotation"] != null)
            {
                Quaternion.TryParse(args["head_rotation"].AsString(), out HeadRotation);
            }

            if (args["body_rotation"] != null)
            {
                Quaternion.TryParse(args["body_rotation"].AsString(), out BodyRotation);
            }

            if (args["control_flags"] != null)
            {
                UInt32.TryParse(args["control_flags"].AsString(), out ControlFlags);
            }

            if (args["energy_level"] != null)
            {
                EnergyLevel = (float)(args["energy_level"].AsReal());
            }

            //This IS checked later
            if (args["god_level"] != null)
            {
                Byte.TryParse(args["god_level"].AsString(), out GodLevel);
            }

            if (args["speed"] != null)
            {
                float.TryParse(args["speed"].AsString(), out Speed);
            }
            else
            {
                Speed = 1;
            }

            if (args["draw_distance"] != null)
            {
                float.TryParse(args["draw_distance"].AsString(), out DrawDistance);
            }
            else
            {
                DrawDistance = 0;
            }

            //Reset this to fix movement... since regions are being bad about this
            if (Speed == 0)
            {
                Speed = 1;
            }

            if (args["always_run"] != null)
            {
                AlwaysRun = args["always_run"].AsBoolean();
            }

            SentInitialWearables = args["sent_initial_wearables"] != null && args["sent_initial_wearables"].AsBoolean();

            if (args["prey_agent"] != null)
            {
                PreyAgent = args["prey_agent"].AsUUID();
            }

            if (args["agent_access"] != null)
            {
                Byte.TryParse(args["agent_access"].AsString(), out AgentAccess);
            }

            if (args["active_group_id"] != null)
            {
                ActiveGroupID = args["active_group_id"].AsUUID();
            }

            if (args["IsCrossing"] != null)
            {
                IsCrossing = args["IsCrossing"].AsBoolean();
            }

            if ((args["animations"] != null) && (args["animations"]).Type == OSDType.Array)
            {
                OSDArray anims = (OSDArray)(args["animations"]);
                Anims = new Animation[anims.Count];
                int i = 0;

                foreach (OSD o in anims.Where(o => o.Type == OSDType.Map))
                {
                    Anims[i++] = new Animation((OSDMap)o);
                }
            }

            Appearance = new AvatarAppearance(AgentID);

            try
            {
                if (args.ContainsKey("packed_appearance") && (args["packed_appearance"]).Type == OSDType.Map)
                {
                    Appearance = new AvatarAppearance(AgentID, (OSDMap)args["packed_appearance"]);
                }
                // DEBUG ON
                else
                {
                    MainConsole.Instance.Warn("[CHILDAGENTDATAUPDATE] No packed appearance");
                }
                // DEBUG OFF
            }
            catch
            {
            }

            if ((args["controllers"] != null) && (args["controllers"]).Type == OSDType.Array)
            {
                OSDArray controls = (OSDArray)(args["controllers"]);
                Controllers = new ControllerData[controls.Count];
                int i = 0;

                foreach (OSD o in controls.Where(o => o.Type == OSDType.Map))
                {
                    Controllers[i++] = new ControllerData((OSDMap)o);
                }
            }

            if (args["SittingObjects"] != null && args["SittingObjects"].Type == OSDType.Map)
            {
                SittingObjects = new SittingObjectData((OSDMap)args["SittingObjects"]);
            }
        }
            public void Deserialize(ControllerData[] controllerData)
            {
                lock (scriptedcontrols)
                {
                    scriptedcontrols.Clear();

                    foreach (ScriptControllers sc in controllerData.Select(c => new ScriptControllers
                                                                                    {
                                                                                        itemID = c.ItemID,
                                                                                        part =
                                                                                            m_sp.Scene
                                                                                                .GetSceneObjectPart(
                                                                                                    c.ObjectID),
                                                                                        ignoreControls =
                                                                                            (ScriptControlled)
                                                                                            c.IgnoreControls,
                                                                                        eventControls =
                                                                                            (ScriptControlled)
                                                                                            c.EventControls
                                                                                    }).Where(sc => sc.part != null))
                    {
                        scriptedcontrols[sc.itemID] = sc;
                    }
                }
            }
        public override void FromOSD(OSDMap args)
        {
            if (args.ContainsKey("region_id"))
                UUID.TryParse(args["region_id"].AsString(), out RegionID);

            if (args["circuit_code"] != null)
                UInt32.TryParse(args["circuit_code"].AsString(), out CircuitCode);

            if (args["agent_uuid"] != null)
                AgentID = args["agent_uuid"].AsUUID();

            if (args["session_uuid"] != null)
                SessionID = args["session_uuid"].AsUUID();

            if (args["position"] != null)
                Vector3.TryParse(args["position"].AsString(), out Position);

            if (args["velocity"] != null)
                Vector3.TryParse(args["velocity"].AsString(), out Velocity);

            if (args["center"] != null)
                Vector3.TryParse(args["center"].AsString(), out Center);

            if (args["size"] != null)
                Vector3.TryParse(args["size"].AsString(), out Size);

            if (args["at_axis"] != null)
                Vector3.TryParse(args["at_axis"].AsString(), out AtAxis);

            if (args["left_axis"] != null)
                Vector3.TryParse(args["left_axis"].AsString(), out AtAxis);

            if (args["up_axis"] != null)
                Vector3.TryParse(args["up_axis"].AsString(), out AtAxis);

            if (args["far"] != null)
                Far = (float) (args["far"].AsReal());

            if (args["aspect"] != null)
                Aspect = (float) args["aspect"].AsReal();

            if (args["throttles"] != null)
                Throttles = args["throttles"].AsBinary();

            if (args["locomotion_state"] != null)
                UInt32.TryParse(args["locomotion_state"].AsString(), out LocomotionState);

            if (args["head_rotation"] != null)
                Quaternion.TryParse(args["head_rotation"].AsString(), out HeadRotation);

            if (args["body_rotation"] != null)
                Quaternion.TryParse(args["body_rotation"].AsString(), out BodyRotation);

            if (args["control_flags"] != null)
                UInt32.TryParse(args["control_flags"].AsString(), out ControlFlags);

            if (args["energy_level"] != null)
                EnergyLevel = (float) (args["energy_level"].AsReal());

            //This IS checked later
            if (args["god_level"] != null)
                Byte.TryParse(args["god_level"].AsString(), out GodLevel);

            if (args["speed"] != null)
                float.TryParse(args["speed"].AsString(), out Speed);
            else
                Speed = 1;

            if (args["draw_distance"] != null)
                float.TryParse(args["draw_distance"].AsString(), out DrawDistance);
            else
                DrawDistance = 0;

            //Reset this to fix movement... since regions are being bad about this
            if (Speed == 0)
                Speed = 1;

            if (args["always_run"] != null)
                AlwaysRun = args["always_run"].AsBoolean();

            SentInitialWearables = args["sent_initial_wearables"] != null && args["sent_initial_wearables"].AsBoolean();

            if (args["prey_agent"] != null)
                PreyAgent = args["prey_agent"].AsUUID();

            if (args["agent_access"] != null)
                Byte.TryParse(args["agent_access"].AsString(), out AgentAccess);

            if (args["active_group_id"] != null)
                ActiveGroupID = args["active_group_id"].AsUUID();

            if (args["IsCrossing"] != null)
                IsCrossing = args["IsCrossing"].AsBoolean();

            if ((args["animations"] != null) && (args["animations"]).Type == OSDType.Array)
            {
                OSDArray anims = (OSDArray) (args["animations"]);
                Anims = new Animation[anims.Count];
                int i = 0;

                foreach (OSD o in anims.Where(o => o.Type == OSDType.Map))
                {
                    Anims[i++] = new Animation((OSDMap) o);
                }
            }

            Appearance = new AvatarAppearance(AgentID);

            try
            {
                if (args.ContainsKey("packed_appearance") && (args["packed_appearance"]).Type == OSDType.Map)
                    Appearance = new AvatarAppearance(AgentID, (OSDMap) args["packed_appearance"]);
                    // DEBUG ON
                else
                    MainConsole.Instance.Warn("[CHILDAGENTDATAUPDATE] No packed appearance");
                // DEBUG OFF
            }
            catch
            {
            }

            if ((args["controllers"] != null) && (args["controllers"]).Type == OSDType.Array)
            {
                OSDArray controls = (OSDArray) (args["controllers"]);
                Controllers = new ControllerData[controls.Count];
                int i = 0;

                foreach (OSD o in controls.Where(o => o.Type == OSDType.Map))
                {
                    Controllers[i++] = new ControllerData((OSDMap) o);
                }
            }

            if (args["SittingObjects"] != null && args["SittingObjects"].Type == OSDType.Map)
                SittingObjects = new SittingObjectData((OSDMap) args["SittingObjects"]);
        }