Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local runcmd = "eluna"
- local function RunCommand(event, player, cmd)
- if (cmd:lower():find("^"..runcmd.." .+")) then
- -- Here you can define some environment variables for the code
- -- I defined plr to be the player or nil
- -- sel to be the current selection of the player or nil
- -- and print to be sendbroadcastmessage if the player is not nil
- local env = [[
- local plr = ...
- local sel = sel
- local pp = function(p, ...)
- local t = {...}
- for i = 1, select("#", ...) do t[i] = tostring(t[i]) end
- p:SendBroadcastMessage(table.concat(t, " "))
- end
- if (plr) then
- sel = plr:GetSelection()
- end
- ]]
- local code = env..cmd:sub(#runcmd+2)
- local func, err = load(code, "."..runcmd)
- if (func) then
- local res
- res, err = pcall(func, player)
- if (res) then
- return false
- end
- end
- print(err)
- if (not player) then
- print(err)
- else
- player:SendBroadcastMessage(err)
- end
- return false
- end
- end
- RegisterPlayerEvent(42, RunCommand)
- -- Example usage:
- -- Note that player doesnt exist if this is run from console, so I made it check for that. This command can be ran from console and ingame
- -- .eluna print(GetLuaEngine(), plr and plr:GetName() or "console")
- -- I defined pp to be a function to send a broadcast message to first passed player
- -- sel is the selection of plr
- -- .eluna pp(plr, plr:GetName(), sel and sel:GetName())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement