Jump to content

Payday Help


sebihunter

Recommended Posts

Posted

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

Posted

When u set the timer you should set it in the onPlayerSpawn and u should pass the player's id so:

setTimer (payday, 5000, 1, source)

oh and anyways this will execute only 1 time if u do not set the times parameter to 0

Posted

Thanks!

Edit:

did everything you told me except to movethe timer to player spawn cause I want that all players get at the same time payday, but there is still an lua warning for the give money function

Posted

heh if u want that payday for all the players at the same time it's more complicated im not sure but u should make a timer without passing the playerid on the top of the gamemode then in the payday function a for that applies the payday to every player on the server...

Posted

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.

Posted

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.

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...