Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Command functions:
- --[=[
- local function command_name(event, pPlayer, pMessage, pType, pLanguage, pMisc, MSG) -- Change command_name to your custom command's name
- -- do something
- -- MSG[1] is the command name and first argument is MSG[2], second is MSG[3].
- -- example of the MSG table: MSG = {"command_name", "1st argument", "2nd argument"}
- end
- ]=]
- local function cast(event, pPlayer, pMessage, pType, pLanguage, pMisc, MSG)
- pPlayer:CastSpell(MSG[2])
- end
- local function fart(event, pPlayer, pMessage, pType, pLanguage, pMisc, MSG)
- pPlayer:PlaySoundToPlayer(17339)
- end
- local function broadcast(event, pPlayer, pMessage, pType, pLanguage, pMisc, MSG)
- SendWorldMessage(MSG[2], MSG[3])
- end
- -- Command table:
- local T =
- {
- --[=[
- ["command_name"] = { command_name, -- Change command_name to your custom command's name
- {}, -- "number" and "string" accepted
- '', -- Must be able to use command group specified here (arcemu command groups) Example: az
- 'Usage: .command_name', -- the help text for the command. If empty, then show default arguments.
- },
- ]=]
- ["cast"] = {
- cast,
- {"number"},
- '',
- '',
- },
- ["fart"] = {
- fart,
- {},
- '',
- '',
- },
- ["broadcast"] = {
- broadcast,
- {"string", "number"},
- 'az',
- 'Usage: .broadcast Text Type\nText must be closed with quotes if it contains spaces: "Hello world"\nType can be 1 for areatrigger message and 2 for broadcast message',
- },
- }
- --
- local function explode(str)
- local pos, arr = 2, {}
- for KEY,VALUE in function() return string.find(str,' ',pos,false) end do
- local X = string.sub(str, pos, KEY-1)
- if(tonumber(X)) then
- X = tonumber(X)
- else
- X = X:gsub('("[^"]*")', function(a) return a:gsub('%%20', " ") end):gsub('"', "")
- end
- table.insert(arr, X)
- pos = VALUE + 1
- end
- local X = string.sub(str,pos)
- if(tonumber(X)) then
- X = tonumber(X)
- else
- X = X:gsub('("[^"]*")', function(a) return a:gsub('%%20', " ") end):gsub('"', "")
- end
- table.insert(arr, X)
- return arr
- end
- local function ON_CHAT(event, pPlayer, pMessage, pType, pLanguage, pMisc)
- if(pPlayer:IsGm() and pMessage:find("[.!]%a+") == 1) then
- local MSG = explode(pMessage:gsub('("[^"]*")', function(a) return a:gsub(' ', "%%20") end))
- if(MSG[1]:len() < 4) then -- Just for caution. We dont want to override every single existing short command. Remove this IF statement if you like.
- return
- end
- MSG[1] = MSG[1]:lower()
- local CMDp
- if(T[MSG[1]]) then
- CMDp = MSG[1]
- else
- for command,_ in pairs(T) do
- if(command:find(MSG[1]) == 1) then
- CMDp = command
- break
- end
- end
- end
- if(CMDp) then
- if(T[CMDp][3] and T[CMDp][3] ~= '' and not pPlayer:CanUseCommand(T[CMDp][3])) then
- return
- end
- local PASS = true
- for k,v in pairs(T[CMDp][2]) do
- if(not MSG[k+1] or type(MSG[k+1]) ~= v) then
- if(T[CMDp][4] and T[CMDp][4] ~= "") then
- pPlayer:SendBroadcastMessage(T[CMDp][4])
- else
- pPlayer:SendBroadcastMessage("Usage: ."..CMDp.." "..(table.concat(T[CMDp][2], " ")))
- end
- return false
- end
- end
- T[CMDp][1](event, pPlayer, pMessage, pType, pLanguage, pMisc, MSG)
- return false
- end
- end
- end
- RegisterServerHook(16, ON_CHAT)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement