Hey,
Im just wondering how would i use commands with specifying players.
For example, if i an going to ban someone using ULX, i would type
!ban {player} {time} {reason}
How do the player, time and reason arguments get processed?
Thanks!
[QUOTE=Livaco;52616801]Hey,
Im just wondering how would i use commands with specifying players.
For example, if i an going to ban someone using ULX, i would type
!ban {player} {time} {reason}
How do the player, time and reason arguments get processed?
Thanks![/QUOTE]
A naive way to do it would be [URL="https://www.lua.org/pil/20.2.html"]lua patterns[/URL]:
[code]
hook.Add("PlayerSay","my_shitty_ban",function(sender,text,_)
--Only admins can ban
if not sender:IsAdmin() then return end
--Get the arguments out of the text
local _,_,playername,time,reason = text:find("!shitban (%w+) (%d+) (.+)$")
--Find the player with the same name
for k,v in pairs(player.GetAll()) do
if v:Name() == playername then
--And ban them
v:Ban(time)
end
end
end
[/code]
This code has some serious flaws (like not being able to specify players with a space, then numbers in their name).
[QUOTE=Apickx;52617359]A naive way to do it would be [URL="https://www.lua.org/pil/20.2.html"]lua patterns[/URL]:
[code]
hook.Add("PlayerSay","my_shitty_ban",function(sender,text,_)
--Only admins can ban
if not sender:IsAdmin() then return end
--Get the arguments out of the text
local _,_,playername,time,reason = text:find("!shitban (%w+) (%d+) (.+)$")
--Find the player with the same name
for k,v in pairs(player.GetAll()) do
if v:Name() == playername then
--And ban them
v:Ban(time)
end
end
end
[/code]
This code has some serious flaws (like not being able to specify players with a space, then numbers in their name).[/QUOTE]
Thanks, that helped alot
Sorry, you need to Log In to post a reply to this thread.