diff --git a/resources/scripts/commands/gm/GiveItem.lua b/resources/scripts/commands/gm/GiveItem.lua new file mode 100644 index 0000000..62cc64c --- /dev/null +++ b/resources/scripts/commands/gm/GiveItem.lua @@ -0,0 +1,9 @@ +required_rank = GM_RANK_DEBUG +command_sender = "[item] " + +function onCommand(args, player) + local id = args[1] + + player:add_item(id) + printf(player, "Added %s to your inventory.", id) +end diff --git a/src/world/connection.rs b/src/world/connection.rs index beac01c..5dc8c98 100644 --- a/src/world/connection.rs +++ b/src/world/connection.rs @@ -780,6 +780,13 @@ impl ZoneConnection { .await; } } + Task::AddItem { id } => { + self.player_data.inventory.add_in_next_free_slot(Item { + id: *id, + quantity: 1, + }); + self.send_inventory(false).await; + } } } player.queued_tasks.clear(); diff --git a/src/world/lua.rs b/src/world/lua.rs index 39d5b9b..d01b4c5 100644 --- a/src/world/lua.rs +++ b/src/world/lua.rs @@ -33,6 +33,7 @@ pub enum Task { ChangeWeather { id: u16 }, AddGil { amount: u32 }, UnlockOrchestrion { id: u16, on: bool }, + AddItem { id: u32 }, } #[derive(Default, Clone)] @@ -248,6 +249,10 @@ impl LuaPlayer { on: unlocked == 1, }); } + + fn add_item(&mut self, id: u32) { + self.queued_tasks.push(Task::AddItem { id }); + } } impl UserData for LuaPlayer { @@ -379,6 +384,10 @@ impl UserData for LuaPlayer { this.unlock_orchestrion(unlock, id); Ok(()) }); + methods.add_method_mut("add_item", |_, this, id: u32| { + this.add_item(id); + Ok(()) + }); } fn add_fields>(fields: &mut F) {