Jump to content

[help]fix vehicle


Wisin

Recommended Posts

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 by Guest
Link to comment

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

and better use isPedInVehicle and getPedOccupiedVehicle :P

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

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

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

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

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