sebihunter Posted January 4, 2008 Posted January 4, 2008 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 Sebihunter Kyes reaction after getting banned twice from #ivmp Yep, very mature.
Franc[e]sco Posted January 4, 2008 Posted January 4, 2008 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
sebihunter Posted January 4, 2008 Author Posted January 4, 2008 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 Kyes reaction after getting banned twice from #ivmp Yep, very mature.
Franc[e]sco Posted January 4, 2008 Posted January 4, 2008 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...
sebihunter Posted January 4, 2008 Author Posted January 4, 2008 I think I make it first with the spawn timer Thanks! Kyes reaction after getting banned twice from #ivmp Yep, very mature.
AlienX Posted January 5, 2008 Posted January 5, 2008 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. if ( DISGRACE_ACTIVE ) then local disgracedPlayer = getFedorsElementID() if ( disgracedPlayer ) then showTextForFedor ( disgracedPlayer, "DISGRACE!", 5000, 255, 0, 0 ) end end
ChrML Posted January 5, 2008 Posted January 5, 2008 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. Linus Torvalds: "Software is like sex: it's better when it's free."
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