-
Notifications
You must be signed in to change notification settings - Fork 187
Set Spawn command (continuation of #2374) #2447
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 14 commits
71459fe
3f5f294
58c00b7
9b0cc99
601c11c
08aab5f
7210271
112cd53
ebf6063
6abc4e5
bfc324a
446500d
dcd2644
ca614bb
6d6d88f
526e052
4a74ec2
77fa6db
2f64797
db7b006
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| const std = @import("std"); | ||
|
|
||
| const main = @import("main"); | ||
| const User = main.server.User; | ||
|
|
||
| pub const description = "Get or set the player spawnPoint"; | ||
Wunka marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| pub const usage = | ||
| \\/spawn | ||
| \\/spawn <x> <y> | ||
| \\/spawn <x> <y> <z> | ||
| ; | ||
|
|
||
| pub fn execute(args: []const u8, source: *User) void { | ||
| var x: ?f64 = null; | ||
| var y: ?f64 = null; | ||
| var z: ?f64 = null; | ||
| var split = std.mem.splitScalar(u8, args, ' '); | ||
| while(split.next()) |arg| { | ||
| if(arg.len == 0) break; | ||
| const num: f64 = std.fmt.parseFloat(f64, arg) catch { | ||
| source.sendMessage("#ff0000Expected number, found \"{s}\"", .{arg}); | ||
| return; | ||
| }; | ||
| if(x == null) { | ||
| x = num; | ||
| } else if(y == null) { | ||
| y = num; | ||
| } else if(z == null) { | ||
| z = num; | ||
| } else { | ||
| source.sendMessage("#ff0000Too many arguments for command /spawn", .{}); | ||
| return; | ||
| } | ||
| } | ||
| if(x == null or y == null) { | ||
|
||
| source.sendMessage("#ffff00{}", .{source.spawnPos}); | ||
| return; | ||
| } | ||
| if(z == null) { | ||
| z = source.player.pos[2]; | ||
| } | ||
| x = std.math.clamp(x.?, -1e9, 1e9); // TODO: Remove after #310 is implemented | ||
| y = std.math.clamp(y.?, -1e9, 1e9); | ||
| z = std.math.clamp(z.?, -1e9, 1e9); | ||
|
|
||
| source.spawnPos = .{x.?, y.?, z.?}; | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.