mirror of
https://github.com/danbulant/flying-squid
synced 2026-06-19 14:31:17 +00:00
Add ~ tp /tp, small fixes
This commit is contained in:
parent
6ab320e3bc
commit
127ef3c777
2 changed files with 24 additions and 10 deletions
|
|
@ -1,13 +1,19 @@
|
|||
var Vec3 = require("vec3").Vec3;
|
||||
|
||||
module.exports.player = (player, serv) => {
|
||||
|
||||
var getPos = (num, dir='x', p=player) => {
|
||||
if (num[0] == '~') return p.position[dir] + parseInt(num.slice(1, num.length) || 0)*32;
|
||||
else return parseInt(num);
|
||||
}
|
||||
|
||||
player.commands.add({
|
||||
base: 'teleport',
|
||||
aliases: ['tp'],
|
||||
info: 'to teleport a player',
|
||||
usage: '/teleport [target player] <destination player or x> [x] [y]',
|
||||
usage: '/teleport [target player] <destination player or x> [y] [z]',
|
||||
parse(str) {
|
||||
return str.match(/^(((\w* )?\d* \d* \d*)|(\w* \w*))$/) ? str.split(' ') : false;
|
||||
return str.match(/^(((\w* )?~?-?\d* ~?-?\d* ~?-?\d*)|(\w* \w*))$/) ? str.split(' ') : false;
|
||||
},
|
||||
action(args) {
|
||||
if(args.length === 2 && args[0] !== args[1]) {
|
||||
|
|
@ -19,14 +25,22 @@ module.exports.player = (player, serv) => {
|
|||
|
||||
player_from.teleport(player_to.position.clone());
|
||||
} else if(args.length === 3) {
|
||||
player.teleport(new Vec3(args[0]*32, args[1]*32, args[2]*32));
|
||||
let x = getPos(args[0], 'x');
|
||||
let y = getPos(args[1], 'y');
|
||||
let z = getPos(args[2], 'z');
|
||||
|
||||
player.teleport(new Vec3(x, y, z));
|
||||
} else if(args.length === 4) {
|
||||
let player_from;
|
||||
|
||||
if(!(player_from = serv.getPlayer(args[0])))
|
||||
return false;
|
||||
|
||||
player_from.teleport(new Vec3(args[1]*32, args[2]*32, args[3]*32));
|
||||
let x = getPos(args[0], 'x', player_from);
|
||||
let y = getPos(args[1], 'y', player_from);
|
||||
let z = getPos(args[2], 'z', player_from);
|
||||
|
||||
player_from.teleport(new Vec3(x, y, z));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -55,16 +55,16 @@ module.exports.player=function(player)
|
|||
return player.behavior('move', {
|
||||
onGround: onGround,
|
||||
position: newPosition
|
||||
}, async () => {
|
||||
}, async ({onGround, position}) => {
|
||||
if (player.position.distanceTo(new Vec3(0, 0, 0)) != 0) {
|
||||
var diff = newPosition.minus(player.position);
|
||||
var diff = position.minus(player.position);
|
||||
if(diff.abs().x>127 || diff.abs().y>127 || diff.abs().z>127)
|
||||
{
|
||||
player._writeOthersNearby('entity_teleport', {
|
||||
entityId:player.id,
|
||||
x: newPosition.x,
|
||||
y: newPosition.y,
|
||||
z: newPosition.z,
|
||||
x: position.x,
|
||||
y: position.y,
|
||||
z: position.z,
|
||||
yaw: player.yaw,
|
||||
pitch: player.pitch,
|
||||
onGround: onGround
|
||||
|
|
@ -80,7 +80,7 @@ module.exports.player=function(player)
|
|||
});
|
||||
}
|
||||
}
|
||||
player.position = newPosition;
|
||||
player.position = position;
|
||||
player.onGround = onGround;
|
||||
}, () => {
|
||||
player.sendPosition();
|
||||
|
|
|
|||
Loading…
Reference in a new issue