More changes
This commit is contained in:
parent
2ebe549340
commit
8fdb82fd94
@ -317,69 +317,3 @@ PyuTest.drop_item = function(pos, name)
|
||||
o:add_velocity(vector.new(math.random(-2, 2), 5, math.random(-2, 2)))
|
||||
end
|
||||
end
|
||||
|
||||
PyuTest.chatcommand_entity_selector = function(caller, param)
|
||||
local p_caller = core.get_player_by_name(caller)
|
||||
|
||||
if core.get_player_by_name(param) ~= nil then
|
||||
return {param}
|
||||
end
|
||||
|
||||
if param == "@self" or param == "@s" then
|
||||
return {caller}
|
||||
elseif param == "@random" or param == "@r" then
|
||||
local players = core.get_connected_players()
|
||||
return {players[math.random(#players)]:get_player_name()}
|
||||
elseif param == "@nearest" or param == "@n" then
|
||||
local players = core.get_connected_players()
|
||||
local pos = p_caller:get_pos()
|
||||
local cd = math.huge
|
||||
local nearest
|
||||
|
||||
for _, v in pairs(players) do
|
||||
local dist = vector.distance(pos, v:get_pos())
|
||||
|
||||
if dist < cd and v ~= p_caller then
|
||||
cd = dist
|
||||
nearest = v
|
||||
end
|
||||
end
|
||||
|
||||
if nearest then
|
||||
return {nearest:get_player_name()}
|
||||
end
|
||||
elseif param == "@all" or param == "@a" then
|
||||
local list = {}
|
||||
|
||||
for _, v in pairs(core.get_connected_players()) do
|
||||
list[#list+1] = v:get_player_name()
|
||||
end
|
||||
|
||||
return list
|
||||
end
|
||||
|
||||
return {caller}
|
||||
end
|
||||
|
||||
PyuTest.execute_as = function(runner, command)
|
||||
local pos = command:find(" ")
|
||||
local cmd, param = command, ""
|
||||
if pos then
|
||||
cmd = command:sub(1, pos - 1)
|
||||
param = command:sub(pos + 1)
|
||||
end
|
||||
local cmddef = core.chatcommands[cmd]
|
||||
if not cmddef then
|
||||
core.chat_send_player(runner, "The command "..cmd.." does not exist")
|
||||
return
|
||||
end
|
||||
local has_privs, missing_privs = core.check_player_privs(runner, cmddef.privs)
|
||||
if not has_privs then
|
||||
core.chat_send_player(runner, "You don't have permission "
|
||||
.."to run "..cmd
|
||||
.." (missing privileges: "
|
||||
..table.concat(missing_privs, ", ")..")")
|
||||
return
|
||||
end
|
||||
cmddef.func(runner, param)
|
||||
end
|
||||
|
@ -64,7 +64,7 @@ core.register_entity("pyutest_fireworks:firework", {
|
||||
|
||||
local pos = self.object:get_pos()
|
||||
|
||||
for v in pairs(core.objects_inside_radius(pos, 3)) do
|
||||
for v in core.objects_inside_radius(pos, 3) do
|
||||
if v ~= self.object then
|
||||
PyuTest.deal_damage(v, 9, PyuTest.DAMAGE_TYPES.fireworks())
|
||||
end
|
||||
|
@ -1 +1 @@
|
||||
depends = pyutest_blocks
|
||||
depends = pyutest_blocks,pyutest_cmds
|
66
mods/PLAYER/pyutest_cmds/api.lua
Normal file
66
mods/PLAYER/pyutest_cmds/api.lua
Normal file
@ -0,0 +1,66 @@
|
||||
PyuTest.chatcommand_entity_selector = function(caller, param)
|
||||
local p_caller = core.get_player_by_name(caller)
|
||||
|
||||
if core.get_player_by_name(param) ~= nil then
|
||||
return {param}
|
||||
end
|
||||
|
||||
if param == "@self" or param == "@s" then
|
||||
return {caller}
|
||||
elseif param == "@random" or param == "@r" then
|
||||
local players = core.get_connected_players()
|
||||
return {players[math.random(#players)]:get_player_name()}
|
||||
elseif param == "@nearest" or param == "@n" then
|
||||
local players = core.get_connected_players()
|
||||
local pos = p_caller:get_pos()
|
||||
local cd = math.huge
|
||||
local nearest
|
||||
|
||||
for _, v in pairs(players) do
|
||||
local dist = vector.distance(pos, v:get_pos())
|
||||
|
||||
if dist < cd and v ~= p_caller then
|
||||
cd = dist
|
||||
nearest = v
|
||||
end
|
||||
end
|
||||
|
||||
if nearest then
|
||||
return {nearest:get_player_name()}
|
||||
end
|
||||
elseif param == "@all" or param == "@a" then
|
||||
local list = {}
|
||||
|
||||
for _, v in pairs(core.get_connected_players()) do
|
||||
list[#list+1] = v:get_player_name()
|
||||
end
|
||||
|
||||
return list
|
||||
end
|
||||
|
||||
return {caller}
|
||||
end
|
||||
|
||||
PyuTest.execute_as = function(runner, command)
|
||||
local pos = command:find(" ")
|
||||
local cmd, param = command, ""
|
||||
if pos then
|
||||
cmd = command:sub(1, pos - 1)
|
||||
param = command:sub(pos + 1)
|
||||
end
|
||||
local cmddef = core.chatcommands[cmd]
|
||||
if not cmddef then
|
||||
core.chat_send_player(runner, "The command "..cmd.." does not exist")
|
||||
return
|
||||
end
|
||||
local has_privs, missing_privs = core.check_player_privs(runner, cmddef.privs)
|
||||
if not has_privs then
|
||||
core.chat_send_player(runner, "You don't have permission "
|
||||
.."to run "..cmd
|
||||
.." (missing privileges: "
|
||||
..table.concat(missing_privs, ", ")..")")
|
||||
return
|
||||
end
|
||||
|
||||
return cmddef.func(runner, param)
|
||||
end
|
@ -1,19 +1,44 @@
|
||||
local modpath = core.get_modpath("pyutest_cmds")
|
||||
dofile(modpath .. "/api.lua")
|
||||
|
||||
|
||||
core.register_chatcommand("say", {
|
||||
params = "<text>",
|
||||
description = [[Say <text>
|
||||
There are some text replacement macros you can use.
|
||||
Here is a list of them:
|
||||
- %s: Replaced with your username]],
|
||||
- %n: Replaced with your username
|
||||
- %r: Replaced with some random player's name]],
|
||||
func = function(name, param)
|
||||
local str = param
|
||||
str = str:gsub("%%s", name)
|
||||
str = str:gsub("%%n", name)
|
||||
str = str:gsub("%%r", function ()
|
||||
return PyuTest.chatcommand_entity_selector(name, "@r")[1]
|
||||
end)
|
||||
str = str:gsub("$embed{([%w%p]+)}", function(input)
|
||||
return PyuTest.execute_as(name, input) or ""
|
||||
end)
|
||||
|
||||
core.chat_send_all(str)
|
||||
end
|
||||
})
|
||||
|
||||
core.register_chatcommand("getpos", {
|
||||
params = "<player>",
|
||||
description = "Return the position of <player>",
|
||||
func = function(name, param)
|
||||
local target = PyuTest.chatcommand_entity_selector(name, param)
|
||||
local player = core.get_player_by_name(target[1])
|
||||
|
||||
if not player then
|
||||
return ""
|
||||
end
|
||||
local pos = player:get_pos()
|
||||
|
||||
return string.format("%f %f %f", pos.x, pos.y, pos.z)
|
||||
end
|
||||
})
|
||||
|
||||
core.register_chatcommand("kill", {
|
||||
params = "<player>",
|
||||
description = "Kill <player>",
|
||||
|
Loading…
x
Reference in New Issue
Block a user