arris Posted June 28, 2009 Share Posted June 28, 2009 ok so i made a menu and i added a button and when a player clicks it, it fixes the players car and the thing i want to do is when they click the button it cost $200 to fix the car. can someone help me. Link to comment
DakiLLa Posted June 28, 2009 Share Posted June 28, 2009 local money = getPlayerMoney( player ) if money >= 200 then fixVehicle( vehicle ) else outputChatBox( "You need 200$ to repair your car", player, 255, 0, 0 ) end something like this... Link to comment
Topp3x Posted June 29, 2009 Share Posted June 29, 2009 local money = getPlayerMoney( player ) if money >= 200 then fixVehicle( vehicle ) else outputChatBox( "You need 200$ to repair your car", player, 255, 0, 0 ) end something like this... ahh dont he need takePlayerMoney too :b ? Link to comment
DakiLLa Posted June 29, 2009 Share Posted June 29, 2009 ahh, ye, thats my usual mistake i always forget to add this line Link to comment
arris Posted June 29, 2009 Author Share Posted June 29, 2009 umm so where do i add the takePlayerMoney line Link to comment
Topp3x Posted June 29, 2009 Share Posted June 29, 2009 ahh, ye, thats my usual mistake i always forget to add this line ye i saw yersterday local money = getPlayerMoney( player ) if money >= 200 then fixVehicle( vehicle ) takePlayerMoney( player, 200 ) else outputChatBox( "You need 200$ to repair your car", player, 255, 0, 0 ) end Link to comment
arris Posted June 29, 2009 Author Share Posted June 29, 2009 This is how i have it and it doesn't work function fix(button,state) --- BUTTON 1 local money = getPlayerMoney( player ) if money >= 200 then fixVehicle( vehicle ) takePlayerMoney( player, 200 ) else outputChatBox( "You need 200$ to repair your car", player, 255, 0, 0 ) end if button == "left" and state == "down" then local clientPlayer = getLocalPlayer() if isPlayerInVehicle(clientPlayer) == true then local Vehicle = getPlayerOccupiedVehicle ( clientPlayer) fixVehicle(Vehicle) outputChatBox("Vehicle Successfully Fixed/Repaired",255,255,0,true) else outputChatBox("You are not in a vehicle",255,0,0,true) end end end --- --- --- --- -- Also can someone help me with this code addEventHandler( "onPlayerWasted", getRootElement( ), function() setTimer( spawnPlayer, 5000, 1, source, 2001.6312255859, 1544.2255859375, 13.5859375 ) end ) i have that code but i want to create another code that if the player has a house he spawn there if he doesn't he spawns at 2001.6312255859, 1544.2255859375, 13.5859375 can someone help Link to comment
Topp3x Posted June 29, 2009 Share Posted June 29, 2009 hmm what about if ( money >= 200) then ? function whatever ( button, player, state ) local vehicle = getPlayerOccupiedVehicle( player ) -- or getPedOccupiedVehicle if its for nightly... if vehicle then local money = getPlayerMoney ( player ) if ( money >= 200) then fixVehicle( vehicle ) takePlayerMoney( player, 200 ) else outputChatBox( "You need 200$ to repair your car", player, 255, 0, 0 ) end else outputChatBox(" you need a vehicle for this ", player, 255, 0, 0 ) end end and the other question.. i dont know how to do it :b but what about spawn player where he died ? Link to comment
DakiLLa Posted June 29, 2009 Share Posted June 29, 2009 dorf, idk what you have done in your code, but i think it should be like next: client side: addEventHandler( "onClientResourceStart", getResourceRootElement( getThisResource() ), function () --your code with your button-- addEventHandler( "onClientGUIClick", yourButton, function () triggerServerEvent( "fixMyVehicle", getLocalPlayer() ) end ) end ) server-side: addEvent( "fixMyVehicle", true ) function fix() local vehicle = getPlayerOccupiedVehicle( source ) if vehicle then local money = getPlayerMoney( source ) if money >= 200 then fixVehicle( vehicle ) else outputChatBox( "You dont have enough money!", source, 255, 0, 0 ) end end end addEventHandler( "fixMyVehicle", getRootElement(), fix ) Link to comment
The_Ex Posted June 29, 2009 Share Posted June 29, 2009 Arris about that spawn in house... You can't just ask for code here. You have to learn both - code and search and in you can't find anything - then come here and ask for something. Link to comment
50p Posted June 29, 2009 Share Posted June 29, 2009 DaK, 2 things: - where is takePlayerMoney? - don't forget about false as the last parameter in addEventHandler call if you use gui elements as attachedTo (2nd parameter) Also, I don't see a point in making a variable which is only used once (the money var is used in the if statement only). Link to comment
arris Posted June 30, 2009 Author Share Posted June 30, 2009 Arris about that spawn in house... You can't just ask for code here. You have to learn both - code and search and in you can't find anything - then come here and ask for something. I did look and i found somethings but i didn't need those and so thats why i asked. Link to comment
DakiLLa Posted June 30, 2009 Share Posted June 30, 2009 DaK, 2 things:- where is takePlayerMoney? - don't forget about false as the last parameter in addEventHandler call if you use gui elements as attachedTo (2nd parameter) Also, I don't see a point in making a variable which is only used once (the money var is used in the if statement only). 1) lol i forgot again to add this line >.< 2) so, it should be addEventHandler( "onClientGUIClick", yourButton, function () triggerServerEvent( "fixMyVehicle", getLocalPlayer() ) end , false ) and.. can you explain in details, why i should use 'false' if event is attached? cse i cant understand what wiki says about it :\ (its an offtopic i think..) Link to comment
50p Posted June 30, 2009 Share Posted June 30, 2009 If you attach a function to a button without the false then that function will be triggered even if you click other GUI (windows, buttons, images, etc.) but if you use false, then this function will be called only if source == this (In other words, if "attachedTo" element (the button in this case) is equal to source (clicked gui element)). 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