Scripting command - MySQL query correct, cmd syntax error

Hey!
I’m making a command for whitelistening members via an in-game command. The commands and the way they work are taken from whitelistDb script and is being implemented by me into the esx_whitelistEnchanced script. However, that isn’t relevant.

I have checked the query, and it works just fine. The only thing I need to get fixed, is the command. Whenever I write a command, I get “Incorrect identifier!” error, as you can see is a part of the wladd command. So my goal is to write /wladd SteamID64inHex - then the SQL query is being executed with the SteamID. Don’t worry about the query, the error is somewhere in the command input.

TriggerEvent('es:addGroupCommand', 'wladd', "admin", function(source, args, user)
	if #args == 2 then
		if isWhiteListed(args[2]) then
			TriggerClientEvent('chatMessage', source, "SYSTEM", {255, 0, 0}, args[2] .. " is already whitelisted!")
		else
			addWhiteList(args[2])
			TriggerClientEvent('chatMessage', source, "SYSTEM", {255, 0, 0}, args[2] .. " has been whitelisted!")
		end
	else
		TriggerClientEvent('chatMessage', source, "SYSTEM", {255, 0, 0}, "Incorrect identifier!")
	end
end, function(source, args, user)
	TriggerClientEvent('chatMessage', source, "SYSTEM", {255, 0, 0}, "Insufficienct permissions!")
end)

function addWhiteList(identifier)
	MySQL.Sync.execute("INSERT INTO whitelist (`identifier`) VALUES (@identifier)", {['@identifier'] = identifier})
end

function removeWhiteList(identifier)
	MySQL.Sync.execute("DELETE identifier FROM whitelist WHERE identifier = @identifier", {['@identifier'] = identifier})
end

function isWhiteListed(identifier)
	local result = MySQL.Sync.fetchScalar("SELECT identifier FROM whitelist WHERE identifier = @identifier", {['@identifier'] = identifier})
	if result then
		return true
	end
	return false
end

What result do you get when you use print(table.unpack(args)) above the if #args == 2 statement?

I suspect that the args table size is either 1 or higher than two.

1 Like

It prints out whatever I write after /wladd. E.g /wlad 123 prints outs 123
That is what it is supposed to do, but giving me this “incorrect identifier”.
I’m actually a bit confused about these args, what exactly do they do? If I set it to 1, then it should work? As 1 input = 1 argument?

That solved it, thanks.

Great, so you didn’t have 2 arguments :stuck_out_tongue:

Maybe the original code expected the /wl command with add and remove as first argument and the steam ID as the second.

1 Like

Yeah it was only 1 argument :smiley:
One more question though when it coms to the query.

Here’s my query:

MySQL.Sync.execute("INSERT INTO whitelist (`identifier`) VALUES (@identifier)", {['@identifier'] = identifier})

I’d like to add “steam:” in front of the identifier into the value, any good way of doing that? Tried adding VALUES (steam:@identifier)" but that didn’t work well, threw an error. Any way of doing that?