SetControlState: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (Moved the section header)
Line 19: Line 19:


==Example==   
==Example==   
<section name="Server" class="server" show="false">
<section name="Server" class="server" show="true">
This example will disable the use of the accelerate, brake/reverse and handbrake keys, then force the accelerate on for any player who enters a vehicle.  
This example will disable the use of the accelerate, brake/reverse and handbrake keys, then force the accelerate on for any player who enters a vehicle.  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function onPlayerEnterVehicle ( theVehicle, seat, jacked )
function onPlayerEnterVehicle ( theVehicle, seat, jacked )
  toggleControl ( source, "accelerate", false ) -- disable the accelerate key
    toggleControl ( source, "accelerate", false ) -- disable the accelerate key
  toggleControl ( source, "brake_reverse", false ) -- disable the brake_reverse key
    toggleControl ( source, "brake_reverse", false ) -- disable the brake_reverse key
  toggleControl ( source, "handbrake", false ) -- disable the handbrake key
    toggleControl ( source, "handbrake", false ) -- disable the handbrake key
  setControlState ( source, "accelerate", true ) -- force the accelerate key on
    setControlState ( source, "accelerate", true ) -- force the accelerate key on
end
end
addEventHandler ( "onPlayerEnterVehicle", getRootElement(), onPlayerEnterVehicle )
addEventHandler ( "onPlayerVehicleEnter", getRootElement(), onPlayerEnterVehicle )
</syntaxhighlight>
</syntaxhighlight>
</section>
</section>


<section name="Client" class="client" show="false">
<section name="Client" class="client" show="true">
This example will disable the use of the accelerate, brake/reverse and handbrake keys, then force the accelerate on for any player who enters a vehicle.  
This example will disable the use of the accelerate, brake/reverse and handbrake keys, then force the accelerate on for any player who enters a vehicle.  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">


function onClientPlayerEnterVehicle ( theVehicle, seat, jacked )
function onClientPlayerEnterVehicle ( theVehicle, seat, jacked )
  toggleControl ( "accelerate", false ) -- disable the accelerate key
    toggleControl ( "accelerate", false ) -- disable the accelerate key
  toggleControl ( "brake_reverse", false ) -- disable the brake_reverse key
    toggleControl ( "brake_reverse", false ) -- disable the brake_reverse key
  toggleControl ( "handbrake", false ) -- disable the handbrake key
    toggleControl ( "handbrake", false ) -- disable the handbrake key
  setControlState ( "accelerate", true ) -- force the accelerate key on
    setControlState ( "accelerate", true ) -- force the accelerate key on
end
end
addEventHandler ( "onClientPlayerVehicleEnter", getRootElement(), onClientPlayerEnterVehicle )
addEventHandler ( "onClientPlayerVehicleEnter", getRootElement(), onClientPlayerEnterVehicle )

Revision as of 17:22, 4 April 2009

Sets a state of a specified player's control, as if they pressed or released it.

Syntax

Click to collapse [-]
Server
bool setControlState ( player thePlayer, string control, bool state ) 
Click to collapse [-]
Client
bool setControlState ( string control, bool state ) 

Required Arguments

  • thePlayer: The player you wish to set the control state of.
  • control: The control that you want to set the state of. See control names for a list of possible controls.
  • state: A boolean value representing whether or not the key will be set to pressed or not.

Returns

Returns 'true' if the control state was successfully set, 'false' otherwise.

Example

Click to collapse [-]
Server

This example will disable the use of the accelerate, brake/reverse and handbrake keys, then force the accelerate on for any player who enters a vehicle.

function onPlayerEnterVehicle ( theVehicle, seat, jacked )
    toggleControl ( source, "accelerate", false ) -- disable the accelerate key
    toggleControl ( source, "brake_reverse", false ) -- disable the brake_reverse key
    toggleControl ( source, "handbrake", false ) -- disable the handbrake key
    setControlState ( source, "accelerate", true ) -- force the accelerate key on
end
addEventHandler ( "onPlayerVehicleEnter", getRootElement(), onPlayerEnterVehicle )
Click to collapse [-]
Client

This example will disable the use of the accelerate, brake/reverse and handbrake keys, then force the accelerate on for any player who enters a vehicle.


function onClientPlayerEnterVehicle ( theVehicle, seat, jacked )
    toggleControl ( "accelerate", false ) -- disable the accelerate key
    toggleControl ( "brake_reverse", false ) -- disable the brake_reverse key
    toggleControl ( "handbrake", false ) -- disable the handbrake key
    setControlState ( "accelerate", true ) -- force the accelerate key on
end
addEventHandler ( "onClientPlayerVehicleEnter", getRootElement(), onClientPlayerEnterVehicle )

See Also