Jump to content

Desynced peds


Drakath

Recommended Posts

Posted

I made a simple script that spawns peds around you. It seems like peds never get desynced when playing on flat surface as the airport. However, when I play on a bumpy surface like San Fierro, many peds get desynced. It seems like desynced peds always spawn on the sideways, I never seen a desynced pedestrian on the street. This probably means that they end up on sideways by falling under the ground. I don't know how it is possible since I use getGroundPosition. I know many scripts like the most popular script in the community (zombies script) somehow avoid desynced zombies. Does anyone know how I can do that in my script?

Server:

addEvent("makeped", true) 
function makeped (x, y, z) 
    if math.random(1,2) == 1 then 
        x = x + math.random(15,40) 
    else 
        x = x + math.random(-40,-15) 
end 
    if math.random(1,2) == 1 then 
        y = y + math.random(15,40) 
    else 
        y = y + math.random(-40,-15) 
end 
local ped = createPed (290, x, y, z+5, 0) 
setElementSyncer(ped, client) 
end 
addEventHandler("makeped", root, makeped) 

Client:

function haha() 
local x, y, z = getElementPosition(localPlayer) 
triggerServerEvent("makeped", resourceRoot, x, y, getGroundPosition(x, y, z)) 
end 
setTimer(haha,math.random(2000,5000),0) 

s.epicrow.com:22003.png

Posted

I remember doing something similar using getGroundPosition, it was also buggy and sometimes they would spawn underground. I think I fixed it by increasing the z coordinate so that's above the ground at all possible cases.

Try this:

  
function haha() 
local x, y, z = getElementPosition(localPlayer) 
triggerServerEvent("makeped", root, x, y, getGroundPosition(x, y, z + 500)) 
end 
setTimer(haha,math.random(2000,5000),0) 
  

Business System viewtopic.php?f=108&t=35797

Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726

SQLite Tutorial viewtopic.php?f=148&t=38203

Posted

Perhaps this will help:

function haha() 
local x, y, z = getElementPosition(localPlayer) 
if math.random(1,2) == 1 then 
        x = x + math.random(15,40) 
    else 
        x = x + math.random(-40,-15) 
end 
    if math.random(1,2) == 1 then 
        y = y + math.random(15,40) 
    else 
        y = y + math.random(-40,-15) 
end 
triggerServerEvent("makeped", root, x, y, getGroundPosition(x, y, z + 500)) 
end 
setTimer(haha,math.random(2000,5000),0) 

addEvent("makeped", true) 
function makeped (x, y, z) 
local ped = createPed (290, x, y, z+5, 0) 
setElementSyncer(ped, client) 
end 
addEventHandler("makeped", root, makeped) 

Business System viewtopic.php?f=108&t=35797

Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726

SQLite Tutorial viewtopic.php?f=148&t=38203

Posted

It worked, peds now spawn on rooftops instead of getting desynced! You are awesome, thank you :)

It's kind of weird though, I always thought that the server is more reliable in setting the coordinates.

s.epicrow.com:22003.png

Posted

The thing is (which I missed when I first posted) that you get the ground position of the current localPlayer's position, you then change it server-side so the original ground position (which is related to the localPlayer) is not the ground position of the ped's position.

Business System viewtopic.php?f=108&t=35797

Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726

SQLite Tutorial viewtopic.php?f=148&t=38203

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