Player killed by world spawn.

Hi, I’m currently trying to help a friend code for his server, after reading some of your threads, I noticed that you guys aren’t really fascinated in helping people who are not honest. So let me be honest here: I don’t know how to code a lot, or at all, depending on you guys.

My problem is, I am making death fees for people as shown here:



		if playermoney > 100000 then
			if killer:IsPlayer() or killer:worldspawn then
				ply:AddMoney(-losemoney)
				DarkRPCreateMoneyBag(ply:GetPos(), dropamt)
				GAMEMODE:Notify(ply, 1, 7, "You have lost " .. GAMEMODE.Config.currency .. losemoney .. " (20% of your money) to pay for your revival.")
				GAMEMODE:Notify(ply, 3, 7, "You may respawn after this message has passed.")
			else
				GAMEMODE:Notify(ply, 3, 7, "No money lost due to you not getting killed by a human.")
				GAMEMODE:Notify(ply, 3, 7, "You may respawn after this message has passed.")
			end
		end


As you can see, my second line involved me being rather… Crude in attempt to try fix my problem.

My question is: What is the hook/function for worldspawn deaths? The reason why I wanted to do this is to prevent people from suicide to prevent RP situations and to avoid their death fees.

Any help is appreciated, thanks for your time.

Oh and by the way, playermoney, losemoney, and dropamt are all variables, and is already correctly declared in the code. So just ignore those.

world spawn should be from fall damage. so the killer SHOULD be nil. You could try



if killer==nil then
--not a person or prop/object
end


You could also test it by killing yourself (falling) and printing the killer.

Printing? What do you mean by printing?

Here’s a quick debug script to help



hook.Add("OnTakeDamage","getkiller",function(cdmg)
	MsgN("Damage Info:")
	MsgN("Killer: "..tostring( cdmg:GetAttacker() ) )
	MsgN("Weapon: "..tostring( cdmg:GetInflictor() ) )
	MsgN("Damage Type: "..tostring( cdmg:GetDamageType() ) )
	MsgN("IsFallDamage: "..tostring( cdmg:IsFallDamage() ) )
end)


Run this in single player to get some info

[editline]22nd September 2013[/editline]

I’m sorry… But where and how do I use the mentioned hook/script? I’m very new to lua coding. Apologies.

if you look at the hook:

you can see at the bottom it is a server sided hook. The easiest way would be to put it in lua/autorun/server/damage.lua
(it can be named whatever you like)

Thanks for the script, and your help. But may I please know where does the result output into? Because I checked console, and the only thing it gave me is:

Did you restart/change the map? It will print in server console since it is a server sided hook.

[editline]24th September 2013[/editline]

Sorry used the wrong hook. Use http://wiki.garrysmod.com/page/GM/EntityTakeDamage instead.

Thanks, I changed your script to:



hook.Add("EntityTakeDamage", "getkiller", function(target, cdmg)
	MsgN("Damage Info:")
	MsgN("Killer: "..tostring(cdmg:GetAttacker()))
	MsgN("Weapon: "..tostring(cdmg:GetInflictor()))
	MsgN("Damage Type: "..tostring(cdmg:GetDamageType()))
	MsgN("IsFallDamage: "..tostring(cdmg:IsFallDamage()))
end)


But now, the problem is here, it states that I’m killed by Entity [0][worldspawn].

What do I do now?

Thats because you died from falldamage. Entity 0 is the map itself.

Yes, but what I’m trying to do is to ensure that people who suicide during an event(like a mug) will lose his money to prevent cheating. So, in short, I want it so that they lose money from fall damage, any way to do that?

You want http://wiki.garrysmod.com/page/GM/PlayerDeath

Thanks to everyone who tried to help me. The guy I’m coding for scrapped the idea of having people to lose money from fall damage due to me not knowing how to do it and to prevent players from complaining if they fall of ledges accidentally.