• 2 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Suggestion] Population Sync
#1
Star 
Population Sync



I am not sure whether this has been suggested before, however after a quick forum search I didn't find anything like this.



It would just be a great thing?to have the default?San Andreas population while playing online!







How would it work?



Every client will just let the GTA:SA default population spawning logic be, and for each ped that is spawned by it, sync it with the server. When two clients?are close to each-other, an algorithm selects the client in charge to sync the population. The peds will also be automatically transferable from a client to another based on latency and other variables.?



Basically, the client with the best conditions?(I will call it master) creates the peds, gets their info (skin, position, speed, animations, weapons, and everything), and sends that info to the server.



The other clients (I will call them?slaves) will simply get this data from the server, and create simple peds that don't follow the logic of their own game, but instead, use the received data. Every single ped will have a unique id on the server.?



In the case of ped driving vehicles, every time the client generates a vehicle for a ped to drive, it will inform the server, which will then keep track of that vehicle until the ped despawns.







TL;DR Basically, like in FiveM.







Server functions and callbacks



Notice: This is just a prototype, and functions might be incorrect?(e.g. I didn't use output/reference?params nor return tags?to simplify reading).



Code:
// enable or disable the feature altogether (if disabled, peds will not be generated by the clients'?games)



TogglePopulation(bool:toggle);







// sets the density multiplier?of population for all players



// 1.0 = default (1x)



SetPopulationDensity(Float:density);







// given a certain client, gets all the peds that are streamed in for it



GetPlayerStreamedPeds(playerid);







// given a certain client, gets all the peds that are being controlled by it



GetPlayerOwnedPeds(playerid);







// will get all peds that are known to the server



GetAllPeds();



// returns whether a ped is valid

IsValidPed(Ped:ped);



// gets a ped's owner (player)

GetPedOwner(Ped:ped);



// gets the ped pool's?size

GetPedPoolSize();







// gets a ped's position



GetPedPosition(Ped:ped);



// gets a ped's facing angle

GetPedFacingAngle(Ped:ped);







// gets a ped's vehicle



GetPedVehicleId(Ped:ped);



// gets the ped's current weapon

GetPedWeapon(Ped:ped);



// returns whether a certain ped is streamed-in (visible) for a certain player

IsPedStreamedIn(Ped:ped, playerid);



// gets a ped's skin model

GetPedSkin(Ped:ped);



// gets a ped's interior

GetPedInterior(Ped:ped);



// gets a ped's health

GetPedHealth(Ped:ped);



// gets a ped's body armor

GetPedArmour(Ped:ped);



// gets a ped's [url=https://www.grandtheftwiki.com/Ped_Type]type[/url]

// eg:?CIVMALE or?COP

// could be used to check whether a ped is a cop for example

GetPedType(Ped:ped);



// gets a ped's [url=https://gtamods.com/wiki/Pedstats.dat]stats[/url]

// eg:?STAT_TOUGH_GUY or?STAT_TAXIDRIVER

GetPedStats(Ped:ped);



// gets a ped's vehicle id

GetPedVehicleId(Ped:ped);



// gets a ped's velocity

GetPedVelocity(Ped:ped);



// gets a ped's weapon skill level

GetPedSkillLevel(Ped:ped, skill);



// gets a ped's current animation index

GetPedAnimationIndex(Ped:ped);







//-------------- callbacks ---------------



// called when a ped was created/spawned

// creatorid is the player that synced the ped for the first time

// in a subsequent step, that ped's ownership?may have been transferred to another player

OnPedSpawn(Ped:ped, creatorid);



// called when a ped has died

// killerType is either "ped" or "player" (or none), and killerid contains the id of one of those two entities

OnPedDeath(Ped:ped, killerType, killerid, reason);



// called when a ped enters a vehicle

OnPedEnterVehicle(Ped:ped, vehicleid);



// called when a ped exits a vehicle

OnPedExitVehicle(Ped:ped, vehicleid);



// called when a ped is streamed in for a player

OnPedStreamIn(Ped:ped, forplayerid);



// called when a ped is streamed out?for a player

OnPedStreamOut(Ped:ped, forplayerid);



// called when a ped gives damage to another ped or player

OnPedGiveDamage(Ped:ped, damagedType, damagedId, Float: amount, weaponid, bodypart);



// called when a ped gives damage to another ped or player

OnPedTakeDamage(Ped:ped, issuerType, issuerid, Float: amount, weaponid, bodypart);





That's pretty much everything that came to my mind at this moment. Of course more functions could be made.



What do you guys think of this suggestion? Think about how radically differents servers will be with population in them :)
[Image: Sasinosoft.png]

  Reply
#2
If I remember correctly, the main reason why we got recorded NPCs was because Kalcor didn't want to put ped sync into the hands of the clients, and since the server doesn't run an instance of the game there would be no other way to sync them. I guess, we have two options:



1. Letting the clients sync the peds lets us use the game's existing ped AI, so we as a community wouldn't have to implement our own one. I don't know what the implications of trusting the client to sync the peds are, though. A player who's in charge of ped sync could be running an annoying ped AI mod and wreak havoc.

2. Letting the server sync the peds provides a uniform ped AI for all players. However, we would have to implement the ped AI by ourselves.



My personal opinion is that we're better off going with server-side NPCs.

[*]The paths can be extracted from the game files.

[*]Ped AI shouldn't be too difficult to implement. Vehicle AI is definitely more challenging.
  Reply
#3
I wouldn't trust the client with handling population sync either. Would be way too easy to spoof and cause havoc. Using decompiled scripts it would be possible to recreate ped AI. Although a few limitations exist at the moment which are: One client can only show up to 51 NPCs (Actors) and a server can only have 1000 of them.
  Reply
#4
(2020-09-11, 10:43 AM)Manyula Wrote: If I remember correctly, the main reason why we got recorded NPCs was because Kalcor didn't want to put ped sync into the hands of the clients



(2020-09-13, 11:58 AM)LaszloR1 Wrote: I wouldn't trust the client with handling population sync either. Would be way too easy to spoof and cause havoc.



FiveM has been doing basically the same thing; yeah some people tried to cheat by creating fake peds and manipulating them, ok, but with frequent updates that problem doesn't exist. There is no problem in letting clients be the brains of peds if there are systems put in place to prevent spoofing and frequent updates to deter hackers from building those programs.
[Image: Sasinosoft.png]

  Reply
#5
It's definitely possible to do this, and the server doesn't need the game files, we could maybe down the line re-implement this ourselves using our system, or we could find a way to piggy back off the current implementation and yet still have the server be in charge of sync.

It's not impossible, it's just quite a big task to do, and it's not going to be a priority for us. However since the idea of open.mp is to be open source eventually, the whole community is freely available to contribute help towards making this possible.
Remember to always refer to J0sh as `J0sh...`



@ Networks/Servers

San Andreas Gaming Network (Owner/Founder)

San Andreas Gaming (Owner/Founder)

Grand Theft Cop's n Robber's (Owner)

Britannia Roleplay (Owner/Founder) [Retired]

Alpine RP (Owner/Founder)

Aluminium Network (Maintainer) [Disbanded]

AlphaDM (Tech Support) [Disbanded]



# Services

forum.open.mp (Forum Manager) (Formerly Burgershot.gg

open.mp (Member)



~ Languages/Frameworks

Pawn, C, C, C#, Javascript, Typescript, Lua, Python, Go, Rust, PHP, SQL,

Angular, React, Vue, Svelte, Laravel, Rocket
  Reply
#6
I always assumed the game's implementation couldn't be used because the server doesn't run an instance of the game. So, would those peds be any different from regular NPCs then? And while we're on the subject of contributing: Do you guys have a contribution guide in place?
  Reply
#7
(2020-09-15, 07:56 PM)Manyula Wrote: I always assumed the game's implementation couldn't be used because the server doesn't run an instance of the game. So, would those peds be any different from regular NPCs then? And while we're on the subject of contributing: Do you guys have a contribution guide in place?



NPCs arent made out of miracle dust. You don't need the game to run it to have a population system. They are just very basic AI that follow paths and react to what is happening around them and to them.
  Reply
#8
I support this completely. Ive always wanted this.
  Reply
#9
Damn, I've always wanted something like that. Adding peds would be such a huge leap for the mod and it would add those singleplayer vibes it could made the mod more popular towards GTA SA's nostalgics. Years ago, when?I discovered SA-MP,?I've been excited by the possibility of a real multiplayer on San Andreas but even disappointed for the dearth of SP features. And the lack of pedastrians was by far the most disappointing?one.
  Reply


Forum Jump: