Mayor dropping items on death?

Okay so, I have added this code to the mayor job:


PlayerDeath = function(ply, weapon, killer)
    for _,v in pairs(team.GetPlayers(TEAM_SS)) do
        v:teamBan()
        v:changeTeam(GAMEMODE.DefaultTeam, true)
    end
	
	for _,v in pairs(team.GetPlayers(TEAM_MAYOR)) do
    v:teamBan()
    v:changeTeam(GAMEMODE.DefaultTeam, true)

    end
	
    if killer:IsPlayer() then
        -- Killed by a player
        DarkRP.notifyAll(0, 4, "The mayor has been killed and all of the secret service are therefor demoted.")
    else
        -- Killed by other causes
        DarkRP.notifyAll(0, 4, "The mayor has died and all of the secret service are therefor demoted.")
    end
end

Now before placing this code, the mayor job is fine, he dies, nothing weapons drop. But the issue is I want him to get demoted on death, I added this code to fix that, but when I add this code and he dies, he loses all his weapons he carries (phys gun, etc). I dont want him dropping that stuff. I have the dropweapons enabled in the config but I disabled that, it didn’t change anything.

I have those code so Secret Service job also gets demoted when mayor dies, but the secret service doesn’t seem to be affected by this issue.

Is there any way where I can stop the mayor dropping items he shouldnt be dropping?

Why aren’t you creating a hook? Why are you doing PlayerDeath = function? Why aren’t you making it local if you are making a var?

So many questions, very little answers.

Go make a hook.

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

I found this online on a darkrp wikia site. I didnt make this myself, it does what I want but its dropping weapons

DarkRP jobs add hooks to certain keys you specify in the job table – it’s functionally equivalent.

[editline]7th January 2017[/editline]

Try running ply:ShouldDropWeapon (false) to the function.

Could you write this out for me? Im not that experienced.

He just did…

Where does that go in the code.

You can put it at the top.