vrhard4 Posted December 26, 2014 Share Posted December 26, 2014 I'm need a mod which is give money to players in team. Like: if someone in police team, he get 20000$, but if player don't have team or in criminal team, he don't get money. This is my script for this, but it isn't good: function tekmoney () local money = 20000 local playerTeam = getTeamName ( theTeam ) for id, player in ipairs(getElementsByType("player")) do if getTeamName ( theTeam ) == "TEK" then givePlayerMoney ( player, money ) outputChatBox ( "[TEAM] Money received.", getRootElement(), 255, 255, 255, true ) end end end setTimer ( tekmoney, 5000, 0) Link to comment
Mr_Moose Posted December 26, 2014 Share Posted December 26, 2014 function giveTeamMembersMoney(theTeam, money) for id, plr in ipairs(getElementsByType("player")) do if getPlayerTeam(plr) == getTeamFromName(theTeam) then givePlayerMoney ( plr, money ) outputChatBox ( "[TEAM] Money received.", plr, 255, 255, 255, true ) end end end You're trying to get a team name from a nil object on line 3, then you compare the same thing with a constant string named "TEK" which applies to all players, "player" is also a class name, it may work for now but in the future when lua get's more object orientated it won't work using class names as variables. The chat output was also seen to all online players unless it crashed before it got there, the above code does what you want, don't forget to pass the arguments. An example call would look like this: giveTeamMembersMoney("Police", 20000) -- give members of the police team $20´000 giveTeamMembersMoney("Criminals", 4000) -- give members of the criminals team $4´000 Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now