如何解决如何在 Sequelize 模型中创建临时对象?
大家好,我正在创建一些程序,当程序加载时,它需要从数据库中加载所有项目并将游戏对象分配给它们,游戏中未保存在数据库中的临时对象 照片:https://i.imgur.com/34y7yaQ.png 我 console.log(this),那个对象和我的游戏对象在那里,但后来不是。 当我尝试 Instance.object 时,它是未定义的,他没有被分配。
我怎样才能做到这一点,或者是否有任何方法可以在模型中定义不应该保存的对象?提前谢谢你!
MODEL(我把它加为 VIRTUAL,还是什么都没有)
frp.Items = frp.Database.define('Item',{
id: { type: DataTypes.INTEGER,autoIncrement: true,primaryKey: true },Item: { type: DataTypes.STRING },Quantity: { type: DataTypes.INTEGER,defaultValue: 1 },Entity: { type: DataTypes.INTEGER,defaultValue: -1 },Owner: { type: DataTypes.STRING,defaultValue: 0 },isWeapon: { type: DataTypes.TEXT,defaultValue: false },Ammo: { type: DataTypes.INTEGER,Last_Owner: { type: DataTypes.INTEGER,Position: {
type: DataTypes.TEXT,defaultValue: null,get: function () { return JSON.parse(this.getDataValue('Position')); },set: function (value) { this.setDataValue('Position',JSON.stringify(value)); }
},Rotation: {
type: DataTypes.TEXT,get: function () { return JSON.parse(this.getDataValue('Rotation')); },set: function (value) { this.setDataValue('Rotation',Dimension: { type: DataTypes.INTEGER,GameObject: {
type: DataTypes.VIRTUAL,set: function (x) {
this.setDataValue('GameObject',x);
},}
},{
timestamps: true,underscrored: true,createdAt: "Created_Date",updatedAt: "Update_Date",}
);
frp.Items.prototype.Refresh = function () {
if (this.Entity == ItemEntities.Ground) {
const Position = this.Position;
const Rotation = this.Rotation;
console.log(Position);
this.GameObject = mp.objects.new(ItemRegistry[this.Item].hash,new mp.Vector3(Position.x,Position.y,Position.z),{
rotation: new mp.Vector3(Rotation.x,Rotation.y,Rotation.z),alpha: 255,dimension: this.Dimension
});
this.GameObject.Item = this.id;
console.log('Turilo game object ' + this.GameObject.Item);
} else {
if (this.GameObject) {
this.GameObject.destroy();
}
}
};
正在加载
(async () => {
frp.Items.sync();
const Items = await frp.Items.findAll();
Items.forEach((Item) => {
Item.Refresh();
});
setTimeout(async () => {
const objs = await frp.Items.findAll();
objs.forEach((obj) => {
console.log(obj.GameObject) // RETURN UNDEFINED
})
},5000);
frp.Main.Terminal(3,Items.length + ' Items Loaded !');
})();
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。