Hey, I’m trying to create a servser-side command that only someone with a txAdmin account can use. I did a bit with txAdmin:events:adminAuth, but that didn’t work and gave me a error.
The error:
[ c-scripting-core] Creating script environments for txTest
[ c-scripting-core] InvokeNative: execution failed: Argument at index 0 was null.
[ script:txTest] SCRIPT ERROR: Execution of native 000000005fa79b0f in script host failed: Argument at index 0 was null.
[ script:txTest] > fn (@txTest/server.lua:1)
Thers nothing about this tx-event in the Web so i dont realy know if i use it right or if theres a other problem.
local players = {}
RegisterNetEvent('txAdmin:events:adminAuth', function(data)
players[data.netid] = {
isAdmin = data.isAdmin,
username = data.username
}
end)
RegisterCommand("somecommand", function(source, args)
if not players[source] then return print('Not found') end
if not players[source].isAdmin then return print('No permissions') end
-- Your code here
print("Hello, world!")
end, false)
Citizen.CreateThread(function()
while true do
if(NetworkIsPlayerActive(PlayerId())) then
break
end
Wait(100)
end
TriggerServerEvent('txsv:checkIfAdmin')
end)
By the way, that’s incorrect. txAdmin has a wonderful page on Github where you can find almost everything.
If you have any other problems, I’m happy to help.
First, thanks for the quick help, I looked at the code and corrected mine.
Now I have another question on this topic: Is it possible that I can put all the IDs of the players with txAdmin accounts into a table and then only trigger a client event for them with TriggerClientEvent?
About the txAdmin Github page, do you mean this page?
If we consider the table ‘players’ as an example, it stores the ID, isAdmin, and the txAdmin username.
Theoretically, if you want to develop a team chat or something similar, you could simply use a loop:
for id, player in pairs(players) do
if player.isAdmin then
TriggerClientEvent('someevent', id, ...)
end
end
Of course, you have to check everything on the server side for security reasons because a modder could also execute something on the client side. But that would be the method.
As for txAdmin’s GitHub page, in theory I mean the entire source code, but for the use and explanation of events, the “events.md” file is also more than sufficient. However, it is worth mentioning that the entire docs/* section is also very informative.