txAdmin events:adminAuth

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.

Server-side:
RegisterCommand(txTester, function(source)
local xplayer = getPlayerPed(source)
AddEventHandler(‘txAdmin:event:adminAuth’, function(xPlayer , isAdmin, adminName)
print(xplayer)
print(isAdmin)
print(adminName)
end)
end)

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.

1 Like

Hey…

I think you should first learn the basics and basic understanding.

Your approach is incorrect, and you’re also using incorrect natives, some of which don’t even exist.

  1. txAdmin:event:adminAuth does not exist, but txAdmin:events:adminAuth does.
  2. getPlayerPed(...) does not exist either, but GetPlayerPed(...) does.
  3. the event is not executed by AddEventHandler, but only received

Take a look at my code; it works and should solve your problem. But as a tip, try to analyze it instead of simply copying it.

server.lua (Download)

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)

client.lua (Download)

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.

2 Likes

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?

Or is there a more detailed one?

Hey,

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.