Jump to content

setPedControlState


Recommended Posts

Alright, so I've made an epic strategy-based team combat gamemode and I'm currently scripting in attack helicopters that are similar to those found in Call of Duty Black Ops ( its AI controlled ). Presented below is my initial test code to see how MTA reacts. My problem is, when the attack helicopter begins to get close to me, my game freezes up and I am forced to shut down the game through Task Manager. Does anyone have a suggestion for controlling a ped's AI flying?

Server-side code

  
function onPlayerHelicopter ( player ) 
    local x, y, z = getElementPosition ( player ) 
    ped = createPed ( 124, 0, 0, 3 ) 
    veh = createVehicle ( 425, 0, 0, 5 ) 
    warpPedIntoVehicle ( ped, veh ) 
    setTimer ( setElementPosition, 7000, 1, veh, x + 30, y, z + 40 ) 
    setElementID( ped, "ped" ) 
    setTimer ( triggerClientEvent, 7000, 1,  player, "onClientPlayerHelicopter", getRootElement() ) 
end 
  
addCommandHandler ( "air", 
    function ( player, command ) 
        onPlayerHelicopter ( player ) 
    end 
) 
  
  

Client-side code

  
function onClientPlayerHelicopter ( ) 
    ped = getElementByID ( "ped" ) 
    setPedControlState( ped, "accelerate", true ) 
    controlChopperOn( ) 
end 
  
function controlChopperOn () 
    setPedControlState ( ped, "steer_forward", true ) 
    setPedControlState ( ped, "vehicle_secondary_fire", true ) 
    setTimer ( controlChopperOff, 750, 0 ) 
end 
  
function controlChopperOff () 
    setPedControlState ( ped, "steer_forward", false ) 
    setPedControlState ( ped, "vehicle_secondary_fire", false ) 
    setTimer ( controlChopperOn, 750, 0 ) 
end 
  
addEvent( "onClientPlayerHelicopter", true ) 
addEventHandler( "onClientPlayerHelicopter", getRootElement( ), onClientPlayerHelicopter ) 
  

Obviously the code is primitive, but I am using the timer loop between the two functions because, as you may know, if you hold the hunter chopper forward key, you'll eventually flip over. Im looking for a relatively simple formula for maneuvering the attack helicopter forward and flying over the location whilst firing.

Link to comment

Thanks for the link and for the example. I'm in favor of a setElementPosition() method, possibly doing it client-side triggered by the "onClientRender" event. I tried a timer at a 50ms interval and increasing position by one but its very jumpy. We shall see. I suppose ill createProjectile client-side rather than setPedControlState() for vehicle_fire.

Link to comment
That looks pretty hard.
    setTimer ( controlChopperOff, 750, 0 ) 
    setTimer ( controlChopperOn, 750, 0 )  

These timers never get disabled, you probably want to change the 0 to 1.

yes, this looks like something that may crash the server...

This may be not what you're looking for, but there exists an 'AI' hunter resource for race. I believe it uses setElementPosition but you can take a look in it.

it uses moveObject serverside, this is very easy to controll, and looks good (but not perfect)

@TheGhost, if you want to use some part of the code, at lest give me credit, but controll state will make it look more natural ;)

By the way, setPedControlState is also server side.

client only function...

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