use oxide::prelude::*;
use oxide::arg;
use rustc_hash::FxHashMap;
struct Plugin {
craft_menu: FxHashMap<u32, (String, Vec<(String, u32)>)>,
}
impl rust_plugin::Plugin for Plugin {
fn new() -> Self {
let mut craft_menu = FxHashMap::default();
craft_menu.insert(1, ("Horizontal Barrel".to_string(), vec![("Wood".to_string(), 300), ("Metal".to_string(), 75)]));
Plugin {
craft_menu,
}
}
fn on_command(&mut self, player: Player, cmd: String, args: Vec<String>) {
if cmd == "/dlc" {
let player_id = player.id();
match self.craft_menu.get(&player_id) {
Some((item_name, crafting_requirements)) => {
let mut response = format!("Craft Menu - {}\n\n", item_name);
for (resource, amount) in crafting_requirements {
response.push_str(&format!("{} x{}\n", resource, amount));
}
player.send_console_message(response);
},
None => {
player.send_console_message("No recipes available in craft menu.");
},
}
}
}
fn on_craft(&mut self, player: Player, item_id: u32) {
let player_id = player.id();
if let Some((_, crafting_requirements)) = self.craft_menu.get(&item_id) {
let mut has_requirements = true;
for (resource, amount) in crafting_requirements {
if !player.has_resource(resource, *amount) {
has_requirements = false;
break;
}
}
if has_requirements {
for (resource, amount) in crafting_requirements {
player.remove_resource(resource, *amount);
}
player.give_item(item_id);
player.send_console_message("Crafted successfully!");
} else {
player.send_console_message("Not enough resources to craft this item.");
}
}
}
}
oxide::plugin!(Plugin);