2020-09-09, 11:49 PM
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).
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 :)
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 :)