Exemple #1
0
        public static Model LoadObject(int hash)
        {
            int counter = 0;
            var res = UIMenu.GetScreenResolutionMantainRatio();

            var m = new Model(hash);

            if (!m.IsValid || !m.IsInCdImage)
            {
                if (!ObjectDatabase.InvalidHashes.Contains(hash))
                {
                    ObjectDatabase.InvalidHashes.Add(hash);
                    ObjectDatabase.SaveInvalidHashes();
                }
                return null;
            }
            globalCounter++;
            var sc = new Scaleform(0);
            sc.Load("instructional_buttons");
            sc.CallFunction("CLEAR_ALL");
            sc.CallFunction("TOGGLE_MOUSE_BUTTONS", 0);
            sc.CallFunction("CREATE_CONTAINER");
            sc.CallFunction("SET_DATA_SLOT", 0, "b_50", Translation.Translate("Loading Model"));
            sc.CallFunction("DRAW_INSTRUCTIONAL_BUTTONS", -1);
            while (!m.IsLoaded && counter < 200)
            {
                m.Request();
                Script.Yield();
                counter++;
                sc.Render2D();
            }
            return m;
        }
        public ResizeDialog(Model model)
        {
            this.model = model;
            InitializeComponent();
            int width = model.Width;
            int height = model.Height;
            this.originalSizeLabel.Text = "Original Size: " + width + " by " + height;
            this.newWidth.Text = width + "";
            this.newHeight.Text = height + "";

            this.horizontalAnchor.SelectedIndex = 0;
            this.verticalAnchor.SelectedIndex = 0;

            this.okButton.Click += (sender, e) => { this.ChangeSize(); };
            this.cancelButton.Click += (sender, e) => { this.Close(); };
        }
Exemple #3
0
 public static Ped CreatePed(Model model, Vector3 position, float heading, bool dynamic, Quaternion q = null, int drawDistance = -1)
 {
     var veh = World.CreatePed(model, position, heading);
     Peds.Add(veh.Handle);
     if (!dynamic)
     {
         StaticProps.Add(veh.Handle);
         veh.FreezePosition = true;
     }
     if (q != null)
         Quaternion.SetEntityQuaternion(veh, q);
     if (drawDistance != -1)
         veh.LodDistance = drawDistance;
     UsedModels.Add(model.Hash);
     model.MarkAsNoLongerNeeded();
     return veh;
 }
Exemple #4
0
        public static DynamicPickup CreatePickup(Model model, Vector3 position, float heading, int amount, bool dynamic, Quaternion q = null)
        {
            var v_4 = 515;
            int newPickup = -1;

            if (Game.Player.Character.IsInRangeOf(position, 30f))
            {
                newPickup = Function.Call<int>(Hash.CREATE_PICKUP_ROTATE, model.Hash, position.X, position.Y,
                    position.Z, 0, 0, heading, v_4, amount, 0, false, 0);
            }

            var pcObj = new DynamicPickup(newPickup);
            pcObj.Flag = v_4;
            pcObj.Amount = amount;
            pcObj.RealPosition = position;
            if (newPickup != -1)
            {
                var start = 0;
                while (pcObj.ObjectHandle == -1 && start < 20)
                {
                    start++;
                    Script.Yield();
                }

                pcObj.Dynamic = false;
                new Prop(pcObj.ObjectHandle).IsPersistent = true;

                if (q != null)
                    Quaternion.SetEntityQuaternion(new Prop(pcObj.ObjectHandle), q);
                pcObj.UpdatePos();
            }

            Pickups.Add(pcObj);
            pcObj.PickupHash = model.Hash;
            pcObj.Timeout = 1;
            pcObj.UID = _pickupIds++;
            return pcObj;
        }
        public MapTypeDialog(Model model)
        {
            InitializeComponent();
            this.picker.SelectedIndex = model.IsSideScroll ? 0 : 1;

            this.okButton.Click += (sender, e) =>
            {
                bool isSidescroll = this.picker.SelectedIndex == 0;
                if (model.IsSideScroll != isSidescroll)
                {
                    model.IsSideScroll = isSidescroll;
                    model.IsDirty = true;
                    MainWindow.Instance.UpdateTitle();
                }
                this.Close();
            };

            this.cancelButton.Click += (sender, e) =>
            {
                this.DialogResult = false;
                this.Close();
            };
        }
Exemple #6
0
        public void ValidateDatabase()
        {
            // Validate object list.
            Dictionary<string, int> tmpDict = new Dictionary<string, int>();
            int counter = 0;
            while (counter < ObjectDatabase.MainDb.Count)
            {
                var pair = ObjectDatabase.MainDb.ElementAt(counter);
                counter++;
                UI.ShowSubtitle((counter) + "/" + ObjectDatabase.MainDb.Count + " done. (" +
                    (counter/(float) ObjectDatabase.MainDb.Count)*100 +
                    "%)\nValid objects: " + tmpDict.Count, 2000);
                Yield();

                var model = new Model(pair.Value);
                model.Request(100);
                if (!model.IsLoaded)
                {
                    model.MarkAsNoLongerNeeded();
                    continue;
                }
                model.MarkAsNoLongerNeeded();
                if (!tmpDict.ContainsKey(pair.Key))
                    tmpDict.Add(pair.Key, pair.Value);
            }
            string output = tmpDict.Aggregate("", (current, pair) => current + (pair.Key + "=" + pair.Value + "\r\n"));
            File.WriteAllText("scripts\\ObjectList.ini", output);
        }
Exemple #7
0
        public static Vehicle CreateVehicle(Model model, Vector3 position, float heading, bool dynamic, Quaternion q = null, int drawDistance = -1)
        {
            Vehicle veh;
            int counter = 0;
            do
            {
                veh = World.CreateVehicle(model, position, heading);
                counter++;
            } while (veh == null && counter < 2000);

            if (veh == null)
            {
                UI.Notify("~r~~h~Map Editor~h~~w~~n~I tried very hard, but the vehicle failed to load.");
                return null;
            }

            Vehicles.Add(veh.Handle);
            if (!dynamic)
            {
                StaticProps.Add(veh.Handle);
                veh.FreezePosition = true;
            }
            if(q != null)
                Quaternion.SetEntityQuaternion(veh, q);
            if (drawDistance != -1)
                veh.LodDistance = drawDistance;
            UsedModels.Add(model.Hash);
            model.MarkAsNoLongerNeeded();
            return veh;
        }
Exemple #8
0
        public static Prop CreateProp(Model model, Vector3 position, Vector3 rotation, bool dynamic, Quaternion q = null, bool force = false, int drawDistance = -1)
        {
            if (StreamedInHandles.Count >= MAX_OBJECTS)
            {
                UI.Notify("~r~~h~Map Editor~h~~w~\nYou have reached the prop limit. You cannot place any more props.");
                return null;
            }

            if (PropCount > 0 && PropCount % 249 == 0)
                Script.Wait(100);

            var prop = new Prop(Function.Call<int>(Hash.CREATE_OBJECT_NO_OFFSET, model.Hash, position.X, position.Y, position.Z, true, true, dynamic));
            prop.Rotation = rotation;
            StreamedInHandles.Add(prop.Handle);
            if (!dynamic)
            {
                StaticProps.Add(prop.Handle);
                prop.FreezePosition = true;
            }
            if (q != null)
                Quaternion.SetEntityQuaternion(prop, q);
            prop.Position = position;
            if (drawDistance != -1)
                prop.LodDistance = drawDistance;
            UsedModels.Add(model.Hash);
            model.MarkAsNoLongerNeeded();
            return prop;
        }
        public Model Parse()
        {
            Dictionary<string, string> values = new Dictionary<string, string>();
            string[] lines = System.IO.File.ReadAllText(this.filename).Replace("\r\n", "\n").Replace('\r', '\n').Split('\n');
            foreach (string line in lines)
            {
                string[] parts = line.Split(':');
                if (parts.Length >= 2)
                {
                    string key = parts[0];
                    if (key.Length > 0 && key[0] == '#')
                    {
                        key = key.Substring(1);
                        string value = parts[1];
                        for (int i = 2; i < parts.Length; ++i)
                        {
                            value += ':' + parts[i];
                        }

                        values[key] = value;
                    }
                }
            }

            int width = int.Parse(values["width"]);
            int height = int.Parse(values["height"]); // let it crash if this is wrong.

            Model model = new Model(width, height);

            TileTemplate[] topLayer = new TileTemplate[width * height];
            TileTemplate[] bottomLayer = new TileTemplate[width * height];

            string[] tileIdsUpper = values["upper"].Split(',');
            string[] tileIdsLower = values["lower"].Split(',');

            for (int i = width * height - 1; i >= 0; --i)
            {
                string tileId = tileIdsUpper[i].Trim();
                if (tileId.Length > 0)
                {
                    topLayer[i] = this.tileLookup[tileId];
                }

                tileId = tileIdsLower[i].Trim();
                if (tileId.Length > 0)
                {
                    bottomLayer[i] = this.tileLookup[tileId];
                }
            }

            // TODO: other fields

            model.SetTiles(topLayer, true);
            model.SetTiles(bottomLayer, false);

            model.SetRawFileData(values);

            model.Path = filename;
            model.IsSideScroll = !values.ContainsKey("view") || values["view"].Trim().ToLowerInvariant() != "over";

            return model;
        }