multitheftauto / mtasa-blue

Multi Theft Auto is a game engine that incorporates an extendable network play element into a proprietary commercial single-player game.
https://multitheftauto.com
GNU General Public License v3.0
1.41k stars 438 forks source link

Add getPlayerSyncerElements #2400

Open ThatG-I opened 3 years ago

ThatG-I commented 3 years ago

Is your feature request related to a problem? Please describe. It's not really a problem. It would be just nice to have.

Describe the solution you'd like A function like getPlayerSyncerElements that returns a table of elements (vehicles and peds) that the player is currently sycning.

Describe alternatives you've considered When I set a player as a syncer of somthing I store that infomation and try to keep it up to date as much as possible.

If anybody is wanting something like we are talking about here you go:

function getElementsSyncedByPlayer( player,  theType )
    local elementsByType = getElementsByType( theType )
    local elementsSyncedByPlayer = {}
    for i, v in pairs(elementsByType) do
        local syncer = getElementSyncer( v )
        if syncer == player then
            table.insert( elementsSyncedByPlayer, v )
        end
    end
    return elementsSyncedByPlayer
end

This is not a nice way of doing it but it's good enough for now I guess

PlatinMTA commented 3 years ago

I do like the idea, but the name seems odd, I wouldn't understand what it does if I hadn't read your description. It could be something like getElementsSyncedByPlayer or something much better than that.

Inder00 commented 3 years ago

In my opinion, the function is unnecessary, the MTA itself synchronizes all the data of the elements.

On clientside you can get list of synced elements using https://wiki.multitheftauto.com/wiki/GetElementsByType functions with streamedIn argument set to true

Inder00 commented 3 years ago

You have also function https://wiki.multitheftauto.com/wiki/SetElementSyncer to change the syncer (player) of an element.

PlatinMTA commented 3 years ago

Is there currently a way to get the elements that a player is currently syncing serverside? getElementsByType with streamIn = true gives a list of current synced elements, but not the ones that the player is syncing (objects do not sync by player if im not wrong, but yet you can get every one that is "streamed in").

I wouldn't know a use for this function tho, but that's probably because I hardly touch my syncers via script.

ThatG-I commented 3 years ago

I do like the idea, but the name seems odd, I wouldn't understand what it does if I hadn't read your description. It could be something like getElementsSyncedByPlayer or something much better than that.

I do agree, that function naming is better suited.

getElementsByType with streamIn = true gives a list of current synced elements, but not the ones that the player is syncing (objects do not sync by player if im not wrong, but yet you can get every one that is "streamed in").

I could make a simple function but it wont be performent that gets all the peds that are streamed in from players. Then loop through each one comparing the syncer to x player and if true store in table and return.

Inder00 commented 3 years ago

Is there currently a way to get the elements that a player is currently syncing serverside? getElementsByType with streamIn = true gives a list of current synced elements, but not the ones that the player is syncing (objects do not sync by player if im not wrong, but yet you can get every one that is "streamed in").

I wouldn't know a use for this function tho, but that's probably because I hardly touch my syncers via script.

There is a way to loop all elements and check them using https://wiki.multitheftauto.com/wiki/GetElementSyncer

ThatG-I commented 3 years ago

You have also function https://wiki.multitheftauto.com/wiki/SetElementSyncer to change the syncer (player) of an element.

The problem is not setting a syncer. As I mentioned in the ticket I use that to store the infomation in a player, but it's very un preticable, becuase there might be a use case where the player is no longer the syncer. I would have to try and think of every use cases to then remove the npc from the player table.

Instead I could just call a simple function getElementsSyncedByPlayer and I can trust that the player is syncing X amount of NPCs instead of trying to hope.

ThatG-I commented 3 years ago

There is a way to loop all elements and check them using https://wiki.multitheftauto.com/wiki/GetElementSyncer

As I just mentioned, that is doable, but it's not really nice. I would assume that in MTA we are storing the elements that are being synced by players somewhere. If that is the case it would be very nice to use that instead of having a hacky loop solution.

ThatG-I commented 3 years ago

If anybody is wanting something like we are talking about here you go:

function getElementsSyncedByPlayer( player,  theType )
    local elementsByType = getElementsByType( theType )
    local elementsSyncedByPlayer = {}
    for i, v in pairs(elementsByType) do
        local syncer = getElementSyncer( v )
        if syncer == player then
            table.insert( elementsSyncedByPlayer, v )
        end
    end
    return elementsSyncedByPlayer
end

This is not a nice way of doing it but it's good enough for now I guess