85485 Posted February 7, 2023 Share Posted February 7, 2023 How do i make a server sided setpedcontrolstate? I want to make a npc and that npc drives car, but i cant use setpedcontrolstate because its client sided function. Link to comment
Trust aka Tiffergan Posted February 7, 2023 Share Posted February 7, 2023 Create a custom event in your script that will trigger the NPC driving the car. 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. 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. 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
85485 Posted February 8, 2023 Author Share Posted February 8, 2023 16 hours ago, Trust aka Tiffergan said: Create a custom event in your script that will trigger the NPC driving the car. 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. 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. 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
FLUSHBICEPS Posted February 8, 2023 Share Posted February 8, 2023 --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
Sr.black Posted February 8, 2023 Share Posted February 8, 2023 Create a custom event in your script that will trigger the NPC driving the car. 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. 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. 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now