mirror of
https://github.com/danbulant/flying-squid
synced 2026-07-06 19:50:40 +00:00
create an entity.attach, some more selector fixes, and add a fun /pile <entities> command (that will go in a plugin later)
This commit is contained in:
parent
ce1ffe9c4f
commit
47c75671c4
2 changed files with 46 additions and 14 deletions
|
|
@ -106,8 +106,7 @@ module.exports.player=function(player, serv) {
|
||||||
},
|
},
|
||||||
action(sel) {
|
action(sel) {
|
||||||
var arr = serv.selectorString(sel, player.position.scaled(1/32), player.world);
|
var arr = serv.selectorString(sel, player.position.scaled(1/32), player.world);
|
||||||
if (arr == null) return 'Could not find player';
|
player.chat(JSON.stringify(arr.map(a => a.id)));
|
||||||
else player.chat(JSON.stringify(arr.map(a => a.id)));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -234,13 +233,13 @@ module.exports.server = function(serv) {
|
||||||
|
|
||||||
if (count > 0) return sample.slice(0, count);
|
if (count > 0) return sample.slice(0, count);
|
||||||
else return sample.slice(count); // Negative, returns from end
|
else return sample.slice(count); // Negative, returns from end
|
||||||
}
|
};
|
||||||
|
|
||||||
serv.selectorString = (str, pos, world, allowUser=true) => {
|
serv.selectorString = (str, pos, world, allowUser=true) => {
|
||||||
pos = pos.clone();
|
pos = pos.clone();
|
||||||
var player = serv.getPlayer(str);
|
var player = serv.getPlayer(str);
|
||||||
if (!player && str[0] != '@') return null;
|
if (!player && str[0] != '@') return [];
|
||||||
else if (player) return allowUser ? [player] : null;
|
else if (player) return allowUser ? [player] : [];
|
||||||
var match = str.match(/^@([a,r,p,e])(?:\[([^\]]+)\])?$/);
|
var match = str.match(/^@([a,r,p,e])(?:\[([^\]]+)\])?$/);
|
||||||
if (match == null) throw new UserError('Invalid selector format');
|
if (match == null) throw new UserError('Invalid selector format');
|
||||||
var typeConversion = {
|
var typeConversion = {
|
||||||
|
|
@ -296,7 +295,7 @@ module.exports.server = function(serv) {
|
||||||
});
|
});
|
||||||
|
|
||||||
return serv.selector(type, data);
|
return serv.selector(type, data);
|
||||||
}
|
};
|
||||||
|
|
||||||
serv.posFromString = (str, pos) => {
|
serv.posFromString = (str, pos) => {
|
||||||
if (parseInt(str)) return parseInt(str);
|
if (parseInt(str)) return parseInt(str);
|
||||||
|
|
@ -304,4 +303,4 @@ module.exports.server = function(serv) {
|
||||||
else if (str == '~') return pos;
|
else if (str == '~') return pos;
|
||||||
else throw new UserError('Invalid position');
|
else throw new UserError('Invalid position');
|
||||||
};
|
};
|
||||||
}
|
};
|
||||||
|
|
@ -59,6 +59,7 @@ module.exports.server=function(serv,options) {
|
||||||
mob.metadata = metadata;
|
mob.metadata = metadata;
|
||||||
|
|
||||||
mob.updateAndSpawn();
|
mob.updateAndSpawn();
|
||||||
|
return mob;
|
||||||
};
|
};
|
||||||
|
|
||||||
serv.destroyEntity = entity => {
|
serv.destroyEntity = entity => {
|
||||||
|
|
@ -126,6 +127,32 @@ module.exports.player=function(player,serv){
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
player.commands.add({
|
||||||
|
base: 'pile',
|
||||||
|
info: 'make a pile of entities',
|
||||||
|
usage: '/pile <entities types>',
|
||||||
|
op: true,
|
||||||
|
parse(str) {
|
||||||
|
var args=str.split(' ');
|
||||||
|
if(args.length==0)
|
||||||
|
return false;
|
||||||
|
return args
|
||||||
|
.map(name => entitiesByName[name])
|
||||||
|
.filter(entity => !!entity);
|
||||||
|
},
|
||||||
|
action(entityTypes) {
|
||||||
|
entityTypes.map(entity =>
|
||||||
|
serv.spawnMob(entity.id, player.world, player.position.scaled(1/32), {
|
||||||
|
velocity: Vec3((Math.random() - 0.5) * 10, Math.random()*10 + 10, (Math.random() - 0.5) * 10)
|
||||||
|
}))
|
||||||
|
.reduce((prec,entity) => {
|
||||||
|
if(prec!=null)
|
||||||
|
prec.attach(entity);
|
||||||
|
return entity;
|
||||||
|
},null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
player.commands.add({
|
player.commands.add({
|
||||||
base: 'attach',
|
base: 'attach',
|
||||||
info: 'attach an entity on an other entity',
|
info: 'attach an entity on an other entity',
|
||||||
|
|
@ -144,13 +171,7 @@ module.exports.player=function(player,serv){
|
||||||
return {carrier:carrier[0],attached:attached[0]};
|
return {carrier:carrier[0],attached:attached[0]};
|
||||||
},
|
},
|
||||||
action({carrier,attached}) {
|
action({carrier,attached}) {
|
||||||
var p={
|
carrier.attach(attached);
|
||||||
entityId:attached.id,
|
|
||||||
vehicleId:carrier.id,
|
|
||||||
leash:false
|
|
||||||
};
|
|
||||||
player._client.write('attach_entity',p);
|
|
||||||
player._writeOthersNearby('attach_entity',p);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -281,4 +302,16 @@ module.exports.entity=function(entity,serv) {
|
||||||
serv.destroyEntity(entity);
|
serv.destroyEntity(entity);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
entity.attach= (attachedEntity,leash=false) =>
|
||||||
|
{
|
||||||
|
var p={
|
||||||
|
entityId:attachedEntity.id,
|
||||||
|
vehicleId:entity.id,
|
||||||
|
leash:leash
|
||||||
|
};
|
||||||
|
if(entity.type=='player')
|
||||||
|
entity._client.write('attach_entity',p);
|
||||||
|
entity._writeOthersNearby('attach_entity',p);
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
Loading…
Reference in a new issue