Promotion/Fire players

I need help with something I’m trying to code for darkrp, basically it allows the Mayor to fire cps if they don’t do their job probably, the other is a thing to stop cps from self promoting themselves to the Chief, so basically the Mayor has to choose the CP.

Now I’ve tried starting the fire command, but I don’t think I have it right.

[Lua] local function FirePlayer(ply, args)
if args == “” then return “” end

if ply:Team() ~= TEAM_MAYOR then Notify(ply, 1, 4, “You are not the Mayor”) return “” end [/lua]

The problem Im having here is the name, like you would type it out as /fire “name” but I don’t know how to get the name part, that’s what confusing me.

The self promotion bit I have no clue on how to do.

Any help would be appreciated.

Wtf is ~=?

you mean !=

[lua]
concommand.Add(“mayor_firecop”, function(p,command,arguments)
if ( p:Team() != TEAM_MAYOR ) then return end;
for _,a in pairs( player.GetAll() ) do
if ( a:SteamID() == arguments[1] ) then
– Set there team right here.
a:SetTeam(tInd);
return;
end
end
end);
[/lua]

Lol? Doesnt ~ mean not also?

I’ve never heard of that before, atleast not in Lua.

Hm, lemme go look it up

~= is used for Lua

!= is used in C

http://cprogramminglanguage.net/c-relational-operators.aspx

So the whole thing should look like this:

[Lua] local function FirePlayer(p,command,arguments)
concommand.Add(“mayor_firecop”, function(p,command,arguments)
if ( p:Team() != TEAM_MAYOR ) then return end;
for _,a in pairs( player.GetAll() ) do
if ( a:SteamID() == arguments[1] ) then
a:SetTeam( TEAM_CITIZEN )
a:SetTeam(tInd);
return;
end
end
end

AddChatCommand ( “/fire”, FirePlayer )[/Lua]

Oops it says I need to close the function, apparently I am missing a parenthesis, but I can’t see it.

You are missing it on your last end. And missing an end for the function.

[lua]
local function FirePlayer(p,command,arguments)

concommand.Add("mayor_firecop", function(p,command,arguments)
	if ( p:Team() != TEAM_MAYOR ) then return end;
	for _,a in pairs( player.GetAll() ) do
		if ( a:SteamID() == arguments[1] ) then
			a:SetTeam( TEAM_CITIZEN )
			a:SetTeam(tInd);
			return;
		end
	end
end)

end
AddChatCommand ( “/fire”, FirePlayer )
[/lua]

So if I where to make it notify the player I would write it out as:

[lua]local function FirePlayer(p,command,arguments)
concommand.Add(“mayor_firecop”, function(p,command,arguments)
if ( p:Team() != TEAM_MAYOR ) then return end;
for _,a in pairs( player.GetAll() ) do
if ( a:SteamID() == arguments[1] ) then
a:SetTeam( TEAM_CITIZEN )
a:SetTeam(tInd);
Notify(1,4”You have been fired”)
return;
end
end
end)
end
AddChatCommand ( “/fire”, FirePlayer )
[/lua]

[lua]
Notify(1,4”You have been fired”)
[/lua]

Should be

[lua]
Notify(a,1,4,”You have been fired”)
[/lua]

If I recall what the arguments to notify are. The order might be different.

Yes that’s what the arguments where.

Well when I tried /fire it just appeared as if I said nothing.

Well it seems all you did was just create a console command.

[lua]
local function cmdFirePlayer(client, arguments)
if (client:Team() == TEAM_MAYOR) then
if (arguments[1] and arguments[1] != “”) then
for k, v in pairs( player.GetAll() ) do
if ( v:SteamID() == arguments[1] ) then
v:SetTeam(TEAM_CITIZEN);

                     Notify(v, 1, 4, "You have been fired from your job.");
                end;
           end;
      end;
 end;

end;

AddChatCommand("/fire", cmdFirePlayer);
[/lua]

Fixed for you.

I put it in main.lua and it seems to do the same thing as before, for example:Player: /fire firedud would come out as Player: firedud

You need to put the SteamID.

[lua]local function cmdFirePlayer(client, arguments)
if (client:Team() == TEAM_MAYOR) then
if (arguments[1] and arguments[1] != “”) then
for k, v in pairs( player.GetAll() ) do
if ( v:Nick() == arguments[1] ) then
v:SetTeam(TEAM_CITIZEN);

                     Notify(v, 1, 4, "You have been fired from your job.");
                end;
           end;
      end;
 end;

end;

AddChatCommand("/fire", cmdFirePlayer);[/lua]

Try this

It does the same thing as before.

Necropost.

[lua]
local function cmdFirePlayer(client, arguments)
if (client:Team() == TEAM_MAYOR) then
if (arguments[1] and arguments[1] != “”) then
for k, v in pairs( player.GetAll() ) do
if (string.find(v:Nick(),arguments[1]) then
v:SetTeam(TEAM_CITIZEN);
Notify(v, 1, 4, “You have been fired from your job.”)
break
end;
end;
end;
end;
return “”
end;

AddChatCommand("/fire", cmdFirePlayer);
[/lua]

May I suggest you have some sort of ply:IsCP() check, as this means mayors can fire everyone.

Seriously… why isn’t anybody using the FindPlayer(info) function created in DarkRP, which was specifically made for things like this?!

v:SetTeam(TEAM_CITIZEN, true)