• DarkRp Mayor Dies.
    40 replies, posted
Hey I have a quick request to throw out there. I am curious on how I can make it so that when the mayor dies he is assassinated and is moved back to the citizen job. Thanks in advanced for people that help.
[code]function MayorDemote( victim, weapon, killer ) if victim:Team() == (TEAM_MAYOR) then victim:SetTeam() == (TEAM_CITIZEN) victim:ChatPrint("You died and you are now a regular citizen") for k, v in pairs (player.GetAll()) do v:PrintMessage( HUD_PRINTCENTER, "The mayor has died!" ) end end end hook.Add( "PlayerDeath", "mayorDemote", MayorDemote )[/code] Something like that.
[lua] victim:SetTeam(TEAM_CITIZEN) [/lua]
[QUOTE=Busymonkey;23821860][code]function MayorDemote( victim, weapon, killer ) if victim:Team() == (TEAM_MAYOR) then victim:SetTeam() == (TEAM_CITIZEN) victim:ChatPrint("You died and you are now a regular citizen") for k, v in pairs (player.GetAll()) do v:PrintMessage( HUD_PRINTCENTER, "The mayor has died!" ) end end end hook.Add( "PlayerDeath", "mayorDemote", MayorDemote )[/code] Something like that.[/QUOTE] [code]function MayorDemote( victim, weapon, killer ) if victim:Team() == TEAM_MAYOR then victim:SetTeam(TEAM_CITIZEN) victim:ChatPrint("You died and you are now a regular citizen") for k, v in pairs (player.GetAll()) do v:PrintMessage( HUD_PRINTCENTER, "The mayor has died!" ) end end end hook.Add( "PlayerDeath", "mayorDemote", MayorDemote )[/code] Fixed.
this helped me alot to is it allright if i use it to ?
[QUOTE=christoffer5700;23892812]this helped me alot to is it allright if i use it to ?[/QUOTE] It's not like it's licensed, Go ahead.
thanks
What file would this be put in?
init.lua
Thanks
Useful'd
[QUOTE=Busymonkey;23821860][code]function MayorDemote( victim, weapon, killer ) if victim:Team() == (TEAM_MAYOR) then victim:SetTeam() == (TEAM_CITIZEN) victim:ChatPrint("You died and you are now a regular citizen") for k, v in pairs (player.GetAll()) do v:PrintMessage( HUD_PRINTCENTER, "The mayor has died!" ) end end end hook.Add( "PlayerDeath", "mayorDemote", MayorDemote )[/code] Something like that.[/QUOTE] your tabbing is bad.
That script demotes, but doesn't change the Salary or Job title. Would anyone kindly fix it?
[LUA]function MayorDemote( victim, weapon, killer ) if victim:Team() == TEAM_MAYOR then ChangeJob(victim,"citizen") victim:ChatPrint("You died and you are now a regular citizen") for k, v in pairs (player.GetAll()) do v:PrintMessage( HUD_PRINTCENTER, "The mayor has died!" ) end end end hook.Add( "PlayerDeath", "mayorDemote", MayorDemote ) [/LUA] It should work... [b]Edit:[/b] What happened to lua tag lol
That doesn't work, it doesn't reset your salary or job title.
[LUA] function MayorDemote( victim, weapon, killer ) if victim:Team() == TEAM_MAYOR then victim:UpdateJob(team.GetName(1)) victim:ChatPrint("You died and you are now a regular citizen") for k, v in pairs (player.GetAll()) do if v != victim then v:PrintMessage( HUD_PRINTCENTER, "The mayor has died!" ) end end end end hook.Add( "PlayerDeath", "mayorDemote", MayorDemote ) [/LUA] It will work I promise :)
Nope, that actually made it worse, now the mayor doesn't change job but changes job title. Salary is still the same.
[QUOTE=czmate10;24104993][LUA] function MayorDemote( victim, weapon, killer ) if victim:Team() == TEAM_MAYOR then victim:UpdateJob(team.GetName(1)) victim:ChatPrint("You died and you are now a regular citizen") for k, v in pairs (player.GetAll()) do if v != victim then v:PrintMessage( HUD_PRINTCENTER, "The mayor has died!" ) end end end end hook.Add( "PlayerDeath", "mayorDemote", MayorDemote ) [/LUA] It will work I promise :)[/QUOTE] You're lying. You havent put the changing of the job anywhere. [code]function MayorDemote( victim, weapon, killer ) if victim:Team() == TEAM_MAYOR then victim:SetTeam(TEAM_CITIZEN) victim:UpdateJob(team.GetName(1)) victim:ChatPrint("You died and you are now a regular citizen") for k, v in pairs (player.GetAll()) do if v != victim then v:PrintMessage( HUD_PRINTCENTER, "The mayor has died!" ) end end end end hook.Add( "PlayerDeath", "mayorDemote", MayorDemote )[/code]
[QUOTE=Busymonkey;24155322]You're lying. You havent put the changing of the job anywhere. [code]function MayorDemote( victim, weapon, killer ) if victim:Team() == TEAM_MAYOR then victim:SetTeam(TEAM_CITIZEN) victim:UpdateJob(team.GetName(1)) victim:ChatPrint("You died and you are now a regular citizen") for k, v in pairs (player.GetAll()) do if v != victim then v:PrintMessage( HUD_PRINTCENTER, "The mayor has died!" ) end end end end hook.Add( "PlayerDeath", "mayorDemote", MayorDemote )[/code][/QUOTE] Their is a bug in your script, When you die as mayor, your salary stays as the mayors salary even though your a citizen.
Yeah, i'm getting that too Angel. However, i haven't tried Busymonkeys script, i'll try it out later.
Shouldn't you be using the ChangeTeam function provided in DarkRP? [lua] function MayorDemote( victim, weapon, killer ) if victim:Team() == TEAM_MAYOR then victim:ChangeTeam(TEAM_CITIZEN, true) victim:UpdateJob("citizen") victim:ChatPrint("You died and you are now a regular citizen.") for k, v in pairs (player.GetAll()) do if v != victim then v:PrintMessage( HUD_PRINTCENTER, "The mayor has died!" ) end end end end hook.Add( "PlayerDeath", "mayorDemote", MayorDemote ) [/lua]
Hello I am very noobish to the LUA language, but will this perhaps work? [code]function MayorDemote( victim, weapon, killer ) if victim:Team() == TEAM_MAYOR then victim:SetTeam(TEAM_CITIZEN) victim:UpdateJob(team.GetName(1)) --Right here victim:SetSalary(TEAM_CITIZEN) --Between this victim:ChatPrint("You died and you are now a regular citizen") for k, v in pairs (player.GetAll()) do if v != victim then v:PrintMessage( HUD_PRINTCENTER, "The mayor has died!" ) end end end end hook.Add( "PlayerDeath", "mayorDemote", MayorDemote )[/code] [b]EDIT[/b]: Also, can is it possible to add another hook in it or an entirely different file that when mayor dies if he had taxes like let's say: [code]rp_propertytax 1[/code] and [code]rp_proppaying 1[/code] Make a hook so when mayor dies they go to 0/1 ?
[QUOTE=jonney934;24387700]Shouldn't you be using the ChangeTeam function provided in DarkRP? [lua] function MayorDemote( victim, weapon, killer ) if victim:Team() == TEAM_MAYOR then victim:ChangeTeam(TEAM_CITIZEN, true) victim:UpdateJob("citizen") victim:ChatPrint("You died and you are now a regular citizen.") for k, v in pairs (player.GetAll()) do if v != victim then v:PrintMessage( HUD_PRINTCENTER, "The mayor has died!" ) end end end end hook.Add( "PlayerDeath", "mayorDemote", MayorDemote ) [/lua][/QUOTE] Correct, however you shouldn't need to use UpdateJob now: [lua] function MayorDemote( victim, weapon, killer ) if victim:Team() == TEAM_MAYOR then victim:ChangeTeam(TEAM_CITIZEN, true) victim:ChatPrint("You died and you are now a regular citizen.") for k, v in pairs (player.GetAll()) do if v != victim then v:PrintMessage( HUD_PRINTCENTER, "The mayor has died!" ) end end end end hook.Add( "PlayerDeath", "mayorDemote", MayorDemote ) [/lua]
[QUOTE=Drakehawke;24409535]Correct, however you shouldn't need to use UpdateJob now: [lua] function MayorDemote( victim, weapon, killer ) if victim:Team() == TEAM_MAYOR then victim:ChangeTeam(TEAM_CITIZEN, true) victim:ChatPrint("You died and you are now a regular citizen.") for k, v in pairs (player.GetAll()) do if v != victim then v:PrintMessage( HUD_PRINTCENTER, "The mayor has died!" ) end end end end hook.Add( "PlayerDeath", "mayorDemote", MayorDemote ) [/lua][/QUOTE] So this one work or is it still bad. Where do you put this file into?
You put that file in [code]gamemodes/darkrp/gamemode/init.lua[/code] at the bottom. Also btw, can someone please answer my question like 3 posts above this one? :P
Just add RunConsoleCommand( "rp_proppaying", 0 ) into the hook.
[QUOTE=Drakehawke;24409535]Correct, however you shouldn't need to use UpdateJob now: [lua] function MayorDemote( victim, weapon, killer ) if victim:Team() == TEAM_MAYOR then victim:ChangeTeam(TEAM_CITIZEN, true) victim:ChatPrint("You died and you are now a regular citizen.") for k, v in pairs (player.GetAll()) do if v != victim then v:PrintMessage( HUD_PRINTCENTER, "The mayor has died!" ) end end end end hook.Add( "PlayerDeath", "mayorDemote", MayorDemote ) [/lua][/QUOTE] Works perfectly, thanks.
Is there a way to make it so the mayor only dies if someone else kills him, and not if he dies by physics props / worldspawn?
I love your bump. Also possibly, just experiment with the code.
Since todd's bumped it and this kind of relates I don't want to make another thread. How would i make it so that you get money for killing the mayor?
Sorry, you need to Log In to post a reply to this thread.