Jump to content

setControllState Problem


Xwad

Recommended Posts

Im trying to brake the vehicle when i stop pressing the "w". Its not working

function brake() 
    local vehicle = getPedOccupiedVehicle(localPlayer) 
    local id = getElementModel ( vehicle ) 
    if id == 432 then 
setControlState ( vehicle,"handbrake", true ) 
end 
end 
bindKey ( "w", "up", brake )  
  

Link to comment

It's running client-side I suppose since you're using localPlayer?

Read the wiki entry for setControlState more thoroughly. Only server-side need an element, a player element - not a vehicle element.

Using it client-side, you needn't enter any element since it's run on the client. So it's obvious you want to do it on the client.

function brake() 
    local vehicle = getPedOccupiedVehicle(localPlayer) 
    local id = getElementModel(vehicle) 
    if(id == 432) then 
        setControlState("handbrake", true) 
    end 
end 
bindKey("w", "up", brake) 

Other than that, make sure you use debugscript to catch any errors and warnings. Go to the wiki to further study the function that is outputting an error and thus help yourself instead of rushing to the forums.

In my opinion, trial and error is what programming and scripting is all about - best way to learn it.

Link to comment

Bro.. Simple logic... Just figure this logic-map out...

  
function something( ... ) 
   if(getPedControlState("w") == false) then 
      setPedControlState("s"); -- I know the function is wrong.. this is just the logic map 
   end 
end 
  

I hope you understood. if you didn't then I'll show it in the codes.

Link to comment

Bro.. Simple logic... Just figure this logic-map out...

  
function something( ... ) 
   if(getPedControlState("w") == false) then 
      setPedControlState("s"); -- I know the function is wrong.. this is just the logic map 
   end 
end 
  

I hope you understood. if you didn't then I'll show it in the codes.

Link to comment
Bro.. Simple logic... Just figure this logic-map out...
  
function something( ... ) 
   if(getPedControlState("w") == false) then 
      setPedControlState("s"); -- I know the function is wrong.. this is just the logic map 
   end 
end 
  

I hope you understood. if you didn't then I'll show it in the codes.

Deepu, you're totally wrong, "(getPed/setPed)ControlState works only with the peds not with local player since it's client sided

Link to comment
Bro.. Simple logic... Just figure this logic-map out...
  
function something( ... ) 
   if(getPedControlState("w") == false) then 
      setPedControlState("s"); -- I know the function is wrong.. this is just the logic map 
   end 
end 
  

I hope you understood. if you didn't then I'll show it in the codes.

Deepu, you're totally wrong, "(getPed/setPed)ControlState works only with the peds not with local player since it's client sided

Link to comment

@Xwad, I tried to make a proper code for you:

Here you go:

try it and tell me the result, because it's not tested

--client sided !

bindKey("w","up", 
function () 
    local localPlayer = getLocalPlayer() 
    local vehicle = getPedOccupiedVehicle(localPlayer) 
    if vehicle then  
        local driver = getVehicleController(vehicle) 
        local theID = getElementModel(vehicle) 
        if (driver == localPlayer and theID == 432) then  
            setControlState("handbrake", true)       
        end 
    end  
end) 

Link to comment

@Xwad, I tried to make a proper code for you:

Here you go:

try it and tell me the result, because it's not tested

--client sided !

bindKey("w","up", 
function () 
    local localPlayer = getLocalPlayer() 
    local vehicle = getPedOccupiedVehicle(localPlayer) 
    if vehicle then  
        local driver = getVehicleController(vehicle) 
        local theID = getElementModel(vehicle) 
        if (driver == localPlayer and theID == 432) then  
            setControlState("handbrake", true)       
        end 
    end  
end) 

Link to comment

Yeah I got it, try it now

bindKey("w","up", 
function () 
    local localPlayer = getLocalPlayer() 
    local vehicle = getPedOccupiedVehicle(localPlayer) 
    if vehicle then 
        local driver = getVehicleController(vehicle) 
        local theID = getElementModel(vehicle) 
        if (driver == localPlayer and theID == 432) then 
            setControlState("handbrake", false)      
        end 
    end 
end) 

Link to comment

Yeah I got it, try it now

bindKey("w","up", 
function () 
    local localPlayer = getLocalPlayer() 
    local vehicle = getPedOccupiedVehicle(localPlayer) 
    if vehicle then 
        local driver = getVehicleController(vehicle) 
        local theID = getElementModel(vehicle) 
        if (driver == localPlayer and theID == 432) then 
            setControlState("handbrake", false)      
        end 
    end 
end) 

Link to comment

@Xwad..

Make sure that yu have attached the function to the right event cuz that might cause problems and bugs too.

If its alright proceed to step 2:

  
if getControlState("accelerate") == false then 
   setControlState("handbrake", true); 
end 
  

if its not working in client side use it in server side by placing the first argument as "playername" in both of the functions

Link to comment

@Xwad..

Make sure that yu have attached the function to the right event cuz that might cause problems and bugs too.

If its alright proceed to step 2:

  
if getControlState("accelerate") == false then 
   setControlState("handbrake", true); 
end 
  

if its not working in client side use it in server side by placing the first argument as "playername" in both of the functions

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