Hello
I’m trying to get a player’s id when he inputs the command /tweet so I can display it for the staff. Everything works correctly but the id is always displayed as if the player viewing it wrote the command
I’m guessing it will have to do something with player ped but I can’t figure it out.
Can someone help??
1 Like
If you are using https://github.com/ESX-Org/esx_rpchat for tweets then:
- server/main.lua: (line 14-23)
RegisterCommand(‘twt’, function(playerId, args, rawCommand)
if playerId == 0 then
print('esx_rpchat: you can\'t use this command from console!')
else
args = table.concat(args, ' ')
local playerName = GetRealPlayerName(playerId)
TriggerClientEvent('chat:addMessage', -1, {args = {_U('twt_prefix', playerId, playerName), args}, color = {0, 153, 204}})
end
end, false)
- and change locales/en.lua
[‘twt_prefix’] = ‘^0[^4Twitter^0] (%s) (^5@%s^0)’,
- Then it would display the ID in chat:
[Twitter] (ID) (@ PlayerName): message
Hope it helps. 
Thanks for the reply.
I am using esx_rpchat and I will try it out tomorrow and let you know if it worked.
Because you seem to know more than me I would like to ask a question. There are some natives that output a player’s id but they expect an input named “player”. What natives do output those “player” outputs?
PS: Also, GetRealPlayerName isn’t on the natives list. Is that FiveM’s fault or is there another place stating more natives?
Hi
GetRealPlayerName is a function from esx_rpchat
You can find it here https://github.com/ESX-Org/esx_rpchat/blob/master/server/main.lua#L47
That why curiosity said “if you are using esx_rpchat”
1 Like
Ok i get this but i don’t know where to put this code because i have seperated users and staff by putting them in two different keys using:
local staff = {}
local user = {}
for i=1, #result, 1 do
if result[i].group == 'admin' or result[i].group == "superadmin" then
staff[id] = true
else
user[id] = true
end
end
And later in the tweet command im using it like this:
for id,_ in pairs(staff) do
--do stuff
end
for id,_ in pairs(user) do
--do stuff
end
Would it be ok if i put this at the start of the code and use it later on in the trigger client event of each command?
Edit: I compared the script I have with the one curiosity sent me and it’s quite different. Mine doesn’t use ESX. stuff so i would guess it’s outdated. Either way, I tried putting the code he gave me and in the end it gives out this error:
Edit 2: When i try putting the code inside the registercommand it just says tried to call a nil value :GetRealPlayerName
1 Like
Hi
This is a simple example on how you can do it…
Since you have the names on a variable list them no loop is need a simple if statement to check is the player is on list A, on list B or on list C is enough.
local user = { #List of all users
["Charles"]=true,
["Nancy"]=true,
["Glory"]=true,
}
local staff = { #List of all staffs
["Michael"]=true,
["Phelps"]=true,
["Kimmy"]=true,
}
#List above should be on a database.
local player = "Phelps" #This is to simulate the player name that is triggering the event
if user[player] then
print("The user " ..player.. " just trigger the x command")
elseif staff[player] then
print("The staff " ..player.. " just trigger the x command")
else
print("The unknown group player " ..player.. " just trigger the x command")
end
Hope this helps…
That might cause errors and definitely will be harsh on the server’s performance since we have 2000 registered users. I don’t have a problem with the script itself since as i stated it perfectly works. What doesn’t is displaying the user’s id, something I don’t know how to get.
Either way thanks for helping
Hi
humm a simple statement will be harsh for the server ? why ?
Unless you are referring to something else
Checking every single member in the database before sending a message will cause lag. And I don’t even think that would work cause it would try to send a message to people that are offline.
Also, your code doesn’t include any IDs and that’s what I wanted
Its one if statement… not a loop. A if statement will not do that.
The code you place above is the one with a loop, is the one that will run x number of times (depending the number of users)
A if statement will simply compare one value with a second one or check if both values are true beetween them and if they are the code inside will run