Jump to content

Payday Help


sebihunter

Recommended Posts

Hey

I have problems with my payday. Here is my code

function payday ( source, command ) 
  
      givePlayerMoney ( source, 2000 ) 
        outputChatBox ( "PAYDAY: 2000$" ) 
     setTimer ( payday, 1000, 1) 
        
end 
  
setTimer (payday, 5000, 1) --1000 = 1 second 

The time is only as test. I hope you can help me :wink:

Sebihunter

Link to comment

Im assuming you wish to pay every player on the server every 5 seconds or whatever..

here is a nice and easy way to do it:

  
  
function allPlayersPayDay() 
  local allPlayers = getElementsByType("player") --Get all the players in the server 
  for index,value in ipairs(allPlayers) do --Loop around all of the players 
    givePlayerMoney ( value, 2000 ) --give this player some moneys 
    outputChatBox ( "Its your payday, you have been given $2000", value ) --Tell them that its been given 
  end 
end 
  
function onResourceStart(thisResource) 
  setTimer ( allPlayersPayDay, 5000, 0 ) --When this resource has started, setup a new timer to give players some cash every 5 seconds 
end 
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), onResourceStart ) --Add the event handler for onResourceStart which is automatically executed when this is started 
  

Sorry if it has any errors, i wrote it from memory in the forum edit box lol.

Link to comment

You can do it easier. givePlayerMoney supports being called to a group of elements/players, so if you call it on the root element, all players get money. Here's an example:

  
function allPlayersPayDay() 
  givePlayerMoney ( getRootElement(), 2000 ) --give all players some moneys 
  outputChatBox ( "Its your payday, you have been given $2000" ) --Tell them that its been given 
end 
  
function onResourceStart(thisResource) 
  setTimer ( allPlayersPayDay, 5000, 0 ) --When this resource has started, setup a new timer to give players some cash every 5 seconds 
end 
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), onResourceStart ) --Add the event handler for onResourceStart which is automatically executed when this is started 
  

If you have a team of players (see createTeam), you can use setElementParent to make the players in the team a child of that team. And call givePlayerMoney on the team, and all players in that team will get the money.

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...