Jump to content

Trying to make NPC Walk along a Sidewalk


XeroXipher

Recommended Posts

Hello MTA...
Sorry for asking rookie questions so frequently.

So, I am trying to make NPC's on the map walk around.
I know I will have to give them a path to walk (Which I don't know how to do, but I'll get there).

Right now I am finding it hard to get my NPC to even move.
This is the very basic coding I have so far.

Pedestrians.lua


function pedLoad()
    local thePed = createPed ( 106,  2492, -1673, 13.25, 200)
    setPedAnimation(thePed, "ped", "walk_gang1", -1, true, true, false, true)
    outputChatBox("This command did something", player, 100, 255, 100)
    
end
addEventHandler ( "onResourceStart", getResourceRootElement(), pedLoad )

Now this works properly:
 

 local thePed = createPed ( 106,  2492, -1673, 13.25, 200)

It creates my NPC and rotates him 200 degrees...
But the rest of the coding doesn't do anything.

 

I have tried setControlState:
 

function pedLoad()
    local thePed = createPed ( 106,  2492, -1673, 13.25, 200)
    setControlState(thePed, "walk", true)
    setControlState(thePed, "forwards", true)
    outputChatBox("This command did something", player, 100, 255, 100)
    
end
addEventHandler ( "onResourceStart", getResourceRootElement(), pedLoad )

And nothing happened...
I know with setControlState I also have to change his camera to move in different directions but I can't get him to move at all...

So, if someone could help me I would appreciate it.
Thank You.

Link to comment

The wiki's arguments list suggests setControlState only works on players, not any ped. Have you tried setPedControlState client-side? You can trigger it by firing off an event from the server that's handled on the client side.

This may need a lot of synchronisation code though, as a client won't receive this event when connecting after the resource was started, nor if the resource starts and triggers onResourceStart before the client side is ready.

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