diff --git a/common/src/comp/stats.rs b/common/src/comp/stats.rs index 10813901ee..96230ca453 100644 --- a/common/src/comp/stats.rs +++ b/common/src/comp/stats.rs @@ -6,6 +6,7 @@ pub enum HealthSource { Attack { by: Uid }, // TODO: Implement weapon Suicide, Revive, + Command, Unknown, } diff --git a/server/src/cmd.rs b/server/src/cmd.rs index 9fe940055d..90fe706299 100644 --- a/server/src/cmd.rs +++ b/server/src/cmd.rs @@ -119,7 +119,13 @@ lazy_static! { handle_empty, ), ChatCommand::new( - "help", "", "/help: Display this message", handle_help) + "help", "", "/help: Display this message", handle_help), + ChatCommand::new( + "health", + "{}", + "/health : Set your current health", + handle_health, + ) ]; } @@ -205,6 +211,31 @@ fn handle_time(server: &mut Server, entity: EcsEntity, args: String, action: &Ch }; } +fn handle_health(server: &mut Server, entity: EcsEntity, args: String, action: &ChatCommand) { + let opt_hp = scan_fmt!(&args, action.arg_fmt, u32); + + match server + .state + .ecs_mut() + .write_storage::() + .get_mut(entity) + { + Some(stats) => match opt_hp { + Some(hp) => stats.health.set_to(hp, comp::HealthSource::Command), + None => { + server.clients.notify( + entity, + ServerMsg::Chat(String::from("You must specify health amount!")), + ); + } + }, + None => server.clients.notify( + entity, + ServerMsg::Chat(String::from("You have no position.")), + ), + } +} + fn handle_alias(server: &mut Server, entity: EcsEntity, args: String, action: &ChatCommand) { let opt_alias = scan_fmt!(&args, action.arg_fmt, String); match opt_alias {