[Release] Death Messages and Join/Leave

This script was created as a basic proof of concept in 2017. Please stop replying to it.

Created a simple script to handle joining/leaving a server and death messages. It actually says who killed who. Wrote this in about an hour so it’s probably sloppy.

Client Script

RegisterNetEvent('showNotification')
AddEventHandler('showNotification', function(text)
	ShowNotification(text)
end)
function ShowNotification(text)
	SetNotificationTextEntry("STRING")
	AddTextComponentString(text)
	DrawNotification(0,1)
end
Citizen.CreateThread(function()
    -- main loop thing
	alreadyDead = false
    while true do
        Citizen.Wait(50)
		local playerPed = GetPlayerPed(-1)
		if IsEntityDead(playerPed) and not alreadyDead then
			killer = GetPedKiller(playerPed)
			killername = false
			for id = 0, 64 do
				if killer == GetPlayerPed(id) then
					killername = GetPlayerName(id)
				end				
			end
			if killer == playerPed then
				TriggerServerEvent('playerDied',0,0)
			elseif killername then
				TriggerServerEvent('playerDied',killername,1)
			else
				TriggerServerEvent('playerDied',0,2)
			end
			alreadyDead = true
		end
		if not IsEntityDead(playerPed) then
			alreadyDead = false
		end
	end
end)

Server Script

AddEventHandler('playerConnecting', function()
	TriggerClientEvent('showNotification', -1,"~g~".. GetPlayerName(source).."~w~ joined.")
end)

AddEventHandler('playerDropped', function()
	TriggerClientEvent('showNotification', -1,"~r~".. GetPlayerName(source).."~w~ left.")
end)

RegisterServerEvent('playerDied')
AddEventHandler('playerDied',function(killer,reason)
	if killer == "**Invalid**" then --Can't figure out what's generating invalid, it's late. If you figure it out, let me know. I just handle it as a string for now.
		reason = 2
	end
	if reason == 0 then
		TriggerClientEvent('showNotification', -1,"~o~".. GetPlayerName(source).."~w~ committed suicide. ")
	elseif reason == 1 then
		TriggerClientEvent('showNotification', -1,"~o~".. killer .. "~w~ killed ~o~"..GetPlayerName(source).."~w~.")
	else
		TriggerClientEvent('showNotification', -1,"~o~".. GetPlayerName(source).."~w~ died.")
	end
end)
14 Likes

Thank you very much m8!

Hello good, but i have a problem, I created a folder with resource.lua / client.lua and server. lua I inserted your scripts but nothing in game

Did you declare the mod in your server config file ?

I have declared in my citmp-server, what do you mean?

That’s what I was wondering. Maybe clear your cache also.

I did but nothing :frowning:

I posted a faulty version of the code at first, try re-copying the code just to make sure you didn’t get it during that first 5 minutes it was wrong.

1 Like

Okay did you corrected it now?

It’s been correct since 5 minutes after I posted it

Okay I retry and will tell you

It doesn’t work … :frowning:

I guess you should to modify the file : - spawnmanager

Oh okay and what im gonne supposed to modify in it?

Seems to be working without touching the spawnmanager

However when someone leaves they dont leave the normal playerlists :S

What Im gonna supposed to write in resource? please

client_script ‘client.lua’
server_script ‘server.lua’

The join message is the only problem seems to be very delayed

The join message is just based in the user connecting, not spawning for the first time.

hello, good script but when a player click to connect on the server also he’s not whitelisted, in game its wrote ‘…’ joined