Skip to content

Commit 31afed9

Browse files
committed
Create RunElunaCommand
1 parent 3b840d5 commit 31afed9

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

Extensions/RunElunaCommand

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
-- Allows running Eluna lua from ingame chat and from server console
2+
-- This command is intended for development purposes
3+
-- Example usage:
4+
-- .eluna pp(GetLuaEngine(), "Code ran by:", plr and plr:GetName() or "console")
5+
6+
-- pp is defined to be a function to send a message to everyone on server and to console for easy printing
7+
-- plr is the player using the command or nil if command from console
8+
-- sel is the selection of plr or nil if nothing selected
9+
10+
-- errors in the lua code executed are printed to command invoker only (console or player), they are not logged
11+
-- errors in timed events made with the code and such delayed actions are reported by normal means to the error logs and console if so defined in Eluna settings.
12+
13+
local runcmd = "eluna"
14+
local function RunCommand(event, player, cmd)
15+
if (cmd:lower():find("^"..runcmd.." .+")) then
16+
-- Here you can define some environment variables for the code
17+
-- I defined plr to be the player or nil
18+
-- sel to be the current selection of the player or nil
19+
-- pp to print the passed arguments to everyone and to console
20+
local env = [[
21+
local plr = ...
22+
local sel = sel
23+
local pp = function(...)
24+
local t = {...}
25+
for i = 1, select("#", ...) do t[i] = tostring(t[i]) end
26+
local msg = table.concat(t, " ")
27+
SendWorldMessage(msg)
28+
print(msg)
29+
end
30+
if (plr) then
31+
sel = plr:GetSelection()
32+
end
33+
]]
34+
local code = env..cmd:sub(#runcmd+2)
35+
local func, err = load(code, "."..runcmd)
36+
if (func) then
37+
local res
38+
res, err = pcall(func, player)
39+
if (res) then
40+
return false
41+
end
42+
end
43+
if (not player) then
44+
print(err)
45+
else
46+
player:SendBroadcastMessage(err)
47+
end
48+
return false
49+
end
50+
end
51+
52+
RegisterPlayerEvent(42, RunCommand)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy