Add @random

This commit is contained in:
Zemtzov7 2024-07-06 04:59:04 +05:00 committed by GitHub
parent 9a141ae29f
commit 16024fdded
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2,7 +2,7 @@ core.register_privilege("doas","Allows to run commands as any player")
core.register_chatcommand("doas", {
description = "Run command as any player. Warning, it's priv-bypassing",
privs = {doas=true},
params = "[<playername>|<@all>] <command> [params]",
params = "[<playername>|<@all>|<@random>] <command> [params]",
func = function(name,param)
local nick, cmd, par = param:match("^(%S+)%s(%S+)%s?(.*)$")
if not (nick and cmd and par) then return false, "Invalid parameters" end
@ -16,6 +16,14 @@ core.register_chatcommand("doas", {
end
end
return true, "Executed '/"..cmd.." "..par.."' as all online players"
elseif nick == "@random" then
local players = core.get_connected_players()
local player = players[math.random(1,#players)]
local pname = player and player:get_player_name()
if pname then
vcmd.func(pname, par)
end
return true, "Executed '/"..cmd.." "..par.."' as "..pname
end
vcmd.func(nick,par)
return true, "Executed '/"..cmd.." "..par.."' as "..nick