How to block KILL in console?

NEW QUESTION!

[lua]
function MayorDemote( victim, weapon, killer )

if victim:Team() == TEAM_MAYOR then
     
    victim:ChangeTeam(TEAM_CITIZEN, true)
    victim:ChatPrint("You were killed and have lost mayor.")
    killer:AddMoney(500)
         
    for k, v in pairs (player.GetAll()) do
         
        if v != victim then
 
            v:Notify( 0, 4, "The mayor has been murdered!" )
                 
            if v:Team() == TEAM_VICE then
                     
                v:ChangeTeam( TEAM_MAYOR, true )
                     
            end -- This is the end you missed.
                 
        end
             
    end
         
end

end
hook.Add( “PlayerDeath”, “mayorDemote”, MayorDemote )[/lua]

This code is suppost to demote the mayor when he is killed then the vice_mayor should become mayor… the problem is that the mayor does get demoted, but the vice doesn’t get promoted…

Then after that, the code just breaks… It is for dark rp in the file init.lua… Why does it break afterwards and why does vice mayor get promoted?

Where does the code get to, does the chat print occur, does the killer get their money, and does everyone receive the notification?

But more importantly, dpwhen you say,“The code breaks,” do you receive any console errors?

Here just do;
[lua]
function MayorDemote( victim, weapon, killer )

if victim:Team() == TEAM_MAYOR && killer:Team() != victim:Team() then
    victim:SetTeam(TEAM_CITIZEN)
    victim:PrintMessage(HUD_PRINTTALK,"You were killed and have lost mayor.")
    killer:AddMoney(500)
          
    for k, v in pairs (player.GetAll()) do
          
        if v != victim then
  
            v:Notify( 0, 4, "The mayor has been murdered!" )
                  
            if v:Team() == TEAM_VICE then
                      
                v:ChangeTeam( TEAM_MAYOR, true )
                      
            end -- This is the end you missed.
                  
        end
              
    end
          
end

end
hook.Add( “PlayerDeath”, “mayorDemote”, MayorDemote )
[/lua]

The strips I added is;
[lua] && victim:Team() != killer:Team() [/lua]
[lua] victim:SetTeam(TEAM_CITIZEN) [/lua]
[lua]victim:PrintMessage(HUD_PRINTTALK,“You were killed and have lost mayor.”)[/lua]

[lua]
function GM:PlayerCanSuicide(player)
return false;
end;
[/lua]

In shared.lua

Wait, you changed questions? Damn it.