Jump to content

Vehicle


Perfect

Recommended Posts

Hi All , my script not working at all. I don't know why because i am beginner :P

here it's my scripte

  
addCommandHandler("vehiclecontrol", 
    function(theVehicle, command, source) 
        if source then 
            if getVehicleFromName(vehicle) then 
                local vehicle = getVehicleFromName(vehicle) 
                local theVehicle = thevehicle 
                    setCameraTarget(thePlayer, player) 
                    toggleAllControls(vehicle, false) 
                    toggleControl(vehicle, "chatbox", true) 
                    toggleControl(vehicle, "playerlist", true) 
                    function bindEightDown() 
                        setElementData(theVehicle, "Player Pressing 8", true) 
                    end 
                     
                    bindKey(thePlayer, "num_8", "down", bindEightDown) 
                    bindKey(thePlayer, "num_8", "up", bindEightUp) 
                     
                    bindKey(thePlayer, "num_4", "down", bindFourDown) 
                    bindKey(thePlayer, "num_4", "up", bindFourUp) 
                     
                    bindKey(thePlayer, "num_6", "down", bindSixDown) 
                    bindKey(thePlayer, "num_6", "up", bindSixUp) 
                     
                    bindKey(thePlayer, "num_2", "down", bindTwoDown) 
                    bindKey(thePlayer, "num_2", "up", bindTwoUp) 
                     
                    bindKey(thePlayer, "num_5", "down", bindFiveDown) 
                    bindKey(thePlayer, "num_5", "up", bindFiveUp) 
                setVehicleControl(True) 
                        function() 
                                setControlState(player, "brake_reverse", true) 
                            else 
                                setControlState(player, "brake_reverse", true) 
                            end 
  
                                setControlState(player, "accelerate", true) 
                            else 
                                setControlState(player, "accelerate", true) 
                            end 
     
                                setControlState(player, "vehicle_left", true) 
                            else 
                                setControlState(player, "vehicle_left", true) 
                            end 
                             
                                setControlState(player, "vehicle_right", true) 
                            else 
                                setControlState(player, "vehicle_right", true) 
                            end 
                        end 
                    addEventHandler("onConsole", thePlayer, releaseControlCommand) 
  

EDIT: I want to control my vehicle with distance by using num keys.

Link to comment

Why don't you tell him what /debugscript is for?

If you are logged in as an admin, you can use the "/debugscript 3" command. It creates some sort of chatbox at the bottom of your screen and if a script isn't working, it outputs the reason for it in there. For example, it says syntax error in server.lua at line 32: bad argument at 'getElementPosition'. This means that in server.lua, line 32 there's something wrong in 'getElementPosition'.

As for your script, you should start reading the page about 'addCommandHandler':

https://wiki.multitheftauto.com/wiki/AddCommandHandler

First parameter in the function you call is a player and yours is 'theVehicle'. Would be pretty weird if vehicles could use commands :D . You have to change it to 'player' for example and after that, you write 'theVehicle = getPedOccupiedVehicle ( player )'.

Link to comment

because i gave him a link.

Debug console

MTA features a built-in debug console that shows debug messages output from MTA functions or from scripts. You can open it by typing debugscript x in console, while x is the debug level:

1: only errors

2: errors and warnings

3: errors, warnings and info messages

Thus, by typing debugscript 3 all messages are visible, that or level 2 are recommended for most occasions. You should have debugscript enabled most of the time you are testing your scripts, this will help you detect typos or other simple issues and solve them easily.

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