[CODE]function ulx.cexec( calling_ply, target_plys, command )
for _, v in ipairs( target_plys ) do
-- it works when this is uncommented
-- v:ConCommand( command )
--and the next line is removed
v:SendLua([[LocalPlayer():ConCommand( command )]])
end
ulx.fancyLogAdmin( calling_ply, "#A ran #s on #T", command, target_plys )
end
[/CODE]
Or maybe with Format()
(Or the printf() equivalence in LUA)
I really need an explanation of Why it isn't working rather than guesses about syntax. The send lua function works fine when I run it out of pointshop. I just need to know why it's not working in ULX.
[editline]2nd March 2014[/editline]
[QUOTE=Walrus Viking;44104726][code]v:SendLua( [[RunConsoleCommand( ']] .. command .. [[']] )[/code]
?[/QUOTE]
It needs to be run on the local player
[LUA]
local str = "LocalPlayer():ConCommand( %s )"
v:SendLua( str:format( command ) )
[/LUA]
just realised i forgot quotes around %s :v:
-snip- misinterpreted what was going on
[editline]2nd March 2014[/editline]
Also, I usually use single ' quotes to wrap the Broadcast/SendLua and double " quotes to wrap the actual strings.
Why not use \"?
[QUOTE=Kuro Light;44108932]Why not use \"?[/QUOTE]
Don't think he really needs to use any escapes...
[QUOTE=rejax;44107630][LUA]
local str = "LocalPlayer():ConCommand( %s )"
v:SendLua( str:format( command ) )
[/LUA][/QUOTE]
ulx cexec galactic say test
returns
[QUOTE][ERROR] LuaCmd:1: ')' expected near 'test'
1. unknown - LuaCmd:0
[/QUOTE]
Is the problem that I need the whole thing to be a string? If so why does this pointshop code work perfectly? Isn't user input already counted as a string?
[CODE]
ITEM.Name = 'Dancing time!'
ITEM.Price = 5000
ITEM.Model = 'models/props_c17/clock01.mdl'
ITEM.SingleUse = true
--ITEM.AllowedUserGroups = { "admin", "superadmin","goatking","hegemon"}
function ITEM:OnBuy(ply)
for k,v in pairs(player.GetAll()) do
if !v:IsGhost() then
v:SendLua([[LocalPlayer():ConCommand("act robot")]])
v:PrintMessage(HUD_PRINTTALK, "Dancing time! 100 points given to you by your dancing fans!")
v:PS_GivePoints(100)
end
end
end
function ITEM:OnSell(ply)
ply:PrintMessage(HUD_PRINTTALK, "What?")
end
[/CODE]
[[blah blah blah]] is the same as "blah blah blah" which is also the same as 'blah blah blah' or even [==[blah blah blah]==]
The brackets are used because they require no escape sequences, they take everything as is, as a literal string. (excluding new lines)
I think because you are casting a variable into the concommand what rejax sugested won't work without quotes. Same with the [[ ]], because it is taken literal.
Try this i think:
[lua]
local str = 'LocalPlayer():ConCommand( "%s" )'
v:SendLua( string.format( str, command ) )
[/lua]
[QUOTE=Ludicium;44113559][[blah blah blah]] is the same as "blah blah blah" which is also the same as 'blah blah blah' or even [==[blah blah blah]==]
The brackets are used because they require no escape sequences, they take everything as is, as a literal string. (excluding new lines)
I think because you are casting a variable into the concommand what rejax sugested won't work without quotes. Same with the [[ ]], because it is taken literal.
Try this i think:
[lua]
local str = 'LocalPlayer():ConCommand( "%s" )'
v:SendLua( string.format( str, command ) )
[/lua][/QUOTE]
You, sir, are the best. Not only did you help me understand what I was doing wrong, you straight up fixed my problem. Thank you everyone else for helping. Thank you Ludicium for being so much smarter than me.
Sorry, you need to Log In to post a reply to this thread.