Anyone know how to create/manage peds on the server-side?

As far as I can tell, the server side script doesn’t know what "CreatePed(…)’ is, so clientside is the only way I can figure out to spawn them.

Also, I’m creating a thread that loops that manages the ped’s AI that governs what the ped does, but again, a lot of the native functions I’m using to help with the AI don’t work on the server script. When I go offline, the peds’ AI breaks and won’t work even if I go back online.

Any tips on creating/managing peds on the server script? Thanks!

1 Like

If you do this:
Client.lua

RegisterNetEvent("spawnped")
AddEventHandler("spawnped", function()
--Your code where you spawn a ped
end)

Server.lua

RegisterCommand("spawnped", function(source, args, raw)
TriggerClientEvent("spawnped", -1)
--The "-1" makes it so it does it on everyones client not only yours
end)

It should work. :slight_smile:

2 Likes

I am having a similar question…

Altough, if im wanting to spawn a ped from server to client at the same coords with a TriggerClientEvent('spawnped', -1) this would make multiple peds right?

Is there an way to still get everyone the same event where it spawn the ped, but let it still spawn one ped for the hole server…

Just use CreatePed on the server.

1 Like

there is no information about it in docs, so what handle does it return? how to use it on client side?

and then, how i can set to that ped for example “SetEntityAsMissionEntity”?, bc if i Trigger a event to client it can’t do it, idk why

A ped created from script is already a ‘mission entity’.

okay, then “TaskWanderStandard” or other thing that you can do to an ped

I have seen this topic

But i did not understand how to do it

You can use these on a server side:

You can create global bags or attach info to your entity:

You can also send the netID to a client side:

3 Likes

Does one have to worry about clients loading the ped model?

I don’t understand how to use the RPC’s server side?

You have to use it like any other native. However, there are some that require a client to actually execute them.