Why doesn't this work?


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


try :

v:SendLua("LocalPlayer():ConCommand( " … command … “)”)

With the input cexec * say test it returns


v:SendLua( [[RunConsoleCommand( ']] .. command .. [[']] )

?

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]

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 "?

Don’t think he really needs to use any escapes…

ulx cexec galactic say test
returns

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?



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


[[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]

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.