Wisin Posted February 11, 2010 Share Posted February 11, 2010 (edited) hi community, im making a menu for the player and i need to get working a "repair" button but the i dont understand how to, here is my server-side code. if someone can tell me how to use will be very nice function fix(button,state) if button == "left" and state == "down" then local clientPlayer = getLocalPlayer() if isPlayerInVehicle(clientPlayer) == true then local Vehicle = getPlayerOccupiedVehicle ( clientPlayer) fixVehicle(theVehicle) outputChatBox("Vehicle Successfully Fixed",255,255,0,true) else outputChatBox("You are not in a vehicle",255,0,0,true) end end end Edited February 11, 2010 by Guest Link to comment
dzek (varez) Posted February 11, 2010 Share Posted February 11, 2010 this is mix of server-side and client-side functions.. maybe just open freeroam resource and see how it is done there? ps. put your lua code in [lua] [/lua] tags Link to comment
Wisin Posted February 11, 2010 Author Share Posted February 11, 2010 well i think i ve did that but dint taked a good look i will check it again, and sorry for the lua tags i just forgot to put them Link to comment
Robert333 Posted February 11, 2010 Share Posted February 11, 2010 I think there is just a spelling mistake. You get with the function 'getPlayerOccupiedVehicle' the 'vehicle' and you set 'Vehicle' as variable, but then you called in 'fixVehicle' the variable 'theVehicle'. Try to set in 'fixVehicle' the variable 'Vehicle' or set the variable of 'getPlayerOccupiedVehicle' to 'theVehicle'. If you use Notepad++ you can avoid this mistakes by double clicking the variable, then notepad show you all words (variables) that have the same name. Link to comment
Aibo Posted February 11, 2010 Share Posted February 11, 2010 and better use isPedInVehicle and getPedOccupiedVehicle why you need to bind "left" to it? is it a GUI button or what? anyway, your code is really a mix of client and server functions, here's the server part: addEvent("fixVehicleRequest", true) addEventHandler("fixVehicleRequest", getRootElement(), function() if isPedInVehicle(source) then fixVehicle(getPedOccupiedVehicle(source)) outputChatBox("Vehicle Successfully Fixed", source, 255, 255, 0, true) else outputChatBox("You are not in a vehicle", source, 255, 0, 0, true) end end ) you need to call this from the client. thru triggerServerEvent i guess: triggerServerEvent("fixVehicleRequest", getLocalPlayer()) Link to comment
Wisin Posted February 11, 2010 Author Share Posted February 11, 2010 yes its a gui window with buttons etc, so i need when click the repair will repair the player vehicle. Edit: wow its working thanks for all guys . i got a question how i can make when hit that button get the player money if he has a special amount if someone can tell me. Link to comment
dzek (varez) Posted February 11, 2010 Share Posted February 11, 2010 post your code pls ps. it will be smth like: local money = getPlayerMoney (source) if (money > 666) then --- do a fix else -- output info end Link to comment
Wisin Posted February 11, 2010 Author Share Posted February 11, 2010 addEvent("fixVehicleRequest", true) addEventHandler("fixVehicleRequest", getRootElement(), function() if isPedInVehicle(source) then local money = getPlayerMoney (source) if (money > 666) then fixVehicle(getPedOccupiedVehicle(source)) outputChatBox("Vehicle Successfully Fixed", source, 255, 255, 0, true) else outputChatBox("You are not in a vehicle", source, 255, 0, 0, true) end end ) i did that its that right? i get a error at debugscript player-menu-s.lua:13: unexpected symbol near ")" Link to comment
Aibo Posted February 11, 2010 Share Posted February 11, 2010 you haven't closed "if (money > 666) then" with "end" addEvent("fixVehicleRequest", true) addEventHandler("fixVehicleRequest", getRootElement(), function() if isPedInVehicle(source) then if (getPlayerMoney(source) > 666) then takePlayerMoney(source, 666) fixVehicle(getPedOccupiedVehicle(source)) outputChatBox("Vehicle Successfully Fixed", source, 255, 255, 0, true) else outputChatBox("Not enough money.", source, 255, 0, 0, true) end else outputChatBox("You are not in a vehicle", source, 255, 0, 0, true) end end ) Link to comment
Vercetti1010 Posted February 11, 2010 Share Posted February 11, 2010 You have to use a combination of a clientside script and a serverside script. Buttons and other GUI elements can only be done clientside. However, things that can affect gameplay for you and others, such as fixing a car, are best done serverside. You can pull this off, but you will need to link the two scripts. Create a custom serverside event to trigger the fix. Have the GUI button trigger a function that has triggerServerEvent in it. How the window opens and goes away is totally up to you. I hope I have helped a little Link to comment
Castillo Posted February 12, 2010 Share Posted February 12, 2010 thanks for all guys now its fully working. 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