public static Quaternion RotationYawPitchRoll(float pitch, float roll, float yaw) { Quaternion result = new Quaternion(); pitch = (float)VectorExtensions.DegToRad(pitch); roll = (float)VectorExtensions.DegToRad(roll); yaw = (float)VectorExtensions.DegToRad(yaw); float halfRoll = roll*0.5f; float sinRoll = (float) Math.Sin((double) halfRoll); float cosRoll = (float) Math.Cos((double) halfRoll); float halfPitch = pitch*0.5f; float sinPitch = (float) Math.Sin((double) halfPitch); float cosPitch = (float) Math.Cos((double) halfPitch); float halfYaw = yaw*0.5f; float sinYaw = (float) Math.Sin((double) halfYaw); float cosYaw = (float) Math.Cos((double) halfYaw); result.X = (cosYaw*sinPitch*cosRoll) + (sinYaw*cosPitch*sinRoll); result.Y = (sinYaw*cosPitch*cosRoll) - (cosYaw*sinPitch*sinRoll); result.Z = (cosYaw*cosPitch*sinRoll) - (sinYaw*sinPitch*cosRoll); result.W = (cosYaw*cosPitch*cosRoll) + (sinYaw*sinPitch*sinRoll); return result; }
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; }
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 static void SetEntityQuaternion(Entity ent, Quaternion q) { Function.Call(Hash.SET_ENTITY_QUATERNION, ent.Handle, q.X, q.Y, q.Z, q.W); }
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; }
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; }