• DarkRP - Mayor demotion on death (Please help)
    12 replies, posted
  • Avatar of Simple_sa
  • Hi. Im ok with lua, but Ive been having problems doing this. Here is what I basically what to do: If the mayor dies he loses his mayor status. They would be automatically demoted and would become a citizen. Also I would like a message on the screen poping up saying "The mayor has been assinated". I can proberly do the message, but having a hard time code the demotion thing. I also dont no where to put it. It should be easy enough, just dont no what to do. Help would be greatly apperciated. Thanx, Simple
  • Avatar of Crazy Quebec
  • If you want a specific and direct answer about the workings of a specific gamemode, ask in that gamemode's thread. All I can tell you is how to find it out yourself, and it's really not hard. Just open Notepad++ (if you're not using that already, see links below) and use the search in files function to find the string "demote" in the DarkRP folder. You'll find what you're looking for in no time at all! [url]http://notepad-plus.sourceforge.net/[/url] [url]http://www.garrysmod.org/downloads/?a=view&id=62428[/url]
  • Avatar of Simple_sa
  • Thanx, ya ive done that. But I don't no which files to put it in. (main.lua, etc) But thanx, il ask in gamemodes section I guess.
  • Avatar of Crazy Quebec
  • You would hook to the mayor's death with the PlayerDeath gamemode hook. [lua] function MayorDeath( victim, weapon, killer ) if victim:Team() == TEAM_MAYOR then --Stuff end end hook.Add( "PlayerDeath", "MayorDeathCheck", MayorDeath) [/lua] [url]http://wiki.garrysmod.com/?title=Gamemode_Hooks[/url] [url]http://wiki.garrysmod.com/?title=Gamemode.PlayerDeath[/url] [url]http://wiki.garrysmod.com/?title=Player.Team[/url]
  • [QUOTE=Crazy Quebec;18043810]You would hook to the mayor's death with the PlayerDeath gamemode hook. [lua] function MayorDeath( victim, weapon, killer ) if victim:Team() == TEAM_MAYOR then --Stuff end end hook.Add( "PlayerDeath", "MayorDeathCheck", MayorDeath) [/lua] [url]http://wiki.garrysmod.com/?title=Gamemode_Hooks[/url] [url]http://wiki.garrysmod.com/?title=Gamemode.PlayerDeath[/url] [url]http://wiki.garrysmod.com/?title=Player.Team[/url][/QUOTE] Where do you put the code?
  • Avatar of sphinxa279
  • /facepalm Stupid bumper, why would they go all the way back to these threads just to nudge them up :saddowns:
  • Avatar of slay3r36
  • its better to bump instead of create a new thread for the same question anyway, put this: [lua]function MayorDeath( victim, weapon, killer ) if victim:Team() == TEAM_MAYOR then victim:SetTeam( TEAM_CITIZEN ) end end hook.Add( "PlayerDeath", "MayorDeathCheck", MayorDeath) [/lua] in garrysmod/garrysmod/lua/autorun/server/randomname.lua
  • Avatar of ST20winD
  • [SUP]hook.Add("PlayerDeath","DemoteMayor",function(v,k) if (v:Team() == TEAM_MAYOR) then v:ChangeTeam(TEAM_CITIZEN,true); for k, v in ipairs(player.GetAll()) do v:PrintMessage(HUD_PRINTCENTER,"The mayor has been killed!"); end; end; end);[/SUP] Goes in init.lua