Making MMOItems move

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

genar
Posts: 137
Joined: 13 Jul 2017, 11:49

Making MMOItems move

Postby genar » 12 Nov 2020, 15:23

So im using MMOItems on the server and client to display mobs and i have a lot of mobs, so the npc system is no option here ( No money ).

The problem here is that mmoApi.setMMOItemPosition() seems to update the position, but it wont fire some sort of position update if its already in the aoi. That means it fires once and thats it. Thats awfull for items that SHOULD move around.

I listen on the client for several updates...

Code: Select all

            connectionManager.Sfs.AddEventListener(SFSEvent.PROXIMITY_LIST_UPDATE, OnProximityListUpdate);
            connectionManager.Sfs.AddEventListener(SFSEvent.USER_VARIABLES_UPDATE, OnUserVariablesUpdate);
            connectionManager.Sfs.AddEventListener(SFSEvent.MMOITEM_VARIABLES_UPDATE, OnMMOItemVariablesUpdate);


And i set my variables like this. It works great, i receive those on my client regulary.

Code: Select all

          mmoApi.setMMOItemVariables(mmo.item, vars, !playerQuery.getEntities().isEmpty());


In my case i need to update the mmoitems position, and it works... but only once, which sucks if the item exists and is already in the aoi of the player.

Code: Select all

        // Update position of the item, only if it moved
        if(!transform.position.equals(transform.previousPos))
            mmoApi.setMMOItemPosition(bulletItem, new Vec3D((float)transform.position.x, (float)transform.position.y, 0), room);


So lets say we have a orc which is controlled by the server and that one contains some sort of ai that makes it move around.
We wanna use MMOItems to represent them, how the hell would we make that mob move on the client ?
User avatar
Lapo
Site Admin
Posts: 23025
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Making MMOItems move

Postby Lapo » 13 Nov 2020, 09:16

Sorry, something is not very clear.

You said:
And i set my variables like this. It works great, i receive those on my client regulary.


but then you also said:
In my case i need to update the mmoitems position, and it works... but only once, which sucks if the item exists and is already in the aoi of the player.

Why only once?
If the Item variables are updates you will receive an SFSEvent.MMOITEM_VARIABLES_UPDATE on every change from server side.

Are you saying you're not receiving the var updates after you modify them from server side?

Thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
genar
Posts: 137
Joined: 13 Jul 2017, 11:49

Re: Making MMOItems move

Postby genar » 13 Nov 2020, 13:48

Lapo wrote:Sorry, something is not very clear.

You said:
And i set my variables like this. It works great, i receive those on my client regulary.


but then you also said:
In my case i need to update the mmoitems position, and it works... but only once, which sucks if the item exists and is already in the aoi of the player.

Why only once?
If the Item variables are updates you will receive an SFSEvent.MMOITEM_VARIABLES_UPDATE on every change from server side.

Are you saying you're not receiving the var updates after you modify them from server side?

Thanks


Looks like we mean different things... what i mean MMOItem-Variables are working.
API.setMMOItemPosition() sets the items position, but the client only receives the position ONCE, when it ENTERS the AOI. When that item already exists in the AOI, the player in which AOI it is in wont receive any other position updates of that item.

So i thought i could make the MMOItem move on the CLIENT by setting its position with API.setMMOItemPosition() and react to position change events on the client. WHICH IS NOT THE CASE, because proximity list fires once a item enters the aoi, the item itself only contains the entered proximity position but not the newest position and the variables dont contain the position either.

What i want is something like this :
- Server spawns in mmoitem at position (10,10)
- Client receives the spawning ( Which works already due to the events )
- Server tells mmoitem to move to (20,20) and sets the new position on the item every frame
- Client receives the new position of the already spawned item every tick and makes it move on the client itself

So how the heck should we make items move visually on the client side ? Is this behaviour with API.setMMOItemPosition() intended ?
User avatar
Lapo
Site Admin
Posts: 23025
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Making MMOItems move

Postby Lapo » 13 Nov 2020, 16:21

genar wrote:Looks like we mean different things... what i mean MMOItem-Variables are working.
API.setMMOItemPosition() sets the items position, but the client only receives the position ONCE, when it ENTERS the AOI. When that item already exists in the AOI, the player in which AOI it is in wont receive any other position updates of that item.

That's okay. It is expected to work like that. The AOI events will only tell you what has changed (i.e. new items in the area, or old ones that are no longer there.)

Use the MMOItemVariables instead to update a custom on-screen position.
Although I wouldn't advice to to do it on every frame as you mentioned because that's likely way too many updates.

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
genar
Posts: 137
Joined: 13 Jul 2017, 11:49

Re: Making MMOItems move

Postby genar » 13 Nov 2020, 19:27

Lapo wrote:
genar wrote:Looks like we mean different things... what i mean MMOItem-Variables are working.
API.setMMOItemPosition() sets the items position, but the client only receives the position ONCE, when it ENTERS the AOI. When that item already exists in the AOI, the player in which AOI it is in wont receive any other position updates of that item.

That's okay. It is expected to work like that. The AOI events will only tell you what has changed (i.e. new items in the area, or old ones that are no longer there.)

Use the MMOItemVariables instead to update a custom on-screen position.
Although I wouldn't advice to to do it on every frame as you mentioned because that's likely way too many updates.

Cheers


Ah ok, thanks... i read the docs and i havent found anything about this behaviour. But probably i just missed it.
Are those MMOItem variables transfered by udp or tcp ? Position updates happen very often, even if i only send them every 500 ms it would be great to do that over udp ^^ Is there a way to fine tune this ?
User avatar
Lapo
Site Admin
Posts: 23025
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Making MMOItems move

Postby Lapo » 16 Nov 2020, 15:47

They happen over TCP.
If you want to use UDP, don't use ItemVariables and instead send custom Extension messages that include an ID referencing the MMOItem.

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: Stevenor and 61 guests