Hey, i am trying to get my darkrp mayor job to demote upon death. this is my code:
[CODE]PlayerDeath = function(ply, weapon, killer)
if( ply:Team() == TEAM_MAYOR ) then
if killer:Nick() ~= nil then
ply:changeTeam( GAMEMODE.DefaultTeam, true )
end
for k,v in pairs( player.GetAll() ) do
if killer:Nick() ~= nil then
DarkRP.notify(v, 1, 4, "The mayor has been killed!" )
else
DarkRP.notify(v, 1, 4, "The mayor has died!" )
end
end
end
end[/CODE]
Whenever he is killed, no message appears but however he is demoted, but his job title is still mayor. I am running darkrp 2.5. Any ideas?
[QUOTE=max_salami;44394668]Hey, i am trying to get my darkrp mayor job to demote upon death. this is my code:
[CODE]PlayerDeath = function(ply, weapon, killer)
if( ply:Team() == TEAM_MAYOR ) then
if killer:Nick() ~= nil then
ply:changeTeam( GAMEMODE.DefaultTeam, true )
end
for k,v in pairs( player.GetAll() ) do
if killer:Nick() ~= nil then
DarkRP.notify(v, 1, 4, "The mayor has been killed!" )
else
DarkRP.notify(v, 1, 4, "The mayor has died!" )
end
end
end
end[/CODE]
Whenever he is killed, no message appears but however he is demoted, but his job title is still mayor. I am running darkrp 2.5. Any ideas?[/QUOTE]
[CODE]
hook.Add("PlayerDeath", "mayorDeathFP", function(ply, weapon, killer)
if( ply.isMayor() ) then
if killer:Nick() ~= nil then
ply:changeTeam( TEAM_CITIZEN, true )
DarkRP.notifyAll(HUD_PRINTCENTER, 4, "The mayor has been killed!" )
else
DarkRP.notifyAll(HUD_PRINTCENTER, 4, "The mayor has died!" )
end
end
end)
[/CODE]
[QUOTE=AnonTakesOver;44394866][CODE]
hook.Add("PlayerDeath", "mayorDeathFP", function(ply, weapon, killer)
if( ply.isMayor() ) then
if killer:Nick() ~= nil then
ply:changeTeam( TEAM_CITIZEN, true )
DarkRP.notifyAll(HUD_PRINTCENTER, 4, "The mayor has been killed!" )
else
DarkRP.notifyAll(HUD_PRINTCENTER, 4, "The mayor has died!" )
end
end
end)
[/CODE][/QUOTE]
Nope, that didnt work.
[QUOTE=max_salami;44394987]Nope, that didnt work.[/QUOTE]
replace ply.isMayor() with ply:isMayor()
My bad, it works, just tested
[QUOTE=AnonTakesOver;44395200]replace ply.isMayor() with ply:isMayor()
My bad, it works, just tested[/QUOTE]
This time, nothing changes at all when he is killed.
[url]http://www.mediafire.com/download/2h52rj9xkh95pdg/mayordeath.zip[/url]
Put that in garrysmod\addons\darkrpmodification-master\lua\darkrp_modules
[QUOTE=AnonTakesOver;44395775][url]http://www.mediafire.com/download/2h52rj9xkh95pdg/mayordeath.zip[/url]
Put that in garrysmod\addons\darkrpmodification-master\lua\darkrp_modules[/QUOTE]
Nope, doesent do anything either
[QUOTE=max_salami;44395887]Nope, doesent do anything either[/QUOTE]
That works perfectly for me, DarkRP 2.5.
What happens when you die? Check the console, I added a print("Derp"), does it say derp in the console when someone dies?
[QUOTE=AnonTakesOver;44395980]That works perfectly for me, DarkRP 2.5.
What happens when you die? Check the console, I added a print("Derp"), does it say derp in the console when someone dies?[/QUOTE]`
Nope.
[QUOTE=max_salami;44396889]`
Nope.[/QUOTE]
It's not running then, that code works, it's just not being ran
[lua] PlayerDeath = function(ply, weapon, killer)
if( ply:Team() == TEAM_MAYOR ) then
ply:teamBan()
ply:changeTeam( TEAM_CITIZEN, true )
for k,v in pairs( player.GetAll() ) do
DarkRP.notify(v, 1, 4, "The mayor has died!" )
end
end
end[/lua]
We add the ply:teamBan() in so that the player that died as mayor cannot automatically become the mayor once again, he has to wait before voting again.
[QUOTE=stapler2025;44397370][lua] PlayerDeath = function(ply, weapon, killer)
if( ply:Team() == TEAM_MAYOR ) then
ply:teamBan()
ply:changeTeam( TEAM_CITIZEN, true )
for k,v in pairs( player.GetAll() ) do
DarkRP.notify(v, 1, 4, "The mayor has died!" )
end
end
end[/lua]
We add the ply:teamBan() in so that the player that died as mayor cannot automatically become the mayor once again, he has to wait before voting again.[/QUOTE]
Why do you loop through everyone and notify them, it makes no sense, do you not know there is a function DarkRP.notifyAll() I don't even program in DarkRP or know any of it's functions but after looking at it's wiki I knew in 5 seconds...
There is also isMayor()
If you read the wiki for about 5 seconds, it would make your life so much easier, and I understand that it's only like a 3 second difference and in actual run time the difference is so small and unnoticeable, but it just irritates me, I have some weird kinds of OCD
Hey, shitler - [url]http://wiki.darkrp.com/index.php/LUA:Demote_Upon_Death[/url]
Update the wiki then.
[QUOTE=stapler2025;44397680]Hey, shitler - [url]http://wiki.darkrp.com/index.php/LUA:Demote_Upon_Death[/url]
Update the wiki then.[/QUOTE]
[url]http://wiki.darkrp.com/index.php/Category:Functions[/url]
GG
How about learn how to google and learn how to code something basic and not copy paste the wiki all the time
Implying that I copy/paste everything I see onto our server.
Thanks for playing though!
How would I make this only happen when the player is killed by another player? If they suicide or are killed by an entity, I don't want them to be demoted.
[QUOTE=ZerK;44397872]How would I make this only happen when the player is killed by another player? If they suicide or are killed by an entity, I don't want them to be demoted.[/QUOTE]
[CODE]
hook.Add("PlayerDeath", "mayorDeathFP", function(ply, weapon, killer)
if( ply.isMayor() ) then
if killer:IsPlayer() then
ply:changeTeam( TEAM_CITIZEN, true )
DarkRP.notifyAll(HUD_PRINTCENTER, 4, "The mayor has been killed!" )
else
DarkRP.notifyAll(HUD_PRINTCENTER, 4, "The mayor has died!" )
end
end
end)
[/CODE]
[QUOTE=AnonTakesOver;44396905]It's not running then, that code works, it's just not being ran[/QUOTE]
If that is so, can you please give step by step instructions on how to install it? Sorry i am new to lua.
Download this: [url]http://www.mediafire.com/download/2h52rj9xkh95pdg/mayordeath.zip[/url]
open it, there will be a folder called mayordeath,
Put that in garrysmod\addons\darkrpmodification-master\lua\darkrp_modules
MAKE SURE YOU PUT THE FOLDER IN NOT THE ZIP, WHEN YOU DOWNLOAD THE FILE IT IS A ZIP, OPEN IT AND THERE IS A FOLDER
That is EXACTLY what ive done and it doesn't work.
[QUOTE=max_salami;44403413]That is EXACTLY what ive done and it doesn't work.[/QUOTE]
I can guarantee you this works, if you really really want, I might be able to teamview with you and set it up?
Probably because you have it as ply.isMayor() still rather than ply:isMayor().
[editline]31st March 2014[/editline]
I also recommend using GAMEMODE.DefaultTeam rather than directly referencing TEAM_CITIZEN.
The ply:teamBan() mentioned earlier is a good idea too (in addition) as it stops the player from immediately going back to the mayor job and instead demotes the player, blocking them from changing to the job for the standard GM.Config.demotetime. Though if you have a vote before being mayor, you may or may not want this.
[editline]31st March 2014[/editline]
[QUOTE=AnonTakesOver;44398031][CODE]
DarkRP.notifyAll(HUD_PRINTCENTER, 4, "The mayor has been killed!" )
[/CODE][/QUOTE]
This takes the [URL="http://wiki.garrysmod.com/page/Enums/NOTIFY"]NOTIFY_ enums[/URL] rather than the HUD_ ones. However, these are not defined serverside so you need to define them yourself or use their values.
[QUOTE=Bo98;44408170]Probably because you have it as ply.isMayor() still rather than ply:isMayor().
[editline]31st March 2014[/editline]
I also recommend using GAMEMODE.DefaultTeam rather than directly referencing TEAM_CITIZEN.
The ply:teamBan() mentioned earlier is a good idea too (in addition) as it stops the player from immediately going back to the mayor job and instead demotes the player, blocking them from changing to the job for the standard GM.Config.demotetime. Though if you have a vote before being mayor, you may or may not want this.[/QUOTE]
Yes, I made a reply saying I screwed up, but in the script I uploaded it is fixed, it shouldn't make a difference between either of default team and team_citizen, assuming they didn't rename citizen, if they did, they would have enough knowledge to set this up..
And I didn't think team ban was necessary as it is up to the server to vote in or not (assuming the server votes for mayor)
[editline]31st March 2014[/editline]
[url]http://wiki.darkrp.com/index.php/Functions/darkrp/server/notifyall[/url]
Darkrp does this already
[QUOTE=AnonTakesOver;44408239]it shouldn't make a difference between either of default team and team_citizen, assuming they didn't rename citizen, if they did, they would have enough knowledge to set this up..[/QUOTE]
GAMEMODE.DefaultTeam covers both cases however.
[QUOTE]
[url]http://wiki.darkrp.com/index.php/Functions/darkrp/server/notifyall[/url]
Darkrp does this already[/QUOTE]
What do you mean? Enums are just numbers. DarkRP only takes it's value, it has no idea what enum you used. That code will not print in the centre of the screen as number 4 in the NOTIFY_ enums just makes the icon the scissors icon.
[QUOTE=Bo98;44408258]GAMEMODE.DefaultTeam covers both cases however.
What do you mean? Enums are just numbers. DarkRP only takes it's value, it has no idea what enum you used. That code will not print in the centre of the screen as number 4 in the NOTIFY_ enums just makes the icon the scissors icon.[/QUOTE]
Oh -.-, silly me, I see what you mean, well it pops up in the bottom right which is all that really matters, but I see what you mean now..
One thing I'd like to note that was maybe confused over earlier.
In this case, hook.Add over the PlayerTeam job field would be more suitable as this could potentially cover more than one job. [URL="https://github.com/FPtje/DarkRP/pull/810"]9 months ago, the ability to have multiple mayor jobs was added.[/URL] Using the 'mayor' job field, you can have as many different jobs with the same powers as the mayor. [URL="https://github.com/FPtje/DarkRP/commit/a6435015c08b59e3a3f880c86046a4ba009fdba5"]The convenience function ply:isMayor() was then added in DarkRP 2.5.0.[/URL] If you were to use the PlayerDeath job field then you would need to add the code to every job while with this hook.Add you would only need it once and it covers all. However if you use either way, and are having a ply:teamBan(), you may want to [URL="https://github.com/FPtje/darkrpmodification/blob/master/lua/darkrp_customthings/demotegroups.lua"]create a mayor demote group with your mayor jobs[/URL].
Sorry, you need to Log In to post a reply to this thread.