etlegacy-lua-scripts/ladm/core/commands.lua

56 lines
No EOL
1.8 KiB
Lua

require "core/user"
require "core/db"
Command = {}
-- Heads or tails
Command["cointoss"] = function(cno, cmd)
local player = getPlayerName( cno )
local number = math.random( 0, 99 )
math.randomseed( os.time() )
et.G_Print( "cointoss: " .. player .. " " .. number .. "\n" )
et.trap_SendServerCommand ( -1, "chat \"" .. player .. "^7 tossed a coin...\"" )
if number < 49 then
et.trap_SendServerCommand ( -1, "chat \"Heads.\"" )
elseif number > 50 then
et.trap_SendServerCommand ( -1, "chat \"Tails.\"" )
elseif number == 49 then
et.trap_SendServerCommand ( -1, "chat \"The coin falls on its side!\"" )
elseif number == 50 then
et.trap_SendServerCommand ( -1, "chat \"A gypsy stole the coin.\"" )
end
end
-- Private message
Command["pm"] = function(cno, cmd)
if tonumber( et.trap_Argc() ) < 3 then
et.trap_SendServerCommand( cno, "chat \"Usage: pm name message\"" )
return(1)
end
local recipient_name = string.lower( et.Q_CleanStr( et.trap_Argv(1) ) )
if recipient_name then
for i=0, tonumber( et.trap_Cvar_Get( "sv_maxclients" ) )-1 do
local player_name = getPlayerName( i )
if player_name then
local sender_name = getPlayerName( cno )
s, e = string.find( string.lower( et.Q_CleanStr( player_name ) ), recipient_name )
if s and e then
if i ~= cno then -- PMing yourself?
et.trap_SendServerCommand( i, "chat \"" .. sender_name .. "^7 -> " .. player_name .. "^7: ^5" .. et.ConcatArgs(2) .. "\"" )
et.trap_SendServerCommand( cno, "chat \"" .. sender_name .. "^7 -> " .. player_name .. "^7: ^5" .. et.ConcatArgs(2) .. "\"" )
return(1) -- send only to the first player matched
end
end
end
end
et.trap_SendServerCommand( cno, "chat \"No player whose name matches the pattern \'" .. recipient_name .. "\' was found.\"" )
return(1)
end
end