Pets

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

Moderators: Lapo, Bax

alfaodin
Posts: 11
Joined: 09 Aug 2010, 13:57

Pets

Postby alfaodin » 20 Sep 2010, 17:03

hi, Sorry for bothering you, the question is how can I add a pet to my character, how can i have control over it (for example the pet has animations and with a button you make the animations play). I am lost.
Thank you
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Postby Bax » 21 Sep 2010, 14:41

A couple of ideas:
1) Pet is an NPC, controlled by your server-side extension. Not so easy to implement
2) Pet is part of the avatar class itself, just like if it was an avatar skin. You can control it in your avatar class
Paolo Bax
The SmartFoxServer Team
TiagoR
Posts: 83
Joined: 15 Mar 2010, 11:42
Location: Portugal
Contact:

Postby TiagoR » 21 Sep 2010, 15:34

Regarding the subject on this topic, is there any avatar action example ?
TR
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Postby Bax » 21 Sep 2010, 15:39

We don't have a specific example on avatar actions, but the usage is very similar to the avatar skin change. In your avatar class, when the action method is called, show the proper animation.
Paolo Bax
The SmartFoxServer Team
alfaodin
Posts: 11
Joined: 09 Aug 2010, 13:57

Pets

Postby alfaodin » 21 Sep 2010, 20:55

Thank you men, You gave me some ideas, another question in the new version of SmartfoxSever, Are you going to include a features like this??. Again thank you.
gl0om
Posts: 54
Joined: 30 Mar 2010, 17:39

Postby gl0om » 22 Sep 2010, 20:07

I use Vector<User> for controlled avatars and Timer for controlling them, but I suppose it's too ugly approach for making npc with "brain"... Please, bax, can you suggest better idea for this?
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Postby Bax » 24 Sep 2010, 11:38

gl0om, how can you control npc avatars on a single client. This is a bad approach.
All npc controlling should be made on the server-side, inside your extension.
Paolo Bax
The SmartFoxServer Team
gl0om
Posts: 54
Joined: 30 Mar 2010, 17:39

Postby gl0om » 24 Sep 2010, 12:25

Seems like you answered on my unedited reply... Actually I found in docs article about scheduler, hope it'll help me in controlling my army of npc
gl0om
Posts: 54
Joined: 30 Mar 2010, 17:39

Postby gl0om » 24 Sep 2010, 20:44

I met a problem. I pass Npc-user as parameter to Task and perform moveAvatar in it. When I kick user Task doesn't stop and I begin to receive warnings like "moveAvatar is ignored because user is not in room".

I tried to do such tricks inside doTask

Code: Select all

if (!npc.isInRoom(npc.getRoom()))
{
      task.active = false;
}

and

Code: Select all

try {
   moveAvatar(npc, npc.getRoom(), (int) Math.round(Math.random() * 10), (int) Math.round(Math.random() * 10), 0);
} catch (Exception e) {
   task.active = false;               
}


So how to kill Task when user is lost, disconnected, kicked?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 27 Sep 2010, 08:46

task.active = false
is correct, but... are you absolutely sure you are pointing to the right task?
Lapo
--
gotoAndPlay()
...addicted to flash games
gl0om
Posts: 54
Joined: 30 Mar 2010, 17:39

Postby gl0om » 27 Sep 2010, 08:59

Lapo wrote:task.active = false
is correct, but... are you absolutely sure you are pointing to the right task?

I suppose that task is correct. It's an argument for doTask(Task task)
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 27 Sep 2010, 09:31

What I mean is that it sounds like you are running several tasks, maybe one per User... am I getting this correctly? So I am suggesting that you debug your code and make sure that the task object you are de-activating is really the one connected with the User that just left.
Lapo

--

gotoAndPlay()

...addicted to flash games
gl0om
Posts: 54
Joined: 30 Mar 2010, 17:39

Postby gl0om » 28 Sep 2010, 15:55

Yes, you are right, I use 1 task per User.
I tried to figure out what's happening inside doTask..

Code: Select all

public void doTask(Task task) throws Exception
{
            String id = (String) task.id;
            String message = "Handling Task >>> { " + id + " }";
           
            Map params = task.parameters;
            User npc = (User)params.get("npc");
            trace("Check user: " + npc.getUserId());
            if (!npc.isInRoom(npc.getRoom()))
            {
               task.active = false;
            }
            else
            {
               trace("User is in room: " + npc.getRoom());
            }
}


After User is disconnected or kicked, I still receive message "User is in room: #"
So task.active = false; is never fired
gl0om
Posts: 54
Joined: 30 Mar 2010, 17:39

Postby gl0om » 30 Sep 2010, 08:28

I tried to solve this issue without success. I have no idea why User npc = (User)params.get("npc"); always exists, even after the user is lost.

Now I see the only solution:

1. Store all NPC in DB.

2. Mark lost users in internalEvent for removing in DB.

3. Check if it's makred for removing on each tick in doTask. If it's - deactivate task and remove NPC from DB.

I'm not sure that it's good solution because of it's complexity and additional stress for DB. What do you think?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 04 Oct 2010, 13:49

I am a little puzzled.
I have no idea why User npc = (User)params.get("npc"); always exists, even after the user is lost.

Can you better explain this?
In the USER_LOST event you are passed the User object. Where else do you get that User? I don't understand. After the USER_LOST you should not receive any more events about that User.
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “OpenSpace v2 discussions and help”

Who is online

Users browsing this forum: No registered users and 17 guests