Jump to content

Server-sided setpedcontrolstate


85485

Recommended Posts

  1. Create a custom event in your script that will trigger the NPC driving the car.
  2. Within this event, you will use the setElementData function to set a custom server-side variable that will keep track of the NPC's driving state.
  3. You will then create another custom event that will be triggered regularly (for example, using a timer) to update the NPC's driving state based on the value of the custom server-side variable set in step 2.
  4. In this second event, you will use the setPedControlState function to set the NPC's driving state.

This way, you will be able to create a server-side setPedControlState that allows an NPC to drive a car in MTA.                        

Link to comment
16 hours ago, Trust aka Tiffergan said:
  1. Create a custom event in your script that will trigger the NPC driving the car.
  2. Within this event, you will use the setElementData function to set a custom server-side variable that will keep track of the NPC's driving state.
  3. You will then create another custom event that will be triggered regularly (for example, using a timer) to update the NPC's driving state based on the value of the custom server-side variable set in step 2.
  4. In this second event, you will use the setPedControlState function to set the NPC's driving state.

This way, you will be able to create a server-side setPedControlState that allows an NPC to drive a car in MTA.                        

Can you show a example code? :/

Link to comment
--server side
local npc
local infernus

function startNPC(player)
  local x, y, z = getElementPosition(player)
  npc = createPed(0, x, y, z)
  infernus = createVehicle(411, x, y, z)
  warpPedIntoVehicle(npc, infernus)
  triggerClientEvent(player, "switchToThirdPerson", player, npc)
  bindKey(player, "w", "down", function() setControlState(npc, "accelerate", true) end)
  bindKey(player, "s", "down", function() setControlState(npc, "brake_reverse", true) end)
  bindKey(player, "a", "down", function() setControlState(npc, "steer_left", true) end)
  bindKey(player, "d", "down", function() setControlState(npc, "steer_right", true) end)
end

function stopNPC(player)
  removePedFromVehicle(npc)
  destroyElement(infernus)
  triggerClientEvent(player, "switchToFirstPerson", player)
  unbindKey(player, "w", "down")
  unbindKey(player, "s", "down")
  unbindKey(player, "a", "down")
  unbindKey(player, "d", "down")
end

function handleCommand(player, command, parameters)
  if player ~= localPlayer then return end
  if command == "npc" then
    if parameters == "start" then
      startNPC(player)
    elseif parameters == "stop" then
      stopNPC(player)
    end
  end
end

addCommandHandler("npc", handleCommand)
--client side
function switchToThirdPerson(player, npc)
  setCameraTarget(npc)
end

function switchToFirstPerson()
  setCameraTarget(localPlayer)
end

addEvent("switchToThirdPerson", true)
addEventHandler("switchToThirdPerson", root, switchToThirdPerson)

addEvent("switchToFirstPerson", true)
addEventHandler("switchToFirstPerson", root, switchToFirstPerson)

if i understood what u need so this is the script for u make sure to check it again since I didn’t try it also I’m not sure if you can use setCameraTarget on an npc but u can always remove it

so usin wasd keys, the player can control an NPC in a vehicle. When controlling the NPC, it toggles the camera view between u and the npc the command to spawn the npc and vehicle(infernus) is /npc start and /npc stop to remove them 

Link to comment
  1. Create a custom event in your script that will trigger the NPC driving the car.
  2. Within this event, you will use the setElementData function to set a custom server-side variable that will keep track of the NPC's driving state.
  3. You will then create another custom event that will be triggered regularly (for example, using a timer) to update the NPC's driving state based on the value of the custom server-side variable set in step 2.
  4. In this second event, you will use the setPedControlState function to set the NPC's driving state.

This way, you will be able to create a server-side setPedControlState that allows an NPC to drive a car in MTA.                        

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