how to get 2nd avatar (other user) coordinate

Post here your questions about the OpenSpace 1.x or notify bugs and suggestions.

Moderators: Lapo, Bax

krazl
Posts: 6
Joined: 22 Aug 2009, 01:11
Contact:

how to get 2nd avatar (other user) coordinate

Postby krazl » 22 Aug 2009, 01:28

Hi all.. i'm new to open space so please get used to all my silly questions. :lol:


Is ther anyway we could retrieve 2nd avatar (other user) position. any pseudo code perhaps?

i've added below.

Code: Select all


this.addEventListener(MouseEvent.CLICK, onClick);

public function set isMyAvatar(myAv:Boolean):void
{
   _isMyAvatar = myAv
}

public function onClick(evt:MouseEvent):void
{
   trace("clicked")
   if(!_isMyAvatar)
        {
      trace("not my avatar")
        }
}

public function onMovementStop(evt:AvatarEvent):void
{
        var pemalarB:Object = detectTilePosition()
   trace("My Position = (" + pemalarB.px +","+ pemalarB.py +")")
}


function detectTilePosition():Object
{
   var myPost:Object = {}
                        
   myPost.px = evt["params"].tile.px;
   myPost.py = evt["params"].tile.py;
   myPost.pz = evt["params"].tile.pz;
   return myPost
}




On myAvatar i could produce my coordinate... but not for other user Avatar.. Anything i've missed?

Thx in advance
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 25 Aug 2009, 07:24

Hi,
yes you have Avatar Events, so all you need to do is register a user for events such as ENTER_TILE.
When the event fires it will pass you the Tile object on which the Avatar is located and from there you can get coordinates etc...

Make sure to check the docs.
Lapo
--
gotoAndPlay()
...addicted to flash games
krazl
Posts: 6
Joined: 22 Aug 2009, 01:11
Contact:

Postby krazl » 26 Aug 2009, 00:31

Thx pal.. i manage to get everything now by triggering onClickEvents. Please note that we need to have Global variable to store their position.

I'm wondering how are we going trace other Avatar position when we entering new room. sending message? Anyone have success done this? any psedo code will help. Thx

Lapo wrote:Hi,
yes you have Avatar Events, so all you need to do is register a user for events such as ENTER_TILE.
When the event fires it will pass you the Tile object on which the Avatar is located and from there you can get coordinates etc...

Make sure to check the docs.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 26 Aug 2009, 07:26

Normally, you would not need this. At least from client side.
Can you explain what are you trying to accomplish?
Lapo

--

gotoAndPlay()

...addicted to flash games
krazl
Posts: 6
Joined: 22 Aug 2009, 01:11
Contact:

Postby krazl » 26 Aug 2009, 23:55

Actually i'm trying to get all avatar position that currently exists in current room. I could track them when they start move etc. but when I newly entering a room and every avatar is stand still, I can't get their position. Maybe there's something wrong in my psedo code?

1) 1st avatar join room. Move to A-Position. Stand still (Store current location)
2) 2nd avatar join room. Move to B-Position. stand Still (Store current location)
3) 3rd avatar join room. Stand still. trying retrieve 1st and 2nd avatar. No luck.

Code: Select all

function onAvatarMovementEnd(evt:AvatarEvent):void
{
   var varList:Array = []
   varList.push( {name:pAvatarPropertyTable[evt.params.id]} )
   pServer.setRoomVariables(varList)
}



pAvatarPropertyTable[userID] is object that store all avatar information.

Is there a way 3rd avatar listening to stored "setRoomVariables"?


Lapo wrote:Normally, you would not need this. At least from client side.
Can you explain what are you trying to accomplish?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 27 Aug 2009, 08:58

Actually i'm trying to get all avatar position that currently exists in current room

This is clear, you have already explained it.
My question is--> what for?
Once you got those positions what are you going to do? Are you trying to implement some sort of NPC client side logic?

Also the idea to store some other Avatar data in Room Variables doesn't sound much right. Each user is already carrying his/her OpenSpace avatar data via User Variables (which you can access if you really need it), so why duplicating that data in Room Variables?
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 27 Aug 2009, 09:00

1) 1st avatar join room. Move to A-Position. Stand still (Store current location)
2) 2nd avatar join room. Move to B-Position. stand Still (Store current location)
3) 3rd avatar join room. Stand still. trying retrieve 1st and 2nd avatar. No luck.


3rd avatar can cycle through the User List and check the User Variables for each connected user in that Room.
If you want to learn more about the variables each User has you can simply connect with the AdminTool, select one of the avatars and inspect the variables
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Postby Bax » 01 Sep 2009, 14:42

krazl wrote:I'm wondering how are we going trace other Avatar position when we entering new room.

Once the map is rendered, you can use the OpenSpace.getAvatarMovieClipById (undocumented, sorry) method.
This returns a reference to the so-called AvatarMovieClip class that you have implemented. Then use this code to retrive the coordinates of the avatar:

Code: Select all

(yourclass.parent as Avatar).px
(yourclass.parent as Avatar).py
(yourclass.parent as Avatar).pz
Paolo Bax
The SmartFoxServer Team
krazl
Posts: 6
Joined: 22 Aug 2009, 01:11
Contact:

Postby krazl » 03 Sep 2009, 03:22

OpenSpace.getAvatarMovieClipById

wah!! this will solve many problem (finger cross..hihi). what will be return on above code? as I newbie here, a simple example much appreciated. Is it like something below?

openSpace.addEventListener(OpenSpaceEvent.OnClick, onOpenSpaceClick){OpenSpace.getAvatarMovieClipById}



bax wrote:
krazl wrote:I'm wondering how are we going trace other Avatar position when we entering new room.

Once the map is rendered, you can use the OpenSpace.getAvatarMovieClipById (undocumented, sorry) method.
This returns a reference to the so-called AvatarMovieClip class that you have implemented. Then use this code to retrive the coordinates of the avatar:

Code: Select all

(yourclass.parent as Avatar).px
(yourclass.parent as Avatar).py
(yourclass.parent as Avatar).pz
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Postby Bax » 03 Sep 2009, 07:47

I don't understand you example, anyway it is a simple method call:

Code: Select all

openSpace.getAvatarMovieClipById(userId)

where you pass the sfs id of the user. The returned object is a reference to the class you created for avatars (the return type is MovieClip, but you can cast it to your class).
Paolo Bax
The SmartFoxServer Team

Return to “OpenSpace v1 discussions and help”

Who is online

Users browsing this forum: No registered users and 10 guests