[HELP] Print the players name in chat

roleplay
chat
name
playername

#1

Im trying to print

Officer: [Players name] Unracked his rifle
Officer: [Players name] Racked his rifle

I know where to put it back I cant figure it out how get the players name.

-------------------- CARBINE ------------------------------

local carbine = false

RegisterNetEvent("rifle")
AddEventHandler("rifle", function()
	carbine = not carbine
    if carbine then
		GiveWeaponToPed(GetPlayerPed(-1), GetHashKey("WEAPON_CARBINERIFLE"), 1000, false)
		GiveWeaponComponentToPed(GetPlayerPed(-1), GetHashKey("WEAPON_CARBINERIFLE"), GetHashKey("COMPONENT_AT_AR_FLSH"))
		GiveWeaponComponentToPed(GetPlayerPed(-1), GetHashKey("WEAPON_CARBINERIFLE"), GetHashKey("COMPONENT_AT_SCOPE_MEDIUM"))
		TriggerEvent("chatMessage", "^1Officer:" [The players name] "Unracked his rifle")
    else
        RemoveWeaponFromPed(GetPlayerPed(PlayerId()), GetHashKey("WEAPON_CARBINERIFLE"))
		TriggerEvent("chatMessage", "^1Officer:" [The players name] "Reracked his rifle")
	end
end)

Thanks!


#2

Just one note, this would only print on your client. Not for everyone.


#3

Well sh*t, How uhm…Do I fix that? Lol


#4

U will need also a server.lua.

To get the playername: NetworkPlayerGetName(PlayerId())


#5

I need to do a TriggerServerEvent(‘Event Name’) Right? If I wanna execute it from a client file?


#6

I don’t 100 % know that out of my mind. You can find that in the Docs.


#7

you can just use GetPlayerName(source)


#8

idk if you still need it, but you can download my script and modify it to work for your use (not needed tho)

or


#9

TriggerServerEvent(“someevent”, GetPlayerName(PlayerId())

and make 1 of the server-side script for handler, to trigger to all client (-1) [ maybe calling the prox-chat event ]