Hey there,
question is in the title. I’d like to get peds to execute tasks while they are far away from any players.
Small definition: When talking about “vehicles” I always refer to spawning a ped inside a vehicle. “Peds” always refer to “ped on foot”.
Here’s the deal:
When spawning peds far away they won’t react at all. No matter what I tried they wouldn’t bother doing anything (except for one task I tried: TaskAimGunAtEntity() worked fine for some reason) and stand around. I tried
- ragdolling them
- using ActivatePhysics() on them
- using SetEntityActivatesPhysicsAsSoonAsUnfrozen() on them
- using FreezeEntityPosition() to freeze and unfreeze them
- using SetEntityDynamic() on them
- using SetEntityCollision() on them
- using ArePathNodesLoadedInArea() as the description states this could load the path nodes in the area
- use LoadAllPathNodes(false) [unsure if that actually did anything as the description states this was removed]
- various combinations of NetworkRegisterEntityAsNetworked(), SetBlockingOfNonTemporaryEvents(), the last boolean of SpawnPed() / SpawnVehicle()
I am coding on my own private server and am the only player on it. This means that I should be the entity owner and allowed to do everything named above.
Spawning vehicles was VERY unreliable, working only a few times then not. This is while using the same source code. Sketch:
local FarAwayCoords = {x = FarAwayX, y = FarAwayY, z = FarAwayZ}
local vehicle = CreateVehicle( FarAwayCoords, [use proper parameters in here])
local pedInVeh = CreatePed( FarAwayCoords, [use proper parameters in here])
local pedOnFoot = CreatePed( FarAwayCoords, [use proper parameters in here])
SetPedIntoVehicle(pedInVeh, vehicle, -1)
TaskVehicleDriveWander(pedInVeh, vehicle, 17.0, 786603)
TaskWanderStandard(pedOnFoot, 10.0, 10)
This doesn’t execute most of the times for vehicles either, I pretty much tried the same as for peds.
Please note that another script I have written works absolutely perfect with no problems of the vehicles not starting to move. Big (and IMO only) difference is that the working script executes events while the non-working version is triggered in a function.
Shortly ago I had the idea to cheese the problem. The idea is to spawn peds and vehicles close to the player and then tp them away:
local FarAwayCoords = {x = FarAwayX, y = FarAwayY, z = FarAwayZ}
local playerped = GetPlayerPed(-1)
local plpedcoords = GetEntityCoords(playerped)
local pedOnFoot = CreatePed(plpedcoords, [use proper parameters here])
local pedInVeh = CreatePed(plpedcoords, [use proper parameters here])
local vehicle = CreateVeh(plpedcoords, [use proper parameters here])
SetPedIntoVehicle(pedInVeh, vehicle, -1)
TaskVehicleDriveWander(ped, vehicleInVeh, 17.0, NormalDrivingBehavior)
TaskWanderStandard(pedOnFoot, 10.0, 10)
Wait(100)
SetEntityCoords(pedOnFoot, FarAwayCoords)
SetEntityCoords(pedInVeh, FarAwayCoords)
SetEntityCoords(vehicle, FarAwayCoords)
SetPedIntoVehicle(pedInVeh, vehicle, -1)
TaskVehicleDriveWander(pedInVeh, vehicle, 17.0, NormalDrivingBehavior)
TaskWanderStandard(pedOnFoot, 10.0, 10)
Doing this I discovered the following:
It seems that vehicles will now consistently start moving and drive around after being teleported away.
Peds will walk around as long as they are near the player. Upon getting teleported away they will stop doing anything. If the player teleports (or drives) near the ped they will execute their movement task. If the player teleports away they will stop.
Any idea if the server-version or the manifest-version could have a big influence on this behavior? From the findings I’d conclude that it is not possible to get peds to act far away from the player however I don’t really believe this…