[Release] Death Messages and Join/Leave


#1

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)

How to know if a player is dead and do something?
#2

Thank you very much m8!


#3

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


#4

Did you declare the mod in your server config file ?


#5

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


#6

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


#7

I did but nothing :frowning:


[Release][vRP]-[Dunko Edited V6.6 - FX Server] UPDATED 19/02/2018 - Supports 15 languages - Zap Hosting 10% DISCOUNT!
#8

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.


#9

Okay did you corrected it now?


#10

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


#11

Okay I retry and will tell you


#12

It doesn’t work … :frowning:


#13

I guess you should to modify the file : - spawnmanager


#14

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


#15

Seems to be working without touching the spawnmanager

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


#16

What Im gonna supposed to write in resource? please


#17

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


#18

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


#19

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


#20

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