About Store Forum Documentation Contact



Post Reply 
MMO code : cursor over players[0]
Author Message
gdalex Offline
Member

Post: #1
MMO code : cursor over players[0]
Hi there smile

I would like to trigger some events when the mouse cursor is over the current playe (Players[0]), but I cannot find how to test see.

I've seen this in the code :
Code:
// move player
      if(Ms.bp(0) && Players.elms()) // on LMB pressed
         if(!Gui.ms() || Gui.ms()==Gui.desktop())
      {
         if(Cur.valid)
         {
            if(Cur.obj.valid())
            {
               if(Chr *chr=CAST(Chr, &Cur.obj()))Players[0].actionAttack(*chr);
            }else
            {
               Players[0].actionMoveTo(Cur.pos);
            }
         }
      }

The object under the cursor is casted to Chr object, if the cast is successful, the pointer character is attacked.
I wanted to use a similar algo to check if my Players[0] is under the cursos, but it failed.
It seems that the Cur.obj.valid() returns 0 when the cursor is over my player.

If I am correct, it means that the cursor update() function ray cast didn't hit successfully... Can somebody explain me why ?
The Players[0] isn't part of the AG_PLAYER actor group ? Or some other reason ?


Thanks guys !
04-28-2013 10:29 AM
Find all posts by this user Quote this message in a reply
gdalex Offline
Member

Post: #2
RE: MMO code : cursor over players[0]
Come on guys, I can't believe anyone came up with something to detect such a click smile
05-03-2013 10:13 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #3
RE: MMO code : cursor over players[0]
Code:
uint    actor_groups=~(IndexToFlag(AG_PLAYER));
         Vec     pos, dir; ScreenToPosDir(screen, pos, dir);
         PhysHit phys_hit; if(Physics.ray(pos, dir*D.viewRange(), &phys_hit, actor_groups))
cursor ignores player actor
05-03-2013 04:02 PM
Find all posts by this user Quote this message in a reply
gdalex Offline
Member

Post: #4
RE: MMO code : cursor over players[0]
The current player and the "neighbor players" are handled the same way ?
It's seems to me that it's not the casen because with the default settings I can select the neighbors but not my character smile

Where can I define my Players[0] as a AG_PLAYER member ?



EDIT: Oops, I didn't get that, thanks Fex smile
(This post was last modified: 05-07-2013 07:24 PM by gdalex.)
05-04-2013 11:49 PM
Find all posts by this user Quote this message in a reply
Fex Offline
Gold Supporter

Post: #5
RE: MMO code : cursor over players[0]
what he is saying is that

uint actor_groups=~(IndexToFlag(AG_PLAYER));

IGNORES the player, so just change

Code:
PhysHit phys_hit; if(Physics.ray(pos, dir*D.viewRange(), &phys_hit, actor_groups))

to

Code:
PhysHit phys_hit; if(Physics.ray(pos, dir*D.viewRange(), &phys_hit))

or you can change the other line from
uint actor_groups=~(IndexToFlag(AG_PLAYER));

to
uint actor_groups=~0
(This post was last modified: 05-05-2013 02:02 AM by Fex.)
05-05-2013 02:02 AM
Find all posts by this user Quote this message in a reply
Post Reply