DarkRP - Share money out between specific teams.

Hello FacePunch,

Recently I’ve been doing my own thing, messing around with gLua really and I just happened to make some sort of concept what i honestly thought would work but didn’t. As simple as I can mention the concept is literally…well have a look…

[LUA]

for _,t in pairs(player.GetAll() ) do
if t:Team() == TEAM_CITIZEN then
t:addMoney(1000/TEAM_CITIZEN)
end

end

[/LUA]

What the result of this code should be is if the specific ‘Team’ is what is stated then share out the value between the team, somehow it just gives all of the team 1000 each when in all purpose it should share it out i.e ( 2 Citizens meaning $500 each ). I’m curious to findout what I’ve done wrong.

Thank you for your time, hope you can help!

I think if you wanted this to actually work properly then you’d need to get the amount of players on TEAM_CITIZEN using something like

team.GetPlayers, then divide the money by that rather than TEAM_CITIZEN like you’re doing there (TEAM_CITIZEN isn’t the number of players on a team)

[editline]26th March 2016[/editline]

I think the reason it’s giving everyone in the team $1000 is because TEAM_CITIZEN is a variable that’s set as 1. As far as I know, that’s all any TEAM variable represents, just an index number like that

Since you asked me to help a bit more, I think something like this would work (although I haven’t tested it):



for _, ply in pairs(player.GetAll() ) do 
	if ( ply:Team() == TEAM_CITIZEN ) then
		ply:addMoney( 1000 / team.NumPlayers( TEAM_CITIZEN ) )
	end
end


My first post was wrong about the function to use, it had to be the NumPlayers function instead

That should theoretically work. What you were doing before was trying to access TEAM_CITIZEN as a number value and divide 1000 by it. TEAM_CITIZEN is not a number, you need to run a method that returns a number to divide 1000 by it, in this case, team.NumPlayers(TEAM_CITIZEN) will return the number of players on the team, divide 1000 by that number and give each player that amount of money.

Yeah, like I was trying to say before, anything starting with TEAM_ doesn’t actually represent the amount of PLAYERS on that team, it just represents the index of that team, e.g. TEAM_CITIZEN for you seems to have the index of 1 assigned to it, considering dividing 1000 by 1 still equals 1000

Not sure how DarkRP works, that would make sense if it returned an index (in this case 1). I didn’t read that last part of how it would always give 1000. I thought TEAM_CITIZEN would return a table, guess not. I should read more carefully :slight_smile: